Пример #1
0
 /**
  * return configured value
  *
  * Depending on type this can be a boolean, a string or an array.
  * For array, this can be used to retrieve sub-key of array, like this:
  *
  * val(array('field' => 'parentkey'))
  * val(array('field' => 'parentkey.subkey'))
  *
  * @see radium\model\Configurations::get()
  * @param object $entity instance of current Record
  * @param string $field what field (in case of array) to return
  * @param array $options an array of options currently supported are
  *              - `default` : what to return, if nothing is found
  *              - `flat`    : to flatten the result, if object/array-ish, defaults to false
  * @return mixed whatever can be returned
  */
 public function val($entity, $field = null, array $options = array())
 {
     $defaults = array('default' => null, 'flat' => false);
     $options += $defaults;
     switch ($entity->type) {
         case 'boolean':
             return (bool) $entity->value;
         case 'string':
             return (string) $entity->value;
         case 'list':
             $items = explode("\n", $entity->value);
             $result = array();
             foreach ($items as $item) {
                 $item = trim($item);
                 if (!empty($item)) {
                     $result[] = $item;
                 }
             }
             return $result;
         case 'navigation':
             return Converter::get('neon', $entity->value, $field, $options);
         case 'json':
         case 'neon':
         case 'ini':
         case 'array':
             return Converter::get($entity->type, $entity->value, $field, $options);
     }
     return $options['default'];
 }
Пример #2
0
 /**
  * reads content from file, converting it if matching converter is found.
  *
  * This method is able to understand library-relative paths. If file starts with a valid
  * library name followed by a slash, i.e. `radium/some-path/file.ext` it will find that file
  * on its own within the file-system. It automatically detects the base-path for that library
  * and will find the file within that library.
  *
  * @see radium\data\Converter::get()
  * @param string $file filename to retrieve contents from
  * @param array $data additional data to be put into `Converter::get()`
  * @param array $options additional options to be put into `Converter::get()`
  * @return mixed
  */
 public static function contents($file, $data = array(), array $options = array())
 {
     $defaults = array('convert' => true, 'type' => static::extension($file), 'default' => false);
     $options += $defaults;
     if (file_exists($file)) {
         $content = file_get_contents($file);
         return $options['convert'] ? Converter::get($options['type'], $content, $data, $options) : $content;
     }
     list($library, $filename) = explode('/', $file, 2);
     if (!($libraryPath = Libraries::get($library, 'path'))) {
         return $options['default'];
     }
     $file = sprintf('%s/%s', $libraryPath, $filename);
     if (file_exists($file)) {
         $content = file_get_contents($file);
         return $options['convert'] ? Converter::get($options['type'], $content, $data, $options) : $content;
     }
     return $options['default'];
 }
Пример #3
0
 /**
  * returns decoded content of asset
  *
  * @see radium\data\Converter::get()
  * @param object $asset instance of current record
  * @param array $data additional data to be passed into render context
  * @param array $options additional options to be passed into `Converter::get()`
  * @return array parsed content of Assets bytes
  */
 public function decode($asset, $data = array(), array $options = array())
 {
     return Converter::get($asset->type, $asset->file->getBytes(), $data, $options);
 }
Пример #4
0
 /**
  * returns parsed content of Contents body
  *
  * @see radium\data\Converter::get()
  * @param object $content instance of current record
  * @param array $data additional data to be passed into render context
  * @param array $options additional options to be passed into `Converter::get()`
  * @return array parsed content of Contents body
  */
 public function body($content, $data = array(), array $options = array())
 {
     return Converter::get($content->type, $content->body, $data, $options);
 }
Пример #5
0
 /**
  * return rendered content of a file
  *
  * @param string $file full path to file
  * @param array $options additional options
  *        - `field`: if rendered content is of type array and field is within, this is returned
  *        - `render`: set to false to return un-rendered content from file
  * @return mixed whatever the content may be
  */
 public static function read($file, $data = array(), array $options = array())
 {
     $defaults = array('field' => null, 'render' => true);
     $options += $defaults;
     $object = new SplFileInfo($file);
     if ($object->isDir()) {
         return false;
     }
     $type = $object->getExtension() ?: 'neon';
     return $options['render'] ? Converter::get($type, file_get_contents($file), $data, $options) : file_get_contents($file);
 }
Пример #6
0
 /**
  * returns all widgets from current Page
  *
  * @see radium\data\Converter::get()
  * @param object $entity instance of current record
  * @param string $field returns a certain field from widgets
  * @param array $options additional options to be passed into Converter::get()
  * @return array an array of widgets
  */
 public function widgets($entity, $field = null, array $options = array())
 {
     return Converter::get('neon', $entity->widgets, $field, $options);
 }