/**
  * Returns all extensions matching the given parameters.
  *
  * @param string $extensionTypeBaseDirectory Base directory where the extensions are located
  * @param string $extensionTypeBaseClass Name of the extension type base class
  * @param string $extensionTypeNamespace Namespace of the extension type
  * @return array
  */
 protected function getExtensions($extensionTypeBaseDirectory, $extensionTypeBaseClass, $extensionTypeNamespace)
 {
     $extensions = array();
     foreach (new GlobIterator(sprintf('%s/*/%s.php', $extensionTypeBaseDirectory, $extensionTypeBaseClass), FilesystemIterator::UNIX_PATHS) as $extensionFileInfo) {
         $extensions[] = ClassUtil::getInstance(sprintf('%s\\%s\\%s', $extensionTypeNamespace, str_replace($extensionTypeBaseDirectory . '/', '', $extensionFileInfo->getPath()), $extensionTypeBaseClass));
     }
     return $extensions;
 }
Beispiel #2
0
 /**
  * Determines the controller responsible for handling the given request
  * and returns an instance of it.
  *
  * @param \Ableron\Core\Request\WebRequestHandler $requestHandler The request handler
  * @param \Ableron\Core\Extension\Module\ModuleManager $moduleManager The module manager
  * @return \Ableron\Core\Controller\ControllerInterface
  */
 public function routeRequest(WebRequestHandler $requestHandler, ModuleManager $moduleManager)
 {
     // check for matching route
     foreach ($moduleManager->getModuleByNamespace($requestHandler->getRequestedModule()->getNamespace())->getRoutes($requestHandler->isFrontendRequest()) as $route) {
         if ($route['type'] === 'route') {
             // get route to match against given request
             $routeInstance = ClassUtil::getInstance('Ableron\\Core\\Router\\Route\\' . $route['route']['type'] . 'Route', array($route['route']['parameters']));
             // check whether current route matches given request
             if ($routeInstance->match($requestHandler->getModuleRequestUri(), $requestHandler->getRequest()) !== null) {
                 return new $route['controller']();
             }
         }
     }
     // return "404 Not Found" controller because no matching route was found
     return $requestHandler->isFrontendRequest() ? new FrontendResourceNotFoundPage() : new BackendResourceNotFoundPage();
 }
Beispiel #3
0
 /**
  * Returns an instance of the module with the given namespace.
  *
  * @param string $namespace Namespace of the module to return the instance of
  * @return \Ableron\Core\Extension\Module\ModuleInterface
  */
 public function getModuleByNamespace($namespace)
 {
     return ClassUtil::getInstance('Ableron\\Modules\\' . $namespace . '\\Module');
 }
 /**
  * Returns an instance of the compiler plugin with the given class name.
  *
  * Does not contain error handling for the case, the plugin could not be found because this
  * method only gets called for plugin which already have been found.
  *
  * @param string $pluginClassName Class name of the template plugin
  * @param \Ableron\Core\Template\TemplateTag $templateTag The template tag to get the compiler plugin for
  * @return \Ableron\Core\Template\Plugins\Interfaces\CompilerPluginInterface
  */
 private function getCompilerPlugin($pluginClassName, TemplateTag $templateTag)
 {
     // build cache key
     $pluginKey = $pluginClassName . $templateTag->getFullTag();
     // find and initialize plugin if not already done
     if (!$this->compilerPluginInstances->containsKey($pluginKey)) {
         foreach ($this->pluginDirectories as $pluginDirectory => $namespace) {
             if (is_file(sprintf('%s/%s.php', $pluginDirectory, $pluginClassName))) {
                 $this->compilerPluginInstances->set($pluginKey, ClassUtil::getInstance($namespace . '\\' . $pluginClassName, array($templateTag)));
                 break;
             }
         }
     }
     // return compiler plugin
     return $this->compilerPluginInstances->get($pluginKey);
 }
Beispiel #5
0
 /**
  * Tests whether getInstance() handles provided arguments correctly.
  *
  * @return void
  */
 public function testGetInstanceHandlesArgumentsCorrectly()
 {
     $this->assertSame(13, ClassUtil::getInstance(SplFixedArray::class, array(13))->getSize());
 }
 /**
  * Tests whether hasBinaryContent() works as expected.
  *
  * @dataProvider dataProviderCommon
  * @return void
  */
 public function testHasBinaryContent($inputParameters, $isKnown, $hasBinaryContent)
 {
     $this->assertSame($hasBinaryContent, InternetMediaTypeLibrary::hasBinaryContent(ClassUtil::getInstance('Ableron\\Lib\\Net\\InternetMediaType', $inputParameters)));
 }
 /**
  * Installs extensions (modules and plugins).
  *
  * @throws \Ableron\Core\Exception\SystemException
  * @return void
  */
 private function installExtensions()
 {
     // install all available modules (except core module which has already been installed)
     foreach (Application::getModuleManager()->getModules() as $module) {
         if ($module::getNamespace() !== CoreModule::getNamespace()) {
             try {
                 Application::getModuleManager()->install(ClassUtil::getInstance(sprintf('Ableron\\Modules\\%s\\Module', $module::getNamespace())));
             } catch (SystemException $e) {
                 $this->getInstaller()->addException(new SystemException(sprintf('Unable to install module "%s"', $module::getNamespace()), 0, E_USER_WARNING, __FILE__, __LINE__, $e));
             }
         }
     }
     // install all available plugins
     foreach (Application::getPluginManager()->getPlugins() as $plugin) {
         try {
             Application::getPluginManager()->install(ClassUtil::getInstance(sprintf('Ableron\\Plugins\\%s\\Plugin', $plugin::getNamespace())));
         } catch (SystemException $e) {
             $this->getInstaller()->addException(new SystemException(sprintf('Unable to install plugin "%s"', $plugin::getNamespace()), 0, E_USER_WARNING, __FILE__, __LINE__, $e));
         }
     }
 }
 /**
  * Returns an instance of the template function plugin with the given class name.
  *
  * @param string $pluginClassName Class name of the template function plugin
  * @throws \Ableron\Core\Exception\SystemException
  * @return \Ableron\Core\Template\Plugins\Interfaces\FunctionPluginInterface
  */
 public function getTemplateFunctionPlugin($pluginClassName)
 {
     // find and initialize plugin if not already done
     if (!$this->getPluginInstances()->containsKey($pluginClassName)) {
         foreach ($this->getPluginDirectories() as $pluginDirectory => $namespace) {
             if (is_file(sprintf('%s/%s.php', $pluginDirectory, $pluginClassName))) {
                 $this->getPluginInstances()->set($pluginClassName, ClassUtil::getInstance($namespace . '\\' . $pluginClassName));
                 break;
             }
         }
     }
     // return an instance of the plugin if possible
     if ($this->getPluginInstances()->containsKey($pluginClassName)) {
         return $this->getPluginInstances()->get($pluginClassName);
     }
     // plugin not found
     throw new SystemException(sprintf('Unable to find template function plugin "%s"', $pluginClassName), 0, E_USER_ERROR, __FILE__, __LINE__);
 }
 /**
  * Wraps the given header field name and field value into a header field
  * object.
  *
  * @param string $fieldName Name of the header field
  * @param string $fieldValue Value of the header field
  * @return \Ableron\Lib\Stdlib\Interfaces\HeaderFieldInterface
  */
 public static function getHeaderFieldObject($fieldName, $fieldValue)
 {
     return isset(self::$headerFieldClasses[strtolower($fieldName)]) ? ClassUtil::getInstance(self::$headerFieldClasses[strtolower($fieldName)], array($fieldValue)) : new GenericHeaderField($fieldName, $fieldValue);
 }
Beispiel #10
0
 /**
  * Reads event handlers from database.
  *
  * Event handlers can be stored in database, so they do not have to be
  * registered at the event manager manually during script execution.
  *
  * @return void
  */
 private function readEventHandlers()
 {
     /** @var \Ableron\Modules\Core\Model\Entities\EventHandlerEntity $eventHandlerEntity */
     foreach ($this->eventHandlerEntityRepository->findAll() as $eventHandlerEntity) {
         $this->registerEventHandler($eventHandlerEntity->getEventName(), ClassUtil::getInstance($eventHandlerEntity->getEventHandlerClass()));
     }
 }