コード例 #1
0
ファイル: GridHelper.php プロジェクト: ventoviro/phoenix
 /**
  * Created date.
  *
  * @param string $format The date format.
  * @param bool   $local  Use local timezone.
  *
  * @return string Date string.
  */
 public function createdDate($format = '', $local = false)
 {
     $field = $this->config->get('field.created', 'created');
     $format = $format ?: DateTime::$format;
     if ($local) {
         return DateTime::toLocalTime($this->current->{$field}, $format);
     }
     return DateTime::create($this->current->{$field})->format($format);
 }
コード例 #2
0
 /**
  * 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());
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * dumpOrphans
  *
  * @param string $format
  *
  * @return  void
  *
  * @throws \Windwalker\Filesystem\Exception\FilesystemException
  */
 public static function dumpOrphans($format = 'ini')
 {
     $format = strtolower($format);
     $ext = $format === 'yaml' ? 'yml' : $format;
     $file = WINDWALKER_TEMP . '/language/orphans.' . $ext;
     if (!is_file($file)) {
         Folder::create(dirname($file));
         file_put_contents($file, '');
     }
     $orphans = new Structure();
     $orphans->loadFile($file, $format, array('processSections' => true));
     $orphans->loadString(static::getFormattedOrphans($format), $format, array('processSections' => true));
     file_put_contents($file, $orphans->toString($format, array('inline' => 99)));
 }