Exemplo n.º 1
0
Arquivo: PHP.php Projeto: jasny/Q
 /**
  * Class constructor
  * 
  * @param array $options Specific options: array('file'=>file_path) or array(file_path)
  */
 public function __construct($options = array())
 {
     if (isset($options[0])) {
         $options['file'] = Fs::file($options[0]);
     } elseif (isset($options['file']) && !$options['file'] instanceof Fs_Node) {
         $options['file'] = Fs::file($options['file']);
     }
     parent::__construct($options);
 }
Exemplo n.º 2
0
Arquivo: Replace.php Projeto: jasny/Q
 /**
  * Class constructor
  * 
  * @param array $options
  */
 public function __construct($options = array())
 {
     if (isset($options[0])) {
         $options['template'] = Fs::file($options[0]);
     } elseif (isset($options['file'])) {
         $options['template'] = Fs::file($options['file']);
     }
     unset($options[0], $options['file']);
     parent::__construct($options);
 }
Exemplo n.º 3
0
Arquivo: File.php Projeto: jasny/Q
 /**
  * Class constructor
  * 
  * @param string $path     OPTIONAL
  * @param array  $options
  */
 public function __construct($path, $options = array())
 {
     if (is_array($path)) {
         $options = $path + $options;
         $path = null;
         if (isset($options['driver'])) {
             if (isset($options[0])) {
                 if (!isset($options['path'])) {
                     $options['path'] = $options[0];
                 }
                 if (!isset($options['ext'])) {
                     $options['ext'] = $options['driver'];
                 }
                 unset($options[0]);
             } else {
                 $options[0] = $options['driver'];
             }
         }
     }
     if (isset($options[0])) {
         if (strpos($options[0], ':') !== false) {
             list($options['ext'], $options['path']) = explode(':', $options[0], 2);
         } else {
             $key = !isset($options['ext']) && strpos($options[0], '.') === false && strpos($options[0], '/') === false ? 'ext' : 'path';
             if (!isset($options[$key])) {
                 $options[$key] = $options[0];
             }
         }
     }
     $this->_path = isset($path) ? Fs::file($path) : (isset($options['path']) ? Fs::file($options['path']) : null);
     $ext = isset($options['ext']) ? $options['ext'] : (isset($this->_path) ? $this->_path->extension() : null);
     if (isset($options['transformer'])) {
         $this->_transformer = $options['transformer'] instanceof Transformer ? $options['transformer'] : Transform::with($options['transformer']);
     } elseif (!empty($ext)) {
         $this->_transformer = Transform::from($ext);
     }
     $values = isset($this->_path) && isset($this->_transformer) ? $this->_transformer->process($this->_path) : array();
     \ArrayObject::__construct(&$values, \ArrayObject::ARRAY_AS_PROPS);
 }
Exemplo n.º 4
0
 }
 /**
  * Transform data and save the result into a file.
  *
  * @param string $filename File name
  * @param mixed  $data
  * @param int    $flags    Fs::RECURSIVE and/or FILE_% flags as binary set.
  */
 function save($filename, $data = null, $flags = 0)
 {
     $out = $this->process($data);
     if (!is_scalar($out) && !(is_object($out) && method_exists($out, '__toString'))) {
         throw new Exception("Unable to save data to '{$filename}': Transformation returned a non-scalar value of type '" . gettype($out) . "'.");
     }
     if (!Fs::file($filename)->putContents((string) $out, $flags)) {
         throw new Exception("Failed to create file {$filename}.");
     }
Exemplo n.º 5
0
Arquivo: Dir.php Projeto: jasny/Q
 /**
  * ArrayAccess; Returns the value at specified offset, loading the section if needed.
  * 
  * @param string $key
  * @return Config_File
  */
 public function offsetGet($key)
 {
     if (parent::offsetExists($key)) {
         return parent::offsetGet($key);
     }
     $dirname = "{$this->_path}/{$key}";
     $filename = "{$dirname}.{$this->_ext}";
     $options = array();
     if ($this->_transformer) {
         $options['transformer'] = $this->_transformer;
     }
     if (is_dir($dirname)) {
         parent::offsetSet($key, new Config_Dir(Fs::dir($dirname), $options));
     } elseif (file_exists($filename)) {
         parent::offsetSet($key, new Config_File(Fs::file($filename), $options));
     } else {
         trigger_error("Configuration section '{$key}' doesn't exist for '{$this->_path}'", E_WARNING);
         return null;
     }
     return parent::offsetGet($key);
 }