Example #1
0
 private function assertBasicPackage(PackageSchema $package)
 {
     $this->assertEquals('basic/package', $package->getFullName());
     $this->assertEquals('package', $package->getName());
     $this->assertEquals('basic', $package->getVendor());
     $this->assertEquals('I am just a dummy', $package->getDescription());
     $this->assertEquals('package', $package->getType());
     $this->assertEquals('MIT', $package->getLicense());
     // authors
     $authors = $package->getAuthors();
     $gossi = $authors->get(0);
     $this->assertEquals(1, $authors->size());
     $this->assertEquals('gossi', $gossi->getName());
     // autoload
     $autoload = $package->getAutoload();
     $psr4 = $autoload->getPsr4();
     $this->assertTrue($autoload->getClassmap()->isEmpty());
     $this->assertTrue($autoload->getFiles()->isEmpty());
     $this->assertTrue($autoload->getPsr0()->isEmpty());
     $this->assertEquals('src/', $psr4->getPath('basic\\package\\'));
     $this->assertTrue($psr4->hasNamespace('basic\\package\\'));
     // require
     $require = $package->getRequire();
     $this->assertFalse($require->isEmpty());
     $this->assertTrue($require->has('phootwork/collection'));
     // require-dev
     $requireDev = $package->getRequireDev();
     $this->assertFalse($requireDev->isEmpty());
     $this->assertTrue($requireDev->has('phpunit/phpunit'));
     // extra
     $extra = $package->getExtra();
     $this->assertTrue($extra->has('moop'));
     $this->assertEquals('value', $extra->get('moop'));
     $this->assertTrue($extra->get('doop') instanceof Map);
     $this->assertEquals('other-value', $extra->get('doop')->get('some'));
 }
Example #2
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;
 }