Example #1
0
 public function testExtensions()
 {
     $package = PackageSchema::fromFile(__DIR__ . '/fixture/module.json');
     $module = $package->getKeeko()->getModule();
     $this->assertTrue($module->hasExtensions('module.dummy'));
     $this->assertFalse($module->hasExtensions('module.another-dummy'));
     $this->assertEquals(['module.dummy'], $module->getExtensionKeys()->toArray());
     $this->assertTrue($module->getExtensions('module.dummy') instanceof ArrayList);
     $this->assertEquals(2, $module->getExtensions('module.dummy')->size());
 }
Example #2
0
 public function testExtendedPackage()
 {
     $package = PackageSchema::fromFile(__DIR__ . '/fixture/extended.json');
     $json = Json::encode($package->toArray(), Json::PRETTY_PRINT | Json::UNESCAPED_SLASHES);
     $expected = file_get_contents(__DIR__ . '/fixture/extended.json');
     $this->assertEquals($expected, $json);
 }
Example #3
0
 /**
  * Loads the given action
  *
  * @param Action|string $actionName
  * @param string $format the response type (e.g. html, json, ...)
  * @return AbstractAction
  */
 public function loadAction($nameOrAction, $format = null)
 {
     $model = null;
     if ($nameOrAction instanceof Action) {
         $model = $nameOrAction;
         $actionName = $nameOrAction->getName();
     } else {
         $actionName = $nameOrAction;
     }
     if (!isset($this->actions[$actionName])) {
         throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $actionName, $this->model->getName()));
     }
     if ($model === null) {
         $model = $this->actions[$actionName]['model'];
     }
     /* @var $action ActionSchema */
     $action = $this->actions[$actionName]['action'];
     // check permission
     if (!$this->service->getFirewall()->hasActionPermission($model)) {
         throw new PermissionDeniedException(sprintf('Can\'t access Action (%s) in Module (%s)', $actionName, $this->model->getName()));
     }
     // check if a response is given
     if ($format !== null) {
         if (!$action->hasResponder($format)) {
             throw new ModuleException(sprintf('No Responder (%s) given for Action (%s) in Module (%s)', $format, $actionName, $this->model->getName()));
         }
         $responseClass = $action->getResponder($format);
         if (!class_exists($responseClass)) {
             throw new ModuleException(sprintf('Responder (%s) not found in Module (%s)', $responseClass, $this->model->getName()));
         }
         $responder = new $responseClass($this);
     } else {
         $responder = new NullResponder($this);
     }
     // gets the action class
     $className = $model->getClassName();
     if (!class_exists($className)) {
         throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $className, $this->model->getName()));
     }
     $class = new $className($model, $this, $responder);
     // locales
     // ------------
     $localeService = $this->getServiceContainer()->getLocaleService();
     // load module l10n
     $file = sprintf('/%s/locales/{locale}/translations.json', $this->package->getFullName());
     $localeService->loadLocaleFile($file, $class->getCanonicalName());
     // 		// load additional l10n files
     // 		foreach ($action->getL10n() as $file) {
     // 			$file = sprintf('/%s/locales/{locale}/%s', $this->package->getFullName(), $file);
     // 			$localeService->loadLocaleFile($file, $class->getCanonicalName());
     // 		}
     // 		// load action l10n
     // 		$file = sprintf('/%s/locales/{locale}/actions/%s', $this->package->getFullName(), $actionName);
     // 		$localeService->loadLocaleFile($file, $class->getCanonicalName());
     // assets
     // ------------
     $app = $this->getServiceContainer()->getKernel()->getApplication();
     $page = $app->getPage();
     // scripts
     foreach ($action->getScripts() as $script) {
         $page->addScript($script);
     }
     // styles
     foreach ($action->getStyles() as $style) {
         $page->addStyle($style);
     }
     return $class;
 }