Esempio n. 1
0
 /**
  * Constructor
  *
  * Prevent creating instances of this class by making the constructor private
  */
 public function __construct(ObjectConfig $config)
 {
     //Set the class loader
     if (!$config->class_loader instanceof ClassLoaderInterface) {
         throw new \InvalidArgumentException('class_loader [ClassLoaderInterface] config option is required, "' . gettype($config->class_loader) . '" given.');
     } else {
         $this->setClassLoader($config['class_loader']);
     }
     //Create the object registry
     if ($config->cache_enabled && ObjectRegistryCache::isSupported()) {
         $this->_registry = new ObjectRegistryCache();
         $this->_registry->setNamespace($config->cache_prefix);
     } else {
         $this->_registry = new ObjectRegistry();
     }
     //Create the object identifier
     $this->__object_identifier = $this->getIdentifier('lib:object.manager');
     //Manually register the library loader
     $config = new ObjectConfig(array('object_manager' => $this, 'object_identifier' => new ObjectIdentifier('lib:object.locator.library')));
     $this->registerLocator(new ObjectLocatorLibrary($config));
     //Register the component locator
     $this->registerLocator('lib:object.locator.component');
     //Register self and set a 'manager' alias
     $this->setObject('lib:object.manager', $this);
     $this->registerAlias('manager', 'lib:object.manager');
 }
Esempio n. 2
0
 /**
  * Enable or disable the cache
  *
  * @param bool $cache True or false.
  * @param string $namespace The cache namespace
  * @return ObjectManager
  */
 public function setCache($cache, $namespace = null)
 {
     if ($cache && ObjectRegistryCache::isSupported()) {
         $this->__registry = new ObjectRegistryCache();
         if ($namespace) {
             $this->__registry->setNamespace($namespace);
         }
     } else {
         if (!$this->__registry instanceof ObjectRegistry) {
             $this->__registry = new ObjectRegistry();
         }
     }
     return $this;
 }