Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes

Robo47_Exiftool Class Reference

List of all members.

Public Member Functions

 __construct ($exiftool= '/usr/bin/exiftool', $format=self::FORMAT_JSON)
 getExifs ($file, $format=null)
 Returns exifs of an image.
 getExiftool ()
 getFormat ()
 setExiftool ($exiftool)
 Set Exiftool.
 setFormat ($format)

Public Attributes

const FORMAT_ARRAY = 'array'
 Format ARRAY.
const FORMAT_JSON = 'json'
 Format JSON.
const FORMAT_XML = 'xml'
 Format XML.

Protected Member Functions

 _runExiftool ($file, $format)

Protected Attributes

 $_exiftool = '/usr/bin/exiftool'
 $_format = null

Detailed Description

Definition at line 34 of file Exiftool.php.


Constructor & Destructor Documentation

Robo47_Exiftool::__construct ( exiftool = '/usr/bin/exiftool',
format = self::FORMAT_JSON 
)
Parameters:
string $exiftool

Definition at line 67 of file Exiftool.php.

References setExiftool(), and setFormat().

    {
        $this->setExiftool($exiftool);
        $this->setFormat($format);
    }

Here is the call graph for this function:


Member Function Documentation

Robo47_Exiftool::_runExiftool ( file,
format 
) [protected]
Parameters:
string $file
string $format
Exceptions:
Robo47_Exiftool_Exception 

Definition at line 163 of file Exiftool.php.

Referenced by getExifs().

    {
        $command = escapeshellarg($this->_exiftool);
        switch ($format) {
            case self::FORMAT_JSON:
                $command .= ' -j ';
                break;
            case self::FORMAT_XML:
                $command .= ' -X ';
                break;
        }
        $output = array();
        $command .= ' ' . escapeshellarg($file);
        $command .= ' 2>&1 ';
        $returnCode = 0;
        exec($command, $output, $returnCode);
        if ($returnCode != 0) {
            $message = 'executing exiftool failed: ' . implode('', $output);
            $message .= PHP_EOL . 'command: ' . $command;
            throw new Robo47_Exiftool_Exception($message, $returnCode);
        }
        return implode('', $output);
    }

Here is the caller graph for this function:

Robo47_Exiftool::getExifs ( file,
format = null 
)

Returns exifs of an image.

Parameters:
string $file
string $format Valid formats are xml, json, array, dom
Exceptions:
Robo47_Exiftool_Exception 
Returns:
DOMDocument|array|string

Definition at line 133 of file Exiftool.php.

References _runExiftool(), and getFormat().

    {
        if (!file_exists($file) || !is_file($file)) {
            $message = 'File "' . $file . '" does not exist.';
            throw new Robo47_Exiftool_Exception($message);
        }
        if (null === $format) {
            $format = $this->getFormat();
        }
        switch ($format) {
            case self::FORMAT_JSON:
                $exifs = $this->_runExiftool($file, self::FORMAT_JSON);
                break;
            case self::FORMAT_ARRAY:
                $exifs = $this->_runExiftool($file, self::FORMAT_JSON);
                $exifs = json_decode($exifs, true);
                break;
            case self::FORMAT_XML:
                $exifs = $this->_runExiftool($file, self::FORMAT_XML);
                break;
        }
        return $exifs;
    }

Here is the call graph for this function:

Robo47_Exiftool::getExiftool (  ) 
Returns:
string

Definition at line 90 of file Exiftool.php.

    {
        return $this->_exiftool;
    }

Robo47_Exiftool::getFormat (  ) 
Returns:
string

Definition at line 120 of file Exiftool.php.

Referenced by getExifs().

    {
        return $this->_format;
    }

Here is the caller graph for this function:

Robo47_Exiftool::setExiftool ( exiftool  ) 

Set Exiftool.

Parameters:
string $exiftool
Returns:
Robo47_Exiftool *Provides Fluent Interface*

Definition at line 80 of file Exiftool.php.

Referenced by __construct().

    {
        $this->_exiftool = $exiftool;
        return $this;
    }

Here is the caller graph for this function:

Robo47_Exiftool::setFormat ( format  ) 
Parameters:
string $format
Returns:
Robo47_Exiftool *Provides Fluent Interface*

Definition at line 100 of file Exiftool.php.

Referenced by __construct().

    {
        $format = strtolower($format);
        switch ($format) {
            case self::FORMAT_JSON:
            case self::FORMAT_ARRAY:
            case self::FORMAT_XML:
                break;
            default:
                $message = 'Invalid format: ' . $format;
                throw new Robo47_Exiftool_Exception($message);
        }
        $this->_format = $format;
        return $this;
    }

Here is the caller graph for this function:


Member Data Documentation

Robo47_Exiftool::$_exiftool = '/usr/bin/exiftool' [protected]

Definition at line 61 of file Exiftool.php.

Robo47_Exiftool::$_format = null [protected]

Definition at line 55 of file Exiftool.php.

Format ARRAY.

Definition at line 39 of file Exiftool.php.

Format JSON.

Definition at line 49 of file Exiftool.php.

Format XML.

Definition at line 44 of file Exiftool.php.


The documentation for this class was generated from the following file: