/**
  * @param IStorable $storable
  *
  * @return IStorable
  * @throws StorageException
  */
 public function load(IStorable $storable)
 {
     if ($this->hasStorable($guid = $storable->guid())) {
         return $this->storable($guid);
     }
     $selectQuery = new SelectQuery();
     $guid = $storable->guid();
     $selectQuery->select(new AsteriskFragment())->from(new SelectTable($storable->schema()->getName()))->where($this->whereIdentifier($guid));
     if (($one = $this->select($selectQuery, $storable)->storable()) === null) {
         throw new StorageException(sprintf('Storable [%s (%s)] not found by given guid [%s].', get_class($storable), $storable->schema()->getName(), $guid));
     }
     $this->register($one);
     return $one;
 }
예제 #2
0
 public function format(IFormatterProvider $formatterProvider)
 {
     $this->distinct();
     if (!empty($this->pathList)) {
         $this->where($wherePath = new WhereChain());
         foreach ($this->pathList as $path) {
             $wherePath->orr(new WhereExpression(new DelimiteFragment('file'), 'LIKE', new ParameterFragment($path, $path)));
         }
     }
     if (!empty($this->extensionList)) {
         $this->where($whereExtension = new WhereChain());
         foreach ($this->extensionList as $extension) {
             $extensionFragment = new DelimiteFragment('extension');
             $whereExtension->orr($extension ? new WhereExpression($extensionFragment, '=', new ParameterFragment($extension, $extension)) : new WhereIsNull($extensionFragment));
         }
     }
     if (isset($wherePath) && isset($whereExtension)) {
         $this->where(new WhereGroup($wherePath, 'AND', $whereExtension));
     }
     return parent::format($formatterProvider);
 }