Esempio n. 1
0
 /**
  * Constructor.
  *
  * @param HtmlView $view   The view object.
  * @param array    $config The config object.
  */
 public function __construct(HtmlView $view, $config = array())
 {
     $this->view = $view;
     $this->config = $config = $config instanceof Structure ? $config : new Structure($config);
     $this->state = $state = $view['state'] ?: new Structure();
     // Merge fields
     $fields = $config->get('field');
     $fields = array_merge($this->fields, (array) $fields);
     $this->config->set('field', $fields);
     // Access context
     $this->context = $this->config->get('option') . '.' . $this->config->get('view_item');
     // Ordering
     $listOrder = $state->get('list.ordering');
     $orderColumn = $state->get('list.orderColumn', $config->get('order_column'));
     $listDirn = $this->state->get('list.direction');
     $this->config->set('list.saveorder', $listOrder == $orderColumn && strtoupper($listDirn) === 'ASC');
 }
 /**
  * Modifies a property of the object, creating it if it does not already exist.
  *
  * @param   string  $key    The name of the property.
  * @param   mixed   $value  The value of the property to set (optional).
  *
  * @return  mixed   Previous value of the property
  *
  * @since   2.0
  */
 public function set($key, $value = null)
 {
     $this->config->set($key, $value);
     return $this;
 }
Esempio n. 3
0
 /**
  * getOrphans
  *
  * @param boolean $flatten
  * @param int     $stripPrefix
  *
  * @return array
  */
 public static function getOrphans($flatten = true, $stripPrefix = 1)
 {
     $orphans = Translator::getInstance()->getOrphans();
     foreach ($orphans as $key => $value) {
         $value = explode('.', $key);
         $value = array_map('ucfirst', $value);
         foreach (range(1, $stripPrefix) as $i) {
             array_shift($value);
         }
         $value = implode(' ', $value);
         $orphans[$key] = $value;
     }
     if (!$flatten) {
         $reg = new Structure();
         foreach ($orphans as $key => $value) {
             $reg->set($key, $value);
         }
         $orphans = $reg->toArray();
     }
     return $orphans;
 }
 /**
  * Constructor.
  *
  * @param   \Windwalker\DI\Container $container
  * @param   \Muse\IO\IOInterface     $io
  * @param   Structure                $config
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(Container $container, IOInterface $io, Structure $config = null)
 {
     // Get item & list name
     $ctrl = $config['ctrl'] ?: $io->getArgument(1);
     $ctrl = explode('.', $ctrl);
     $inflector = StringInflector::getInstance();
     if (empty($ctrl[0])) {
         $ctrl[0] = 'item';
     }
     if (empty($ctrl[1])) {
         $ctrl[1] = $inflector->toPlural($ctrl[0]);
     }
     list($itemName, $listName) = $ctrl;
     // Prepare package name
     $class = explode('\\', str_replace('/', '\\', $config['name']));
     $name = array_pop($class);
     $class = StringNormalise::toClassNamespace(implode('\\', $class));
     $class = $class ? $class . '\\' : null;
     // Check keywords
     if (in_array(strtolower($name), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $name);
     }
     if (in_array(strtolower($listName), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $listName);
     }
     if (in_array(strtolower($itemName), static::$keywords)) {
         throw new \InvalidArgumentException('Do not use reserved keywords: ' . $itemName);
     }
     $config['package.name'] = $name;
     $config['package.namespace'] = $class;
     $this->replace = new Structure();
     $this->replace['package.namespace'] = $class;
     $this->replace['package.name.lower'] = lcfirst($name);
     $this->replace['package.name.upper'] = strtoupper($name);
     $this->replace['package.name.cap'] = ucfirst($name);
     $this->replace['controller.list.name.lower'] = strtolower($listName);
     $this->replace['controller.list.name.upper'] = strtoupper($listName);
     $this->replace['controller.list.name.cap'] = ucfirst($listName);
     $this->replace['controller.item.name.lower'] = strtolower($itemName);
     $this->replace['controller.item.name.upper'] = strtoupper($itemName);
     $this->replace['controller.item.name.cap'] = ucfirst($itemName);
     // Set replace to config.
     $config->mergeTo('replace', $this->replace);
     // Set copy dir.
     $config->set('dir.dest', WINDWALKER_SOURCE . '/' . $this->replace['package.namespace'] . $this->replace['package.name.cap']);
     $config->set('dir.tmpl', PHOENIX_TEMPLATES . '/package/' . $config['template']);
     $config->set('dir.src', $config->get('dir.tmpl'));
     // Replace DS
     $config['dir.dest'] = Path::clean($config['dir.dest']);
     $config['dir.tmpl'] = Path::clean($config['dir.tmpl']);
     $config['dir.src'] = Path::clean($config['dir.src']);
     // Push container
     $this->container = $container;
     parent::__construct($io, $config, $this->replace->toArray());
 }