Example #1
0
 /**
  * Initialize the all or only autoload options.
  *
  * @param bool $autoload
  */
 protected function initialize($autoload = false)
 {
     if ($this->initialized) {
         return;
     }
     if ($autoload) {
         if (!$this->autoload) {
             $this->options = $this->autoload = $this->cache->fetch($this->prefix . 'Autoload');
         }
         if ($this->autoload) {
             return;
         }
         $query = "SELECT name, value, autoload FROM {$this->table} WHERE autoload = 1";
     } else {
         $query = "SELECT name, value, autoload FROM {$this->table}";
     }
     if ($options = $this->connection->fetchAll($query)) {
         foreach ($options as $option) {
             $this->options[$option['name']] = json_decode($option['value'], true);
             if ($option['autoload']) {
                 $this->autoload[$option['name']] = $this->options[$option['name']];
             }
         }
         $this->cache->save($this->prefix . 'Autoload', $this->autoload);
         if (!$autoload) {
             $this->initialized = true;
         }
     }
 }
 /**
  * Gets the metadata for the given class.
  *
  * @param  object|string $class
  * @return Metadata
  */
 public function get($class)
 {
     $class = new \ReflectionClass($class);
     $name = $class->getName();
     if (!isset($this->metadata[$name])) {
         if ($this->cache) {
             $id = sprintf('%s%s.%s', $this->prefix, filemtime($class->getFileName()), $name);
             if ($config = $this->cache->fetch($id)) {
                 $this->metadata[$name] = new Metadata($this, $name, $config);
             } else {
                 $this->cache->save($id, $this->load($class)->getConfig());
             }
         } else {
             $this->load($class);
         }
     }
     return $this->metadata[$name];
 }
Example #3
0
 /**
  * Clears the cache.
  */
 public function clearCache()
 {
     $this->cache->delete($this->cacheKey);
     $this->cacheEntries = false;
 }