@param $folder

@return RegexIterator
168030
protected function getIterator($folder)
    {
        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($folder,
                \RecursiveDirectoryIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::SELF_FIRST,
            \RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied"
        );
        $files = new RegexIterator($iterator, '/^.+Exception\.php$/i', RecursiveRegexIterator::GET_MATCH);

        return $files;
    }
1289964
protected function createBreadcrumbJson(Folder $folder)
    {
        $breadcrumbs = array();
        while ($folder->exists()) {
            $breadcrumbs[] = array(
                'title' => $folder->Title,
                'id' => $folder->ID
            );

            $folder = $folder->Parent();
        }
        $breadcrumbs[] = array(
            'title' => ASSETS_DIR,
            'id' => 0
        );

        return array_reverse($breadcrumbs);
    }
704894
public function folder_validate($folder, &$char = null)
    {
        $delim = $this->get_hierarchy_delimiter();

        if (strpos($folder, $delim) !== false) {
            $char = $delim;
            return false;
        }

        return true;
    }
923736
public function deleteFolder($folder)
    {
        $folder = trim($folder, '/') . '/';

        // Fail if this pseudo directory key already exists
        if (!$this->isDir($folder)) {
            $path = $this->bucket . "/" . $folder;
            throw new ExceptionStorage("Directory {$path} Not found or Not Is Diretory", static::E_NOT_IS_DIR);
        }

        return (bool) $this->clientS3->deleteMatchingObjects($this->bucket, $folder);
    }
1321858
private function recurseFolders(ExtendedFolderInterface $folder)
    {
        $volume = $folder->getVolume();
        $subFolders = $volume->findFoldersByParentFolder($folder);

        $permissionRegistry = $this->get('phlexible_access_control.permission_registry');

        $children = [];
        foreach ($subFolders as $subFolder) {
            /* @var $subFolder ExtendedFolderInterface */

            if (!$this->isGranted('ROLE_SUPER_ADMIN') && !$this->isGranted('FOLDER_READ', $folder)) {
                continue;
            }

            // TODO: fix
            $userRights = array();
            foreach ($permissionRegistry->get(get_class($subFolder))->all() as $permission) {
                $userRights[] = $permission->getName();
            }

            $tmp = [
                'id' => $subFolder->getId(),
                'text' => $subFolder->getName(),
                'leaf' => false,
                'numChilds' => $volume->countFilesByFolder($subFolder),
                'draggable' => true,
                'expanded' => true,
                'allowDrop' => true,
                'allowChildren' => true,
                'isTarget' => true,
                'rights' => $userRights,
            ];

            if ($volume->countFoldersByParentFolder($subFolder)) {
                $tmp['children'] = $this->recurseFolders($subFolder);
                $tmp['expanded'] = false;
            } else {
                $tmp['children'] = [];
                $tmp['expanded'] = true;
            }

            $children[] = $tmp;
        }

        return $children;
    }
526082
public static function getDefaultParams($folder=null, $element=null)
	{
		$plugin = \Plugin::byType($folder, $element);

		return new Registry($plugin->params);
	}
1315175
public function createFolder($folder)
    {
        $folder = trim($folder, "/") . "/";

        if ($folder === "/") {
            return true;
        }

        // Fail if this pseudo directory key already exists
        if ($this->exists($folder)) {
            return true;
        }

        $response = $this->clientS3->putObject(array(
            'Bucket' => $this->bucket,
            'Key'    => $folder,
            'ACL'    => static::ACL_PUBLIC_READ,
            'Body'   => "",
        ));

        return (bool) $response;
    }
436399
public function addChildren(Folder $folder)
    {
        $ids = '';
        foreach ($folder->getChildren() as $child) {
            $ids .= ' and folder.id != '.$child->getId();
            $ids .= $this->addChildren($child);
        }

        return $ids;
    }
674385
public function trashRestoreFolderAction(Folder $folder)
    {
        $folder->setIsDeleted(false);

        $this->persist($folder, true);

        $this->addFlash('success', 'Папка восстановлена.');

        return $this->redirectToRoute('cms_admin_structure_trash');
    }
609784
public function createFolder($folder, $allFolders = FALSE)
    {
        if (substr($folder, -1) != '/') $folder = $folder . '/';
        if (!is_dir($folder)) {
            @mkdir($folder, 0777, $allFolders) or die ("Error creating folder '{$folder}'.");
        }
    }
59870
public static function getFilesystemFilesInFolder(FilesystemFolder $folder) {

		$files = [];

		$glob = glob($folder->getPath() . '*', GLOB_NOSORT);

		if($glob !== FALSE) {

			foreach($glob as $f) {
				if(!is_dir($f)) {

					if(!isset(self::$instances[$f])) {
						self::$instances[$f] = new self(basename($f), $folder);
					}

					$files[] = self::$instances[$f];
				}
			}
		}

		return $files;
	}
782358
public function IsFolderMatchingFilter($path, $regexFilter) {
        return \Puzzlout\Framework\Helpers\RegexHelper::Init($path)->IsMatch($regexFilter);
    }
951336
public static function addFormatterFolder($folder)
    {
        if (! is_dir($folder)) {
            return;
        }

        array_unshift(self::$formatterDirectories, $folder);
        self::$list = null;
    }
590262
protected function normalizeFolderInfo(array & $folder, $localizer)
    {
        if(empty(array_get($folder, 'type')) && !empty(array_get($folder, 'path'))){
            $folder['type'] = 'dir';
        }
        parent::normalizeFolderInfo($folder, $localizer);
        $folder['last_modified'] = gmdate('D, d M Y H:i:s \G\M\T', array_get($folder, 'timestamp', 0));
        unset($folder['timestamp']);
    }
489231
public function folder(Folder $folder = null)
    {
        if (is_null($folder)) {
            return $this->folder;
        }

        $this->folder = $folder;

        return $this;
    }
1365932
public function get_permflags($folder)
    {
        if (!strlen($folder)) {
            return array();
        }

        if (!$this->check_connection()) {
            return array();
        }

        if ($this->conn->select($folder)) {
            $permflags = $this->conn->data['PERMANENTFLAGS'];
        }
        else {
            return array();
        }

        if (!is_array($permflags)) {
            $permflags = array();
        }

        return $permflags;
    }
834359
protected function detectInFolder($folder, $lookup = null)
    {
        $folder = rtrim($folder, '/');
        $path = trim(Folder::getRelativePath($folder), '/');
        $base = $path === $folder ? '' : ($path ? substr($folder, 0, -strlen($path)) : $folder . '/');

        $list = [];

        if (is_dir($folder)) {
            $iterator = new \DirectoryIterator($folder);

            /** @var \DirectoryIterator $directory */
            foreach ($iterator as $directory) {
                if (!$directory->isDir() || $directory->isDot()) {
                    continue;
                }

                $name = $directory->getFilename();
                $find = ($lookup ?: $name) . '.yaml';
                $filename = "{$path}/{$name}/{$find}";

                if (file_exists($base . $filename)) {
                    $basename = $this->base . $name;
                    $list[$basename] = ['file' => $filename, 'modified' => filemtime($base . $filename)];
                }
            }
        }

        return $list;
    }