PHP Class PHPExiftool\Reader

It scans files and directories, and provide an iterator on the FileEntities generated based on the results. Example usage: $Reader = new Reader(); $Reader->in('/path/to/directory') ->exclude('tests') ->extensions(array('jpg', 'xml)); Throws an exception if no file found $first = $Reader->first(); Returns null if no file found $first = $Reader->getOneOrNull(); foreach($Reader as $entity) { Do your logic with FileEntity }
Author: Romain Neutron ([email protected])
Inheritance: implements IteratorAggregate
Show file Open project: romainneutron/PHPExiftool Class Usage Examples

Protected Properties

Property Type Description
$collection Doctrine\Common\Collections\ArrayCollection
$dirs
$excludeDirs
$exiftool
$extensions
$extensionsToggle
$files
$followSymLinks
$ignoreDotFile
$parser
$readers
$recursive
$sort

Public Methods

Method Description
__construct ( Exiftool $exiftool, RDFParser $parser ) Constructor
__destruct ( )
all ( ) : ArrayCollection Perform the scan and returns all the results
append ( Reader $reader ) : Reader Append a reader to this one.
create ( Psr\Log\LoggerInterface $logger )
exclude ( string | array $dirs ) : Reader Exclude directories from scan
extensions ( string | array $extensions, boolean $restrict = true ) : Reader Restrict / Discard files based on extensions Extensions are case insensitive
files ( string | array $files ) : Reader Add files to scan
first ( ) : FileEntity Return the first result. If no result available, throws an exception
followSymLinks ( ) : Reader Toggle to enable follow Symbolic Links
getIterator ( ) : Iterator Implements \IteratorAggregate Interface
getOneOrNull ( ) : FileEntity Return the first result. If no result available, null is returned
ignoreDotFiles ( ) : Reader Ignore files starting with a dot (.)
in ( string | array $dirs ) : Reader Add dirs to scan
notRecursive ( ) : Reader Disable recursivity in directories scan.
reset ( )
sort ( string | array $by ) : Reader Sort results with one or many criteria

Protected Methods

Method Description
buildQuery ( ) : string Build query from criterias
buildQueryAndExecute ( ) : ArrayCollection Build the command returns an ArrayCollection of FileEntity
computeExcludeDirs ( string $rawExcludeDirs, $rawSearchDirs ) : array Compute raw exclude rules to simple ones, based on exclude dirs and search dirs
resetResults ( ) : Reader Reset any computed result

Method Details

__construct() public method

Constructor
public __construct ( Exiftool $exiftool, RDFParser $parser )
$exiftool Exiftool
$parser RDFParser

__destruct() public method

public __destruct ( )

all() public method

Perform the scan and returns all the results
public all ( ) : ArrayCollection
return Doctrine\Common\Collections\ArrayCollection

append() public method

Finale result will be the sum of the current reader and all appended ones.
public append ( Reader $reader ) : Reader
$reader Reader The reader to append
return Reader

buildQuery() protected method

Build query from criterias
protected buildQuery ( ) : string
return string

buildQueryAndExecute() protected method

Build the command returns an ArrayCollection of FileEntity
protected buildQueryAndExecute ( ) : ArrayCollection
return Doctrine\Common\Collections\ArrayCollection

computeExcludeDirs() protected method

Compute raw exclude rules to simple ones, based on exclude dirs and search dirs
protected computeExcludeDirs ( string $rawExcludeDirs, $rawSearchDirs ) : array
$rawExcludeDirs string
return array

create() public static method

public static create ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface

exclude() public method

Warning: only first depth directories can be excluded Imagine a directory structure like below, With a scan in "root", only sub1 or sub2 can be excluded, not subsub. root ├── sub1 └── sub2    └── subsub Example usage: Will scan documents recursively, discarding documents/test $Reader ->in('documents') ->exclude(array('test'))
public exclude ( string | array $dirs ) : Reader
$dirs string | array The directories
return Reader

extensions() public method

Restrict / Discard files based on extensions Extensions are case insensitive
public extensions ( string | array $extensions, boolean $restrict = true ) : Reader
$extensions string | array The list of extension
$restrict boolean Toggle restrict/discard method
return Reader

files() public method

Example usage: Will scan 3 files : dc00.jpg in CWD and absolute paths /tmp/image.jpg and /tmp/raw.CR2 $Reader ->files('dc00.jpg') ->files(array('/tmp/image.jpg', '/tmp/raw.CR2'))
public files ( string | array $files ) : Reader
$files string | array The files
return Reader

first() public method

Return the first result. If no result available, throws an exception
public first ( ) : FileEntity
return FileEntity

getIterator() public method

Implements \IteratorAggregate Interface
public getIterator ( ) : Iterator
return Iterator

getOneOrNull() public method

Return the first result. If no result available, null is returned
public getOneOrNull ( ) : FileEntity
return FileEntity

ignoreDotFiles() public method

Folders starting with a dot are always exluded due to exiftool behaviour. You should include them manually
public ignoreDotFiles ( ) : Reader
return Reader

in() public method

Example usage: Will scan 3 dirs : documents in CWD and absolute paths /usr and /var $Reader ->in('documents') ->in(array('/tmp', '/var'))
public in ( string | array $dirs ) : Reader
$dirs string | array The directories
return Reader

notRecursive() public method

If you only specify files, this toggle has no effect
public notRecursive ( ) : Reader
return Reader

reset() public method

public reset ( )

resetResults() protected method

Reset any computed result
protected resetResults ( ) : Reader
return Reader

sort() public method

Example usage: Will sort by directory then filename $Reader ->in('documents') ->sort(array('directory', 'filename')) Will sort by filename $Reader ->in('documents') ->sort('filename')
public sort ( string | array $by ) : Reader
$by string | array
return Reader

Property Details

$collection protected property

protected ArrayCollection,Doctrine\Common\Collections $collection
return Doctrine\Common\Collections\ArrayCollection

$dirs protected property

protected $dirs

$excludeDirs protected property

protected $excludeDirs

$exiftool protected property

protected $exiftool

$extensions protected property

protected $extensions

$extensionsToggle protected property

protected $extensionsToggle

$files protected property

protected $files

$ignoreDotFile protected property

protected $ignoreDotFile

$parser protected property

protected $parser

$readers protected property

protected $readers

$recursive protected property

protected $recursive

$sort protected property

protected $sort