单例化
@param $size int 每页行数
@param $order string 排序依据字段
@param $dir string 排序方向
@return Page
5316
public static function instance($size = null, $order = 'id', $dir = 'desc'): Page
    {
        static $handle;
        if (!$handle) {
            $handle = new self ($size, $order, $dir);
        }
        return $handle;
    }
234212
public function findPage($page = null, $size = self::PAGE_SIZE, $filter = null)
    {
        try {
            $offset = ($page - 1) * $size;
            return $this->select(null, $filter, $size, $offset)->fetchAll(\PDO::FETCH_ASSOC);
        } catch (\PDOException $e) {
            throw new StorageException($e->getMessage());
        }
    }
65666
public function sizeUrl($size)
    {
        if (($this->base['return_format'] === 'array') && isset($this->base['value']['sizes'][$size])) {
            return $this->base['value']['sizes'][$size];
        } elseif ($this->base['return_format'] === 'id') {
            if ($src = wp_get_attachment_image_src($this->id(), $size)) {
                return $src[0];
            }
        }

        return '';
    }
1276335
public function getImageSrc($type, $size)
	{
		if (empty($this->$type))
		{
			return null;
		}
		return $this->getImageConfig($type, $size, 'dir') . $this->$type;
	}
540180
public static function getDirectorySize($dir) {
		if (is_dir($dir)) {
			$totalSize = 0;
			$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
			foreach($iterator as $file) {
				$totalSize += $file->getSize();
			}
			return $totalSize;
		}
		return false;
	}
1204683
public static function fromString($resource = '', $size = null)
    {
        $stream = fopen('php://temp', 'r+');

        if ($resource !== '') {
            fwrite($stream, $resource);
            fseek($stream, 0);
        }

        return new self($stream, $size);
    }
367095
public function batch($size)
    {
        $chunks = array_chunk($this->items, $size, true);

        $list = [];
        foreach ($chunks as $chunk) {
            $list[] = new static($chunk, $this->params, $this->pages);
        }

        return $list;
    }
702741
public static function createDir($dir, $mode = 0777)
    {
        if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
        if (!static::createDir(dirname($dir), $mode)) return FALSE;
        return @mkdir($dir, $mode);
    }
772343
public function forcedImageDownsize($fail, $id, $size) {
        if(empty($size) || empty($id) || is_array($size)) {
            return $fail;
        }

        $meta = wp_get_attachment_metadata($id);

        if(empty($meta)) {
            return $fail;
        }

        if(!isset($meta['sizes'])) {
            return $fail;
        }

        if(!isset($meta['sizes'][$size])) {
            return $fail;
        }

        $isOffloadS3 = (arrayPath($meta, 's3/provider', null) == 'aws');

        $sizeMeta = $meta['sizes'][$size];
        if(!isset($sizeMeta['s3'])) {
            if ($isOffloadS3) {
                if ($this->fixOffloadS3Meta($id, $meta)) {
                    return $this->forcedImageDownsize($fail, $id, $size);
                } else {
                    return $fail;
                }
            } else {
                return $fail;
            }
        }

        $url = $this->getAttachmentURLFromMeta($sizeMeta);// $sizeMeta['s3']['url'];

        $result = [
            $url,
            $sizeMeta['width'],
            $sizeMeta['height'],
            true
        ];

        return $result;
    }
1038789
public function sort(PageInterface $page, $order_by = null, $order_dir = null, $sort_flags = null)
    {
        if ($order_by === null) {
            $order_by = $page->orderBy();
        }
        if ($order_dir === null) {
            $order_dir = $page->orderDir();
        }

        $path = $page->path();
        $children = $this->children[$path] ?? [];

        if (!$children) {
            return $children;
        }

        if (!isset($this->sort[$path][$order_by])) {
            $this->buildSort($path, $children, $order_by, $page->orderManual(), $sort_flags);
        }

        $sort = $this->sort[$path][$order_by];

        if ($order_dir !== 'asc') {
            $sort = array_reverse($sort);
        }

        return $sort;
    }
727168
public function order($orderFlag, $dir = 'desc')
    {
        if (!in_array($orderFlag, static::$orderCriteria)) {
            throw new InvalidArgumentException("Invalid order criteria '{$orderFlag}'");
        }

        $this->order = $orderFlag;
        $this->orderDir = strtolower($dir) === 'asc' ? 0 : 1;

        return $this;
    }
167622
public function read(int $size = null)
    {
        if ($this->file == null) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Cannot read file for unopened file",
                "solution" =>
                    "Please open the file with [FileListener::open] before trying to get read it.")));
        }
        if ($size === null) {
            return (fread($this->file, $this->size()));
        } else {
            return (fread($this->file, $size));
        }
    }
483926
static function chdir($dir, $callback = null, $argv = array())
    {
        if (!is_dir($dir)) {
            throw new \InvalidArgumentException("$dir does not exist.");
        }

        $cwd = getcwd();
        chdir($dir);

        if (null === $callback) {
            return;
        }

        $returnValue = call_user_func_array($callback, $argv);

        chdir($cwd);
        return $returnValue;
    }
138464
public function src($email, $size = null, $rating = null)
    {
        if (is_null($size)) {
            $size = $this->getSize();
        }

        $size = max(1, min(512, $size));

        $this->setSize($size);

        if ( ! is_null($rating)) {
            $this->setRating($rating);
        }

        return $this->get($email);
    }
554402
public function query($queryString, $type, $start = 0, $count = 10, $order = 'id', $dir = 'DESC') {
        $rootClass = $this->getClass($type);
        $results = $rootClass->searchInstances([
            OntologyRdfs::RDFS_LABEL => $queryString
        ], array(
            'recursive' => true,
            'like'      => true,
            'offset'    => $start,
            'limit'     => $count,
        ));
        $ids = array();
        foreach ($results as $resource) {
            $ids[] = $resource->getUri();
        }

        return new ResultSet($ids, $this->getTotalCount($queryString, $rootClass));
    }
634527
public static function directory_size($dir)
    {
        $size = 0;
        foreach(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS)) as $file => $key) {
            if ($key->isFile()) {
                $size += $key->getSize();
            }
        }
        return $size;
    }
39973
public function processCrop($size, $upload_path, $file, $sizeMeta) {
		$upload_info = wp_upload_dir();
		$subdir = trim(str_replace($upload_info['basedir'], '', $upload_path), '/');
		$upload_path = rtrim(str_replace($subdir, '', $upload_path), '/');

		if($this->client && $this->client->enabled()) {
			$sizeMeta = $this->processFile($upload_path, $subdir.'/'.$file, $sizeMeta);
		}

		return $sizeMeta;
	}