src/Charcoal/Model/Service/MetadataLoader.php
public function load($ident, $metadata = [], array $idents = null)
    {
        if (!is_string($ident)) {
            throw new InvalidArgumentException(sprintf(
                'Metadata identifier must be a string, received %s',
                is_object($ident) ? get_class($ident) : gettype($ident)
            ));
        }

        if (strpos($ident, '\\') !== false) {
            $ident = $this->metaKeyFromClassName($ident);
        }

        $valid = $this->validateMetadataContainer($metadata, $metadataType, $targetMetadata);
        if ($valid === false) {
            throw new InvalidArgumentException(sprintf(
                'Metadata object must be a class name or instance of %s, received %s',
                MetadataInterface::class,
                is_object($metadata) ? get_class($metadata) : gettype($metadata)
            ));
        }

        if (isset(static::$metadataCache[$ident])) {
            $cachedMetadata = static::$metadataCache[$ident];

            if (is_object($targetMetadata)) {
                return $targetMetadata->merge($cachedMetadata);
            } elseif (is_array($targetMetadata)) {
                return array_replace_recursive($targetMetadata, $cachedMetadata->data());
            }

            return $cachedMetadata;
        }

        $data = $this->loadMetadataFromCache($ident, $idents);

        if (is_object($targetMetadata)) {
            return $targetMetadata->merge($data);
        } elseif (is_array($targetMetadata)) {
            return array_replace_recursive($targetMetadata, $data);
        }

        $targetMetadata = new $metadataType;
        $targetMetadata->setData($data);

        static::$metadataCache[$ident] = $targetMetadata;

        return $targetMetadata;
    }
public function load($ident, $metadata = [], array $idents = null)
    {
        if (!is_string($ident)) {
            throw new InvalidArgumentException(sprintf(
                'Metadata identifier must be a string, received %s',
                is_object($ident) ? get_class($ident) : gettype($ident)
            ));
        }

        if (strpos($ident, '\\') !== false) {
            $ident = $this->metaKeyFromClassName($ident);
        }

        $valid = $this->validateMetadataContainer($metadata, $metadataType, $targetMetadata);
        if ($valid === false) {
            throw new InvalidArgumentException(sprintf(
                'Metadata object must be a class name or instance of %s, received %s',
                MetadataInterface::class,
                is_object($metadata) ? get_class($metadata) : gettype($metadata)
            ));
        }

        if (isset(static::$metadataCache[$ident])) {
            $cachedMetadata = static::$metadataCache[$ident];

            if (is_object($targetMetadata)) {
                return $targetMetadata->merge($cachedMetadata);
            } elseif (is_array($targetMetadata)) {
                return array_replace_recursive($targetMetadata, $cachedMetadata->data());
            }

            return $cachedMetadata;
        }

        $data = $this->loadMetadataFromCache($ident, $idents);

        if (is_object($targetMetadata)) {
            return $targetMetadata->merge($data);
        } elseif (is_array($targetMetadata)) {
            return array_replace_recursive($targetMetadata, $data);
        }

        $targetMetadata = new $metadataType;
        $targetMetadata->setData($data);

        static::$metadataCache[$ident] = $targetMetadata;

        return $targetMetadata;
    }
public function load ( $ ident , $ metadata = [ ] , array $ idents = null ) { if ( ! is_string ( $ ident ) ) { throw new InvalidArgumentException ( sprintf ( 'Metadata identifier must be a string, received %s' , is_object ( $ ident ) ? get_class ( $ ident ) : gettype ( $ ident ) ) ) ; } if ( strpos ( $ ident , '\\' ) !== false ) { $ ident = $ this -> metaKeyFromClassName ( $ ident ) ; } $ valid = $ this -> validateMetadataContainer ( $ metadata , $ metadataType , $ targetMetadata ) ; if ( $ valid === false ) { throw new InvalidArgumentException ( sprintf ( 'Metadata object must be a class name or instance of %s, received %s' , MetadataInterface :: class , is_object ( $ metadata ) ? get_class ( $ metadata ) : gettype ( $ metadata ) ) ) ; } if ( isset ( static :: $ metadataCache [ $ ident ] ) ) { $ cachedMetadata = static :: $ metadataCache [ $ ident ] ; if ( is_object ( $ targetMetadata ) ) { return $ targetMetadata -> merge ( $ cachedMetadata ) ; } elseif ( is_array ( $ targetMetadata ) ) { return array_replace_recursive ( $ targetMetadata , $ cachedMetadata -> data ( ) ) ; } return $ cachedMetadata ; } $ data = $ this -> loadMetadataFromCache ( $ ident , $ idents ) ; if ( is_object ( $ targetMetadata ) ) { return $ targetMetadata -> merge ( $ data ) ; } elseif ( is_array ( $ targetMetadata ) ) { return array_replace_recursive ( $ targetMetadata , $ data ) ; } $ targetMetadata = new $ metadataType ; $ targetMetadata -> setData ( $ data ) ; static :: $ metadataCache [ $ ident ] = $ targetMetadata ; return $ targetMetadata ; }
Load the metadata for the given identifier or interfaces.

Notes:
- If the requested dataset is found, it will be stored in the cache service.
- If the provided metadata container is an {@see MetadataInterface object},
it will be stored for the lifetime of the script (whether it be a longer
running process or a web request).

@param  string $ident    The metadata identifier to load.
@param  mixed  $metadata The metadata type to load the dataset into.
If $metadata is a {@see MetadataInterface} instance, the requested dataset will be merged into the object.
If $metadata is a class name, the requested dataset will be stored in a new instance of that class.
If $metadata is an array, the requested dataset will be merged into the array.
@param  array  $idents   The metadata identifier(s) to load.
If $idents is provided, $ident will be used as the cache key
and $idents are loaded instead.
@throws InvalidArgumentException If the identifier is not a string.
@return MetadataInterface|array Returns the dataset, for the given $ident,
as an array or an instance of {@see MetadataInterface}.
See $metadata for more details.
Load the metadata for the given identifier or interfaces .