eZ\Publish\Core\FieldType\Image\Value::fromString PHP Method

fromString() public static method

Creates a value only from a file path.
Deprecation: Starting with 5.3.3, handled by Image\Type::acceptValue()
public static fromString ( string $path ) : Value
$path string
return Value
    public static function fromString($path)
    {
        if (!file_exists($path)) {
            throw new InvalidArgumentType('$path', 'existing file', $path);
        }
        return new static(array('inputUri' => $path, 'fileName' => basename($path), 'fileSize' => filesize($path)));
    }

Usage Example

Example #1
0
 /**
  * Inspects given $inputValue and potentially converts it into a dedicated value object.
  *
  * @param string|array|\eZ\Publish\Core\FieldType\Image\Value $inputValue
  *
  * @return \eZ\Publish\Core\FieldType\Image\Value The potentially converted and structurally plausible value.
  */
 protected function createValueFromInput($inputValue)
 {
     if (is_string($inputValue)) {
         $inputValue = Value::fromString($inputValue);
     }
     if (is_array($inputValue)) {
         if (isset($inputValue['inputUri']) && file_exists($inputValue['inputUri'])) {
             $inputValue['fileSize'] = filesize($inputValue['inputUri']);
             if (!isset($inputValue['fileName'])) {
                 $inputValue['fileName'] = basename($inputValue['inputUri']);
             }
         }
         $inputValue = new Value($inputValue);
     }
     return $inputValue;
 }