Newscoop\Storage::listItems PHP Метод

listItems() публичный Метод

List items
public listItems ( string $key ) : mixed
$key string
Результат mixed
    public function listItems($key)
    {
        $path = $this->getPath($key, TRUE);
        if (!$path) {
            throw new \InvalidArgumentException($key, self::ERROR_NOT_FOUND);
        }
        if (!is_dir($path)) {
            throw new \InvalidArgumentException($key, self::ERROR_NOT_DIR);
        }
        $items = array();
        foreach (glob("{$path}/*") as $file) {
            $items[] = basename($file);
        }
        return $items;
    }

Usage Example

Пример #1
0
 /**
  *
  */
 public function cacheTemplates($path)
 {
     try {
         $items = array();
         foreach ($this->storage->listItems($path) as $file) {
             $storageFile = $this->storage->getItem($file);
             if (!$storageFile->isDir() && $storageFile->getType() == 'tpl') {
                 $items[] = $this->repository->getTemplate($storageFile);
             }
         }
         return $this->repository->flush();
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf("'%s' not found", $path), $e->getCode(), $e);
     }
 }