public function definition(string $resource, int $version = null) : ResourceDefinition
    {
        $version = $version ?? $this->version;

        if (str_contains($resource, '.')) {
            list($resource, $related) = explode('.', $resource);
            $definition = $this->definition($resource, $version);

            $relatedDefinition = $definition->relations->filter(function (ResourceDefinition $definition) use ($related, $version) {
                return $definition->version === $version && $definition->resource === $related;
            });

	        if($relatedDefinition->isEmpty())
		        throw ResourceNotDefinedException::resource($resource, 'version ' . $version);

            return $relatedDefinition->first();
        }

        $found = $this->definitions->filter(function (ResourceDefinition $definition) use ($resource, $version) {
            return $definition->version === $version && $definition->resource === $resource;
        });

        if ($found->isEmpty()) {
            throw ResourceNotDefinedException::resource($resource, 'version ' . $version);
        }

        return $found->first();
    }
public function definition(string $resource, int $version = null) : ResourceDefinition
    {
        $version = $version ?? $this->version;

        if (str_contains($resource, '.')) {
            list($resource, $related) = explode('.', $resource);
            $definition = $this->definition($resource, $version);

            $relatedDefinition = $definition->relations->filter(function (ResourceDefinition $definition) use ($related, $version) {
                return $definition->version === $version && $definition->resource === $related;
            });

	        if($relatedDefinition->isEmpty())
		        throw ResourceNotDefinedException::resource($resource, 'version ' . $version);

            return $relatedDefinition->first();
        }

        $found = $this->definitions->filter(function (ResourceDefinition $definition) use ($resource, $version) {
            return $definition->version === $version && $definition->resource === $resource;
        });

        if ($found->isEmpty()) {
            throw ResourceNotDefinedException::resource($resource, 'version ' . $version);
        }

        return $found->first();
    }
public function definition ( string $ resource , int $ version = null ) : ResourceDefinition { $ version = $ version ?? $ this -> version ; if ( str_contains ( $ resource , '.' ) ) { list ( $ resource , $ related ) = explode ( '.' , $ resource ) ; $ definition = $ this -> definition ( $ resource , $ version ) ; $ relatedDefinition = $ definition -> relations -> filter ( function ( ResourceDefinition $ definition ) use ( $ related , $ version ) { return $ definition -> version === $ version && $ definition -> resource === $ related ; } ) ; if ( $ relatedDefinition -> isEmpty ( ) ) throw ResourceNotDefinedException :: resource ( $ resource , 'version ' . $ version ) ; return $ relatedDefinition -> first ( ) ; } $ found = $ this -> definitions -> filter ( function ( ResourceDefinition $ definition ) use ( $ resource , $ version ) { return $ definition -> version === $ version && $ definition -> resource === $ resource ; } ) ; if ( $ found -> isEmpty ( ) ) { throw ResourceNotDefinedException :: resource ( $ resource , 'version ' . $ version ) ; } return $ found -> first ( ) ; }
returns definition for resource and version

@param string $resource
@param int $version
@return ResourceDefinition
@throws ResourceNotDefinedException when no definition found
returns definition for resource and version