/** * Gets menu items url info from cache. * * @return array */ protected function getItems() { if (false === ($this->cacheEntries = $this->cache->fetch($this->cacheKey))) { $this->cacheEntries = ['paths' => [], 'patterns' => []]; foreach ($this['menus']->getItemRepository()->query()->where(['status' => ItemInterface::STATUS_ACTIVE])->get() as $item) { if (!$item->getPages()) { $this->cacheEntries['paths'][strtok(strtok($item->getUrl(), '?'), '#')][$item->getId()] = $item->getUrl(); } else { $this->cacheEntries['patterns'][$item->getId()] = $item->getPages(); } } $this->cache->save($this->cacheKey, $this->cacheEntries); } return $this->cacheEntries; }
/** * 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]; }