MetaModels\Helper\ToolboxFile::convertUuidsOrPathsToMetaModels PHP Method

convertUuidsOrPathsToMetaModels() public static method

The output array will have the following layout: array( 'bin' => array() // the binary id. 'value' => array() // the uuid. 'path' => array() // the path. )
public static convertUuidsOrPathsToMetaModels ( array $values ) : array
$values array The binary uuids or paths to convert.
return array
    public static function convertUuidsOrPathsToMetaModels($values)
    {
        $values = array_filter((array) $values);
        if (empty($values)) {
            return array('bin' => array(), 'value' => array(), 'path' => array());
        }
        foreach ($values as $key => $value) {
            if (!\Validator::isUuid($value)) {
                $file = \FilesModel::findByPath($value) ?: \Dbafs::addResource($value);
                if (!$file) {
                    throw new \InvalidArgumentException('Invalid value.');
                }
                $values[$key] = $file->uuid;
            }
        }
        return self::convertValuesToMetaModels($values);
    }

Usage Example

Esempio n. 1
0
 /**
  * Test all empty values are mapped correctly.
  *
  * See https://github.com/MetaModels/attribute_file/issues/45#issuecomment-85937268
  *
  * @return void
  */
 public function testConvertUuidsOrPathsToMetaModelsEmpty()
 {
     $emptyExpected = array('bin' => array(), 'value' => array(), 'path' => array());
     $this->assertEquals($emptyExpected, ToolboxFile::convertUuidsOrPathsToMetaModels(null));
     $this->assertEquals($emptyExpected, ToolboxFile::convertUuidsOrPathsToMetaModels(array()));
     $this->assertEquals($emptyExpected, ToolboxFile::convertUuidsOrPathsToMetaModels(array(null)));
 }
All Usage Examples Of MetaModels\Helper\ToolboxFile::convertUuidsOrPathsToMetaModels