[COMPOSER] Add new php-ffmpeg package
This commit is contained in:
318
vendor/phpdocumentor/fileset/src/phpDocumentor/Fileset/Collection.php
vendored
Normal file
318
vendor/phpdocumentor/fileset/src/phpDocumentor/Fileset/Collection.php
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
/**
|
||||
* phpDocumentor
|
||||
*
|
||||
* PHP Version 5
|
||||
*
|
||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||
* @copyright 2010-2011 Mike van Riel / Naenius (http://www.naenius.com)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
|
||||
namespace phpDocumentor\Fileset;
|
||||
|
||||
/**
|
||||
* Files container handling directory scanning, project root detection and ignores.
|
||||
*
|
||||
* Always set any filtering options (extensions, ignore patterns, hidden files, symlinks)
|
||||
* _before_ adding any directories or files. Such filtering is done immediately
|
||||
* upon loading the directory/file. As such, setting filtering options
|
||||
* _after_ adding directories/files will seem as though your filters were ignored.
|
||||
*
|
||||
* @author Mike van Riel <mike.vanriel@naenius.com>
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link http://phpdoc.org
|
||||
*/
|
||||
class Collection extends \ArrayObject
|
||||
{
|
||||
/** @var bool Whether to follow symlinks*/
|
||||
protected $follow_symlinks = false;
|
||||
|
||||
/** @var bool Whether to ignore hidden files and folders */
|
||||
protected $ignore_hidden = false;
|
||||
|
||||
/** @var Collection\IgnorePatterns */
|
||||
protected $ignore_patterns = array();
|
||||
|
||||
/** @var \ArrayObject Array containing a list of allowed line endings */
|
||||
protected $allowed_extensions = null;
|
||||
|
||||
/** @var string[] An array containing file names */
|
||||
protected $files = array();
|
||||
|
||||
/**
|
||||
* Initializes the finding component.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->ignore_patterns = new Collection\IgnorePatterns();
|
||||
$this->allowed_extensions = new \ArrayObject(
|
||||
array('php', 'php3', 'phtml')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the patterns by which to detect which files to ignore.
|
||||
*
|
||||
* @param array $patterns Glob-like patterns to filter files.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnorePatterns(array $patterns)
|
||||
{
|
||||
$this->ignore_patterns = new Collection\IgnorePatterns($patterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ignore patterns.
|
||||
*
|
||||
* @return Collection\IgnorePatterns
|
||||
*/
|
||||
public function getIgnorePatterns()
|
||||
{
|
||||
return $this->ignore_patterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a list of allowed extensions; if not used php, php3 and phtml
|
||||
* is assumed.
|
||||
*
|
||||
* @param array $extensions An array containing extensions to match for.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAllowedExtensions(array $extensions)
|
||||
{
|
||||
$this->allowed_extensions = new \ArrayObject($extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file extension to the list of allowed extensions.
|
||||
*
|
||||
* No dot is necessary and will even prevent the extension from being
|
||||
* picked up.
|
||||
*
|
||||
* @param string $extension Allowed file Extension to add (i.e. php).
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addAllowedExtension($extension)
|
||||
{
|
||||
$this->allowed_extensions->append($extension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the content of a set of directories to the list of files to parse.
|
||||
*
|
||||
* @param array $paths The paths whose contents to add to the collection.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addDirectories(array $paths)
|
||||
{
|
||||
foreach ($paths as $path) {
|
||||
$this->addDirectory($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all files in the given directory and add them to the parsing list.
|
||||
*
|
||||
* @param string $path A path to a folder, may be relative, absolute or
|
||||
* even phar.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addDirectory($path)
|
||||
{
|
||||
$finder = new \Symfony\Component\Finder\Finder();
|
||||
|
||||
$patterns = $this->getIgnorePatterns()->getRegularExpression();
|
||||
|
||||
if ($this->follow_symlinks) {
|
||||
$finder->followLinks();
|
||||
}
|
||||
|
||||
// restrict names to those ending in the given extensions
|
||||
$finder
|
||||
->files()
|
||||
->in($path)
|
||||
->name(
|
||||
'/\.('.implode('|', $this->allowed_extensions->getArrayCopy()).')$/'
|
||||
)
|
||||
->ignoreDotFiles($this->getIgnoreHidden())
|
||||
->filter(
|
||||
function(\SplFileInfo $file) use ($patterns) {
|
||||
if (!$patterns) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// apply ignore list on path instead of file, finder
|
||||
// can't do that by default
|
||||
return !preg_match($patterns, $file->getPathname());
|
||||
}
|
||||
);
|
||||
|
||||
try {
|
||||
/** @var \SplFileInfo $file */
|
||||
foreach ($finder as $file) {
|
||||
$file = new File($file);
|
||||
$path = $file->getRealPath()
|
||||
? $file->getRealPath()
|
||||
: $file->getPathname();
|
||||
|
||||
$this[$path] = $file;
|
||||
}
|
||||
} catch(\LogicException $e)
|
||||
{
|
||||
// if a logic exception is thrown then no folders were included
|
||||
// for phpDocumentor this is not an issue since we accept separate
|
||||
// files as well
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a list of individual files to the collection.
|
||||
*
|
||||
* @param array $paths File locations, may be absolute, relative or even phar.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addFiles(array $paths)
|
||||
{
|
||||
foreach ($paths as $path) {
|
||||
$this->addFile($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a file to the collection.
|
||||
*
|
||||
* @param string $path File location, may be absolute, relative or even phar.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addFile($path)
|
||||
{
|
||||
$paths = $this->getGlobbedPaths($path);
|
||||
foreach ($paths as $path) {
|
||||
$file = new File($path);
|
||||
$path = $file->getRealPath()
|
||||
? $file->getRealPath()
|
||||
: $file->getPathname();
|
||||
|
||||
$this[$path] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a globbed list out of the given path.
|
||||
*
|
||||
* This wrapper method normalizes for OS-divergent behavior of the native glob() function.
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
protected function getGlobbedPaths($path)
|
||||
{
|
||||
$paths = glob($path);
|
||||
|
||||
/*
|
||||
* Windows glob('') returns an array with one empty member...
|
||||
* 'nix glob('') returns an empty array...
|
||||
* we'd prefer to have the File('') constructor throw the exception in this edge case,
|
||||
* so keep the Windows behavior.
|
||||
*/
|
||||
$result = (array() === $paths) ? array('') : $paths;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of file paths that are ready to be parsed.
|
||||
*
|
||||
* Please note that the ignore pattern will be applied and all files are
|
||||
* converted to absolute paths.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getFilenames()
|
||||
{
|
||||
return array_keys($this->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the project root from the given files by determining their
|
||||
* highest common path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getProjectRoot()
|
||||
{
|
||||
$base = '';
|
||||
$files = array_keys($this->getArrayCopy());
|
||||
$parts = explode(DIRECTORY_SEPARATOR, reset($files));
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$base_part = $base . $part . DIRECTORY_SEPARATOR;
|
||||
foreach ($files as $dir) {
|
||||
if (substr($dir, 0, strlen($base_part)) != $base_part) {
|
||||
return $base;
|
||||
}
|
||||
}
|
||||
|
||||
$base = $base_part;
|
||||
}
|
||||
|
||||
return $base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to ignore hidden files and folders.
|
||||
*
|
||||
* @param boolean $ignore_hidden if true skips hidden files and folders.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setIgnoreHidden($ignore_hidden)
|
||||
{
|
||||
$this->ignore_hidden = $ignore_hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether files and folders that are hidden are ignored.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIgnoreHidden()
|
||||
{
|
||||
return $this->ignore_hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to follow symlinks.
|
||||
*
|
||||
* PHP version 5.2.11 is at least required since the
|
||||
* RecursiveDirectoryIterator does not support the FOLLOW_SYMLINKS
|
||||
* constant before that version.
|
||||
*
|
||||
* @param boolean $follow_symlinks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setFollowSymlinks($follow_symlinks)
|
||||
{
|
||||
$this->follow_symlinks = $follow_symlinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to follow symlinks.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getFollowSymlinks()
|
||||
{
|
||||
return $this->follow_symlinks;
|
||||
}
|
||||
|
||||
}
|
||||
63
vendor/phpdocumentor/fileset/src/phpDocumentor/Fileset/Collection/IgnorePatterns.php
vendored
Normal file
63
vendor/phpdocumentor/fileset/src/phpDocumentor/Fileset/Collection/IgnorePatterns.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace phpDocumentor\Fileset\Collection;
|
||||
|
||||
class IgnorePatterns extends \ArrayObject
|
||||
{
|
||||
public function getRegularExpression()
|
||||
{
|
||||
$pattern = '';
|
||||
|
||||
if ($this->count() > 0) {
|
||||
$patterns = array();
|
||||
foreach ($this as $item) {
|
||||
$this->convertToPregCompliant($item);
|
||||
$patterns[] = $item;
|
||||
}
|
||||
|
||||
$pattern = '/('.implode('|', $patterns).')$/';
|
||||
}
|
||||
|
||||
return $pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts $string into a string that can be used with preg_match.
|
||||
*
|
||||
* @param string &$string Glob-like pattern with wildcards ? and *.
|
||||
*
|
||||
* @author Greg Beaver <cellog@php.net>
|
||||
* @author mike van Riel <mike.vanriel@naenius.com>
|
||||
*
|
||||
* @see PhpDocumentor/phpDocumentor/Io.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function convertToPregCompliant(&$string)
|
||||
{
|
||||
$y = (DIRECTORY_SEPARATOR == '\\') ? '\\\\' : '\/';
|
||||
$string = str_replace('/', DIRECTORY_SEPARATOR, $string);
|
||||
$x = strtr(
|
||||
$string,
|
||||
array(
|
||||
'?' => '.',
|
||||
'*' => '.*',
|
||||
'.' => '\\.',
|
||||
'\\' => '\\\\',
|
||||
'/' => '\\/',
|
||||
'[' => '\\[',
|
||||
']' => '\\]',
|
||||
'-' => '\\-'
|
||||
)
|
||||
);
|
||||
|
||||
if ((strpos($string, DIRECTORY_SEPARATOR) !== false)
|
||||
&& (strrpos($string, DIRECTORY_SEPARATOR) === strlen($string) - 1)
|
||||
) {
|
||||
$x = "(?:.*$y$x?.*|$x.*)";
|
||||
}
|
||||
|
||||
$string = $x;
|
||||
}
|
||||
|
||||
}
|
||||
131
vendor/phpdocumentor/fileset/src/phpDocumentor/Fileset/File.php
vendored
Normal file
131
vendor/phpdocumentor/fileset/src/phpDocumentor/Fileset/File.php
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace phpDocumentor\Fileset;
|
||||
|
||||
class File extends \SplFileInfo
|
||||
{
|
||||
/**
|
||||
* Open file for reading, and if it doesn't exist create it.
|
||||
*
|
||||
* @param string|\SplFileInfo $file
|
||||
*
|
||||
* @throws \InvalidArgumentException if an invalid type was passed
|
||||
*/
|
||||
public function __construct($file)
|
||||
{
|
||||
if ($file instanceof \SplFileInfo) {
|
||||
$file = $file->getPathname();
|
||||
}
|
||||
|
||||
if (!is_string($file)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Expected filename or object of type SplFileInfo but received '
|
||||
. get_class($file)
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($file)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Expected filename or object of type SplFileInfo but received nothing at all'
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mime type for this file.
|
||||
*
|
||||
* @throws \RuntimeException if finfo failed to load
|
||||
* and/or mime_content_type is unavailable
|
||||
* @throws \LogicException if the mime type could not be interpreted
|
||||
* from the output of finfo_file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMimeType()
|
||||
{
|
||||
if (function_exists('finfo_open')) {
|
||||
$finfo = finfo_open(FILEINFO_MIME);
|
||||
if (!$finfo) {
|
||||
throw new \RuntimeException('Failed to open finfo');
|
||||
}
|
||||
|
||||
$actualInfo = @finfo_file($finfo, $this->getPathname());
|
||||
if (false === $actualInfo) {
|
||||
throw new \RuntimeException('Failed to read file info via finfo');
|
||||
}
|
||||
$mime = strtolower($actualInfo);
|
||||
finfo_close($finfo);
|
||||
|
||||
if (!preg_match(
|
||||
'/^([a-z0-9]+\/[a-z0-9\-\.]+);\s+charset=(.*)$/', $mime, $matches
|
||||
)) {
|
||||
throw new \LogicException(
|
||||
'An error parsing the MIME type "'.$mime.'".'
|
||||
);
|
||||
}
|
||||
|
||||
return $matches[1];
|
||||
} elseif (function_exists('mime_content_type')) {
|
||||
return mime_content_type($this->getPathname());
|
||||
}
|
||||
|
||||
throw new \RuntimeException(
|
||||
'The finfo extension or mime_content_type function are needed to '
|
||||
.'determine the Mime Type for this file.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file contents as a string.
|
||||
*
|
||||
* @return string
|
||||
* @throws \RuntimeException if unable to open the file
|
||||
*/
|
||||
public function fread()
|
||||
{
|
||||
try {
|
||||
$file = $this->openFile('r');
|
||||
} catch (\Exception $exc) {
|
||||
throw new \RuntimeException('Unable to open file', 0, $exc);
|
||||
}
|
||||
|
||||
$result = '';
|
||||
foreach ($file as $line) {
|
||||
$result .= $line;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename, relative to the given root.
|
||||
*
|
||||
* @param string $root_path The root_path of which this file is composed.
|
||||
*
|
||||
* @throws \InvalidArgumentException if file is not in the project root.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @todo this protected method is unused in this class... can it be removed?
|
||||
*/
|
||||
protected function getFilenameRelativeToRoot($root_path)
|
||||
{
|
||||
// strip path from filename
|
||||
$result = ltrim(
|
||||
substr($this->getPathname(), strlen($root_path)),
|
||||
DIRECTORY_SEPARATOR
|
||||
);
|
||||
|
||||
if ($result === '') {
|
||||
throw new \InvalidArgumentException(
|
||||
'File "' . $this->getPathname() . '" is not present in the '
|
||||
.'given root: ' . $root_path
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user