Skip to content

Commit

Permalink
#47: Wire up a new osid.runtime service to access the OSID API.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfranco committed Sep 24, 2024
1 parent c9c5d4c commit 1021e45
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 92 deletions.
91 changes: 0 additions & 91 deletions application/resources/Catalog/Action/Helper/Osid.php

This file was deleted.

10 changes: 10 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
app.osid.runtime.courseimpl: 'banner_course_CourseManager'

services:
# default configuration for services in *this* file
Expand All @@ -22,3 +23,12 @@ services:

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

App\Service\Osid\Runtime:
arguments:
$configPath: '../configuration.plist'
$courseImpl: '%app.osid.runtime.courseimpl%'

# Service aliases.
osid.runtime:
class: App\Service\Osid\Runtime
18 changes: 17 additions & 1 deletion src/Controller/Catalogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace App\Controller;

use App\Service\Osid\Runtime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -23,10 +24,25 @@
class Catalogs extends AbstractController
{

/**
* @var \App\Service\Osid\Runtime
*/
private $osidRuntime;

/**
* Construct a new Catalogs controller.
*
* @param \App\Service\Osid\Runtime $osidRuntime
* The osid.runtime service.
*/
public function __construct(Runtime $osidRuntime) {
$this->osidRuntime = $osidRuntime;
}

#[Route('/catalogs/', name: 'List all catalogs')]
public function listAction()
{
$lookupSession = $this->_helper->osid->getCourseManager()->getCourseCatalogLookupSession();
$lookupSession = $this->osidRuntime->getCourseManager()->getCourseCatalogLookupSession();

return $this->render('catalogs.html.twig', [
'title' => 'Available Catalogs',
Expand Down
106 changes: 106 additions & 0 deletions src/Service/Osid/Runtime.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace App\Service\Osid;

/**
* A helper to provide access to the CourseManager OSID and OSID configuration.
*
* @since 6/9/10
*
* @copyright Copyright &copy; 2009, Middlebury College
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
*/
class Runtime
{

private $runtimeManager;
private $courseManager;
private $configPath;
private $courseImpl;

/**
* Create a new OSID service instance.
*
* @param string $configPath
* The path to the Osid Configuration XML file.
* @param string $courseImpl
* The OSID CourseManager implementation class to use.
*/
public function __construct(string $configPath, string $courseImpl = 'banner_course_CourseManager') {
$this->setConfigPath($configPath);
$this->courseImpl = $courseImpl;
}

/**
* Answer the configuration path.
*
* @return string
*
* @since 6/11/09
*/
public function getConfigPath()
{
if (!isset($this->configPath)) {
$this->configPath = BASE_PATH.'/configuration.plist';
}

return $this->configPath;
}

/**
* Set the configuration path.
*
* @param string $path
*
* @since 6/11/09
*
* @throws osid_IllegalStateException the config path has already been set
*/
public function setConfigPath($path)
{
if (isset($this->configPath) && $this->configPath != $path) {
throw new osid_IllegalStateException('the config path has already been set');
}

$this->configPath = $path;
}

/**
* Answer the CourseManager.
*
* @return osid_course_CourseManager
*
* @since 4/20/09
*/
public function getCourseManager()
{
if (!isset($this->courseManager)) {
if (class_exists($this->courseImpl)) {
$runtimeManager = $this->getRuntimeManager();
$this->courseManager = $runtimeManager->getManager(osid_OSID::COURSE(), $this->courseImpl, '3.0.0');
}
else {
throw new \InvalidArgumentException("Unknown CourseManger implementation class: " . $this->courseImpl);
}

}

return $this->courseManager;
}

/**
* Answer the Runtime Manager.
*
* @return osid_OsidRuntimeManager
*
* @since 4/20/09
*/
public function getRuntimeManager()
{
if (!isset($this->runtimeManager)) {
$this->runtimeManager = new phpkit_AutoloadOsidRuntimeManager($this->getConfigPath());
}

return $this->runtimeManager;
}
}

0 comments on commit 1021e45

Please sign in to comment.