Пример #1
0
Файл: Dir.php Проект: jasny/Q
 /**
  * Class constructor
  * 
  * @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::dir($path) : (isset($options['path']) ? Fs::dir($options['path']) : null);
     if (isset($options['transformer'])) {
         $this->_transformer = $options['transformer'] instanceof Transformer ? $options['transformer'] : Transform::with($options['transformer']);
     }
     $this->_ext = isset($options['ext']) ? $options['ext'] : (isset($this->_transformer) ? $this->_transformer->ext : null);
     if (!isset($this->_transformer) && !empty($this->_ext)) {
         $this->_transformer = Transform::from($this->_ext);
     }
     \ArrayObject::__construct(array(), \ArrayObject::ARRAY_AS_PROPS);
     if (!empty($options['loadall'])) {
         $this->loadAll();
     }
 }