/** * Get routing config. * * @param string $option The component option name. * @param string $type The routing file type. * * @return mixed */ public static function getRouting($option, $type = self::TYPE_YAML) { if (self::$routing) { return self::$routing; } $path = PathHelper::getSite($option); $fileType = $type == static::TYPE_YAML ? 'yml' : $type; $data = new Registry(); $data->loadFile($path . '/routing.' . $fileType, $type); return self::$routing = $data->toArray(); }
/** * onBeforeRenderFiles * * @param Event $event * * @return void */ public function onBeforeRenderFiles(Event $event) { $this->data = array(); $files = new \DirectoryIterator(__DIR__ . '/../../resources'); $resources = new PriorityQueue(); $menus = new PriorityQueue(); /** @var \SplFileInfo $file */ foreach ($files as $file) { if ($file->isDir()) { continue; } $data = new Registry(); $data->loadFile($file->getPathname(), 'yaml'); $resName = $file->getBasename('.yml'); list($priority, $resName) = explode('-', $resName, 2); $data['alias'] = $resName; $resources->insert($data->toArray(), PHP_INT_MAX - $priority); $menus->insert(array('title' => $data['title'], 'alias' => $resName), PHP_INT_MAX - $priority); } // Store in cache $this->data['menus'] = $menus->toArray(); foreach ($resources as $data) { $this->data['resources'][$data['alias']] = $data; } // Auto create pages $categoryFolder = new \SplFileInfo(__DIR__ . '/../../entries/type'); if (is_dir($categoryFolder->getPathname())) { Folder::delete($categoryFolder->getPathname()); } Folder::create($categoryFolder->getPathname()); foreach ($this->data['resources'] as $catName => &$category) { File::copy(__DIR__ . '/../../layouts/tmpl/category.twig', __DIR__ . '/../../entries/type/' . $catName . '.twig'); // Auto create items page $itemFolder = new \SplFileInfo(__DIR__ . '/../../entries/type/' . $catName); if (is_dir($itemFolder->getPathname())) { Folder::delete($itemFolder->getPathname()); } Folder::create($itemFolder->getPathname()); foreach ($category['data'] as $itemAlias => &$item) { File::copy(__DIR__ . '/../../layouts/tmpl/item.twig', __DIR__ . '/../../entries/type/' . $catName . '/' . $itemAlias . '.twig'); $item['alias'] = $itemAlias; } } }
/** * getTwig * * @param bool $new * * @return \Twig_Environment */ public function getEngine($new = false) { if (!$this->engine instanceof \Twig_Environment || $new) { $this->engine = new \Twig_Environment($this->getLoader(), $this->config->toArray()); foreach (GlobalContainer::getExtensions() as $extension) { $this->engine->addExtension(clone $extension); } foreach ($this->extensions as $extension) { $this->engine->addExtension($extension); } foreach (GlobalContainer::getGlobals() as $name => $value) { $this->engine->addGlobal($name, $value); } if ($this->config->get('debug')) { $this->engine->addExtension($this->getDebugExtension()); } } return $this->engine; }
/** * extractConfig * * @param string $template * * @return string */ public function prepareData($template) { $template = explode('---', $template, 3); if (!trim($template[0])) { array_shift($template); $template = implode('---', $template); $template = explode('---', $template, 2); } try { $config = Yaml::parse($template[0]); if ($config) { array_shift($template); } $this->config->loadArray($config); $this->config->merge(Ioc::getConfig()); $this->getData()->bind(array('config' => $this->config->toArray())); // Target permalink if ($this->config['permalink']) { $this->target = rtrim($this->config['permalink'], '/'); if (substr($this->target, -5) != '.html') { $this->target .= '/index.html'; } $this->data->uri['base'] = ProcessorHelper::getBackwards($this->target) ?: './'; $this->data->uri['media'] = ProcessorHelper::getBackwards($this->target) . 'media/'; } else { $this->target = $this->getTarget(); } $template = implode('---', $template); } catch (ParseException $e) { $template = implode('---', $template); } $event = new Event('loadProvider'); $event['data'] = $this->data; $event['processor'] = $this; $dispatcher = Ioc::getDispatcher(); $dispatcher->triggerEvent($event); return $template; }
/** * Get extension params. * * @param string $element The extension name. * * @return Registry|\JRegistry Extension params object. */ public static function getParams($element) { $extension = static::extractElement($element); switch ($extension['type']) { case 'component': $params = \JComponentHelper::getParams($element); $params = new Registry($params->toArray()); break; case 'module': $module = \JModuleHelper::getModule($element); $params = new Registry(); $params->loadString($module->params); break; case 'plugin': $plugin = \JPluginHelper::getPlugin($extension['group'], $extension['name']); $params = $plugin->params; $params = new Registry($params); break; default: $params = new Registry(); break; } return $params; }
/** * Transforms a namespace to an array * * @return array An associative array holding the namespace data * * @since 1.0 */ public function toArray() { return $this->registry->toArray(); }
/** * Method to render the view. * * @return string The rendered view. * * @throws \RuntimeException */ public function doRender() { return JsonResponse::response($this->data->toArray()); }
/** * Set config object into this class. * * @param Registry $config The config object. * * @return void */ public static function setConfig($config) { if ($config instanceof \Joomla\Registry\Registry) { $config = new Registry($config->toArray()); } self::$config = $config; }
/** * Method to test toArray(). * * @return void * * @covers Windwalker\Registry\Registry::toArray */ public function testToArray() { $registry = new Registry($this->getTestData()); $this->assertEquals($registry->toArray(), $this->getTestData()); }
/** * prepareGlobals * * @param \Windwalker\Data\Data $data * * @return void */ protected function prepareGlobals($data) { $uri = new Registry(); $layout = explode('/', $this->getLayout()); array_pop($layout); $uri['base'] = str_repeat('../', count($layout)) ?: './'; $uri['media'] = str_repeat('../', count($layout)) . 'media/'; $layout = implode('/', (array) $layout); $this->data->uri = $uri->toArray(); $this->data->helper = new HelperSet(); $this->data->path = explode('/', $this->getLayout()); $this->data->bind(GlobalProvider::loadGlobalProvider()); }
/** * Merge a Registry object into this one * * @param Registry $source Source Registry object to merge. * @param boolean $recursive True to support recursive merge the children values. * * @return Registry Return this object to support chaining. * * @since 2.0 */ public function merge(Registry $source, $recursive = true) { $this->bindData($this->data, $source->toArray(), $recursive, false); return $this; }