Пример #1
0
 /**
  * @inheritdoc
  */
 public function register($key, $decorator)
 {
     if ($this->isRegistered($key)) {
         throw new \LogicException(sprintf('The given decorator key "%s" cannot be registered because it already exists.', $key));
     }
     $this->decorators[$key] = TypeUtilities::buildTypeCheckedObject($decorator, 'decorator', null, '\\Sitegear\\View\\Decorator\\DecoratorInterface');
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function register($renderers)
 {
     LoggerRegistry::debug('RendererRegistry::register({renderers})', array('renderers' => TypeUtilities::describe($renderers)));
     if (!is_array($renderers)) {
         $renderers = array($renderers);
     }
     foreach ($renderers as $renderer) {
         if (!$this->isRegistered($renderer)) {
             $this->registry[TypeUtilities::getClassName($renderer)] = TypeUtilities::buildTypeCheckedObject($renderer, 'content renderer', null, '\\Sitegear\\View\\Renderer\\RendererInterface');
         }
     }
 }
Пример #3
0
 /**
  * Instantiate a module instance for this engine.
  *
  * @param string $name Module to load.
  *
  * @return \Sitegear\Module\ModuleInterface
  *
  * @throws \InvalidArgumentException If the named module does not exist.
  * @throws \DomainException If the named module does not implement ModuleInterface.
  */
 protected function createModule($name)
 {
     LoggerRegistry::debug('AbstractEngine::createModule({name})', array('name' => TypeUtilities::describe($name)));
     try {
         return TypeUtilities::buildTypeCheckedObject($this->getModuleClassName($name) ?: '', 'module', null, '\\Sitegear\\Module\\ModuleInterface', array($this));
     } catch (\DomainException $e) {
         throw new \InvalidArgumentException(sprintf('AbstractEngine cannot create module "%s" because it does not exist', $name), 0, $e);
     }
 }
Пример #4
0
 /**
  * Register a file loader of the given class.
  *
  * @param string|\Sitegear\Config\FileLoader\FileLoaderInterface $fileLoader Class name of the file loader to
  *   register, or a class implementing FileLoaderInterface.
  *
  * @throws \InvalidArgumentException If the class does not exist or is not a FileLoaderInterface implementation.
  */
 public function registerFileLoader($fileLoader)
 {
     LoggerRegistry::debug('ConfigLoader::registerFileLoader({loader})', array('loader' => TypeUtilities::describe($fileLoader)));
     $this->fileLoaders[TypeUtilities::getClassName($fileLoader)] = TypeUtilities::buildTypeCheckedObject($fileLoader, 'config file loader', null, '\\Sitegear\\Config\\FileLoader\\FileLoaderInterface');
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function start()
 {
     parent::start();
     $connectionConfig = $this->config('connection');
     if (!empty($connectionConfig) && is_array($connectionConfig)) {
         // Setup Doctrine. Largely borrowed from
         // https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/annotations.md#em-setup
         // Register Doctrine default annotations.
         AnnotationRegistry::registerFile($this->getEngine()->getSiteInfo()->getSiteRoot() . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
         // Setup annotation metadata cache
         if ($this->getEngine()->getEnvironmentInfo()->isDevMode() || !$this->getEngine()->config('memcache.enabled')) {
             $cache = new ArrayCache();
         } else {
             $cache = new MemcacheCache();
             $cache->setMemcache($this->getEngine()->getMemcache());
         }
         // Setup annotation metadata reader and driver
         /** @var AnnotationReader $cachedAnnotationReader (for all intents and purposes...) */
         $cachedAnnotationReader = new CachedReader(new AnnotationReader(), $cache);
         $this->driverChain = new MappingDriverChain();
         $this->annotationDriver = new AnnotationDriver($cachedAnnotationReader, array($this->getEngine()->getApplicationInfo()->getSitegearRoot()));
         // Setup Gedmo extension annotations
         \Gedmo\DoctrineExtensions::registerAnnotations();
         $this->driverChain->addDriver($this->annotationDriver, 'Gedmo');
         // Setup Sitegear extension annotations
         // TODO Make model-providing modules declare their own namespaces
         $this->driverChain->addDriver($this->annotationDriver, 'Sitegear\\Module\\Customer\\Model');
         $this->driverChain->addDriver($this->annotationDriver, 'Sitegear\\Module\\News\\Model');
         $this->driverChain->addDriver($this->annotationDriver, 'Sitegear\\Module\\Locations\\Model');
         $this->driverChain->addDriver($this->annotationDriver, 'Sitegear\\Module\\Products\\Model');
         // Create the entity manager configuration, with proxy generation, cached metadata and lowercase-underscore
         // database naming convention.
         $entityManagerConfig = new Configuration();
         // TODO Make this a temp directory set in the engine config
         $entityManagerConfig->setProxyDir(sys_get_temp_dir());
         // TODO Configurable namespace and naming strategy
         $entityManagerConfig->setProxyNamespace('Proxy');
         $entityManagerConfig->setAutoGenerateProxyClasses($this->getEngine()->getEnvironmentInfo()->isDevMode());
         $entityManagerConfig->setMetadataDriverImpl($this->driverChain);
         $entityManagerConfig->setMetadataCacheImpl($cache);
         $entityManagerConfig->setQueryCacheImpl($cache);
         $entityManagerConfig->setNamingStrategy(new UnderscoreNamingStrategy(CASE_LOWER));
         // Setup event subscribers.
         $eventManager = new EventManager();
         foreach ($this->config('orm.subscribers') as $subscriberConfig) {
             /** @var \Doctrine\Common\EventSubscriber $subscriber */
             $subscriber = TypeUtilities::buildTypeCheckedObject($subscriberConfig['class'], 'event subscriber', null, array('\\Doctrine\\Common\\EventSubscriber'), isset($subscriberConfig['arguments']) ? $subscriberConfig['arguments'] : array());
             if ($subscriber instanceof MappedEventSubscriber) {
                 /** @var MappedEventSubscriber $subscriber */
                 $subscriber->setAnnotationReader($cachedAnnotationReader);
             }
             $eventManager->addEventSubscriber($subscriber);
         }
         // Create the entity manager using the configured connection parameters.
         $this->entityManager = EntityManager::create($this->config('connection'), $entityManagerConfig, $eventManager);
         // Register the JSON custom data type.  This has to be done last, when the entity manager has a connection.
         foreach ($this->config('dbal.types') as $key => $className) {
             Type::addType($key, $className);
             $this->entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping(preg_replace('/^.*\\\\(.*?)$/', '$1', $className), $key);
         }
     } else {
         throw new \DomainException('<h1>Incorrect or Missing Configuration</h1><p>You have attempted to use the Doctrine module in your site, but you have not provided all the required connection parameters in your configuration file.</p><p>Please rectify this by providing connection parameters ("driver", "dbname", plus normally "username" and "password") or disabling the Doctrine module.</p>');
     }
 }
Пример #6
0
 /**
  * Create a RendererFactoryInterface implementation as determined by configuration.
  *
  * @return RendererFactoryInterface
  */
 protected function createRendererFactory()
 {
     $factoryClassName = $this->config('form-renderer-factory.class-name');
     $factoryConstructorArguments = $this->config('form-renderer-factory.constructor-arguments');
     return TypeUtilities::buildTypeCheckedObject($factoryClassName, 'form renderer factory', null, array('\\Sitegear\\Form\\Renderer\\Factory\\RendererFactoryInterface'), $factoryConstructorArguments);
 }
Пример #7
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testTypeCheckedObjectInvalidArgument()
 {
     TypeUtilities::buildTypeCheckedObject(42, '[test]');
 }