src/Controller/ModelCollector.php
public function getModel($modelId, $providerName = null)
    {
        if (\is_string($modelId)) {
            try {
                $modelId = ModelId::fromValues($providerName, $modelId);
            } catch (\Exception $swallow) {
                $modelId = ModelId::fromSerialized($modelId);
            }
        }

        if (!($modelId instanceof ModelIdInterface)) {
            throw new \InvalidArgumentException('Invalid model id passed: ' . \var_export($modelId, true));
        }

        $definition       = $this->environment->getDataDefinition();
        $parentDefinition = $this->environment->getParentDataDefinition();
        $dataProvider     = $this->environment->getDataProvider($modelId->getDataProviderName());
        $config           = $dataProvider->getEmptyConfig();

        if ($definition->getName() === $modelId->getDataProviderName()) {
            $propertyDefinition = $definition->getPropertiesDefinition();
        } elseif ($parentDefinition->getName() === $modelId->getDataProviderName()) {
            $propertyDefinition = $parentDefinition->getPropertiesDefinition();
        } else {
            throw new \InvalidArgumentException('Invalid provider name ' . $modelId->getDataProviderName());
        }

        $properties = [];

        // Filter real properties from the property definition.
        foreach ($propertyDefinition->getPropertyNames() as $propertyName) {
            if ($dataProvider->fieldExists($propertyName)) {
                $properties[] = $propertyName;

                continue;
            }

            // @codingStandardsIgnoreStart
            @\trigger_error(
                'Only real property is allowed in the property definition.' .
                'This will no longer be supported in the future.',
                E_DEPRECATED
            );
            // @codingStandardsIgnoreEnd
        }
        $config->setId($modelId->getId())->setFields($properties);

        return $dataProvider->fetch($config);
    }
public function getModel($modelId, $providerName = null)
    {
        if (\is_string($modelId)) {
            try {
                $modelId = ModelId::fromValues($providerName, $modelId);
            } catch (\Exception $swallow) {
                $modelId = ModelId::fromSerialized($modelId);
            }
        }

        if (!($modelId instanceof ModelIdInterface)) {
            throw new \InvalidArgumentException('Invalid model id passed: ' . \var_export($modelId, true));
        }

        $definition       = $this->environment->getDataDefinition();
        $parentDefinition = $this->environment->getParentDataDefinition();
        $dataProvider     = $this->environment->getDataProvider($modelId->getDataProviderName());
        $config           = $dataProvider->getEmptyConfig();

        if ($definition->getName() === $modelId->getDataProviderName()) {
            $propertyDefinition = $definition->getPropertiesDefinition();
        } elseif ($parentDefinition->getName() === $modelId->getDataProviderName()) {
            $propertyDefinition = $parentDefinition->getPropertiesDefinition();
        } else {
            throw new \InvalidArgumentException('Invalid provider name ' . $modelId->getDataProviderName());
        }

        $properties = [];

        // Filter real properties from the property definition.
        foreach ($propertyDefinition->getPropertyNames() as $propertyName) {
            if ($dataProvider->fieldExists($propertyName)) {
                $properties[] = $propertyName;

                continue;
            }

            // @codingStandardsIgnoreStart
            @\trigger_error(
                'Only real property is allowed in the property definition.' .
                'This will no longer be supported in the future.',
                E_DEPRECATED
            );
            // @codingStandardsIgnoreEnd
        }
        $config->setId($modelId->getId())->setFields($properties);

        return $dataProvider->fetch($config);
    }
public function getModel ( $ modelId , $ providerName = null ) { if ( \ is_string ( $ modelId ) ) { try { $ modelId = ModelId :: fromValues ( $ providerName , $ modelId ) ; } catch ( \ Exception $ swallow ) { $ modelId = ModelId :: fromSerialized ( $ modelId ) ; } } if ( ! ( $ modelId instanceof ModelIdInterface ) ) { throw new \ InvalidArgumentException ( 'Invalid model id passed: ' . \ var_export ( $ modelId , true ) ) ; } $ definition = $ this -> environment -> getDataDefinition ( ) ; $ parentDefinition = $ this -> environment -> getParentDataDefinition ( ) ; $ dataProvider = $ this -> environment -> getDataProvider ( $ modelId -> getDataProviderName ( ) ) ; $ config = $ dataProvider -> getEmptyConfig ( ) ; if ( $ definition -> getName ( ) === $ modelId -> getDataProviderName ( ) ) { $ propertyDefinition = $ definition -> getPropertiesDefinition ( ) ; } elseif ( $ parentDefinition -> getName ( ) === $ modelId -> getDataProviderName ( ) ) { $ propertyDefinition = $ parentDefinition -> getPropertiesDefinition ( ) ; } else { throw new \ InvalidArgumentException ( 'Invalid provider name ' . $ modelId -> getDataProviderName ( ) ) ; } $ properties = [ ] ; // Filter real properties from the property definition. foreach ( $ propertyDefinition -> getPropertyNames ( ) as $ propertyName ) { if ( $ dataProvider -> fieldExists ( $ propertyName ) ) { $ properties [ ] = $ propertyName ; continue ; } // @codingStandardsIgnoreStart @ \ trigger_error ( 'Only real property is allowed in the property definition.' . 'This will no longer be supported in the future.' , E_DEPRECATED ) ; // @codingStandardsIgnoreEnd } $ config -> setId ( $ modelId -> getId ( ) ) -> setFields ( $ properties ) ; return $ dataProvider -> fetch ( $ config ) ; }
Fetch a certain model from its provider.

@param string|ModelIdInterface $modelId      This is either the id of the model or a serialized id.
@param string|null             $providerName The name of the provider, if this is empty, the id will be
deserialized and the provider name will get extracted from there.

@return ModelInterface

@throws \InvalidArgumentException When the model id is invalid.
Fetch a certain model from its provider .