123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- namespace Cube\Application\Resource;
- use Cube\Navigation as NavigationObject,
- Cube\Loader\Autoloader;
- class Navigation extends AbstractResource
- {
- const CONFIG_NAMESPACE = '\\Cube\\Config\\';
- const DEFAULT_CONFIG = 'ArrayConfig';
-
- protected $_type;
-
- protected $_file;
-
- protected $_container;
-
- public function getContainer()
- {
- return $this->_container;
- }
-
- public function setContainer($container)
- {
- if (!$container instanceof Navigation) {
- throw new \InvalidArgumentException(
- sprintf("'%s' must be an instance of \Cube\Navigation.", $container));
- }
- $this->_container = $container;
- return $this;
- }
-
- public function setType($type)
- {
- $this->_type = $type;
- return $this;
- }
-
- public function setFile($file)
- {
- if (isset($file) && file_exists($file)) {
- $this->_file = $file;
- }
- else {
- throw new \InvalidArgumentException(sprintf("The navigation file '%s' does not exist.", $file));
- }
- return $this;
- }
-
- public function init()
- {
- if (!($this->_container instanceof NavigationObject)) {
- $navigationFile = $this->_options['navigation']['data_file'];
- $basePath = $this->_options['paths']['base'];
- $pattern = str_replace('navigation.', '*.', $navigationFile);
- $additionalFiles = array_unique(array_merge(
- glob($pattern),
- glob(str_replace($basePath, $basePath . DIRECTORY_SEPARATOR . Autoloader::getInstance()->getModsPath(), $pattern))
- ));
- $configClass = self::CONFIG_NAMESPACE
- . ((isset($this->_options['navigation']['data_type'])) ?
- ucfirst($this->_options['navigation']['data_type']) : self::DEFAULT_CONFIG);
-
- if (class_exists($configClass)) {
- $configObject = new $configClass(
- $navigationFile);
- foreach ($additionalFiles as $additionalFile) {
- if (file_exists($additionalFile) && $additionalFile != $navigationFile) {
- $configObject->addData($additionalFile);
- }
- }
- }
- else {
- throw new \InvalidArgumentException(sprintf("Class '%s' does not exist.", $configClass));
- }
- $this->_container = new NavigationObject($configObject);
- if (isset($this->_options['navigation']['views_path'])) {
- $this->_container->setPath($this->_options['navigation']['views_path']);
- }
- }
- return $this->_container;
- }
- }
|