idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
3,500
|
private function getEnabled ( array $ context , string $ resourceClass = null , string $ operationName = null , bool $ partial = false ) : bool { $ enabled = $ this -> options [ $ partial ? 'partial' : 'enabled' ] ; $ clientEnabled = $ this -> options [ $ partial ? 'client_partial' : 'client_enabled' ] ; if ( null !== $ resourceClass ) { $ resourceMetadata = $ this -> resourceMetadataFactory -> create ( $ resourceClass ) ; $ enabled = $ resourceMetadata -> getCollectionOperationAttribute ( $ operationName , $ partial ? 'pagination_partial' : 'pagination_enabled' , $ enabled , true ) ; $ clientEnabled = $ resourceMetadata -> getCollectionOperationAttribute ( $ operationName , $ partial ? 'pagination_client_partial' : 'pagination_client_enabled' , $ clientEnabled , true ) ; } if ( $ clientEnabled ) { return filter_var ( $ this -> getParameterFromContext ( $ context , $ this -> options [ $ partial ? 'partial_parameter_name' : 'enabled_parameter_name' ] , $ enabled ) , FILTER_VALIDATE_BOOLEAN ) ; } return $ enabled ; }
|
Is the classic or partial pagination enabled?
|
3,501
|
private function getParameterFromContext ( array $ context , string $ parameterName , $ default = null ) { $ filters = $ context [ 'filters' ] ?? [ ] ; return \ array_key_exists ( $ parameterName , $ filters ) ? $ filters [ $ parameterName ] : $ default ; }
|
Gets the given pagination parameter name from the given context .
|
3,502
|
public function createFilterCollectionFromLocator ( ContainerInterface $ filterLocator ) : FilterCollection { $ filters = [ ] ; foreach ( $ this -> filtersIds as $ filterId ) { if ( $ filterLocator -> has ( $ filterId ) ) { $ filters [ $ filterId ] = $ filterLocator -> get ( $ filterId ) ; } } return new FilterCollection ( $ filters ) ; }
|
Creates a filter collection from a filter locator .
|
3,503
|
private function setFilterLocator ( $ filterLocator , bool $ allowNull = false ) : void { if ( $ filterLocator instanceof ContainerInterface || $ filterLocator instanceof FilterCollection || ( null === $ filterLocator && $ allowNull ) ) { if ( $ filterLocator instanceof FilterCollection ) { @ trigger_error ( sprintf ( 'The %s class is deprecated since version 2.1 and will be removed in 3.0. Provide an implementation of %s instead.' , FilterCollection :: class , ContainerInterface :: class ) , E_USER_DEPRECATED ) ; } $ this -> filterLocator = $ filterLocator ; } else { throw new InvalidArgumentException ( sprintf ( 'The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.' , ContainerInterface :: class , $ allowNull ? ' or null' : '' ) ) ; } }
|
Sets a filter locator with a backward compatibility .
|
3,504
|
private function getFilter ( string $ filterId ) : ? FilterInterface { if ( $ this -> filterLocator instanceof ContainerInterface && $ this -> filterLocator -> has ( $ filterId ) ) { return $ this -> filterLocator -> get ( $ filterId ) ; } if ( $ this -> filterLocator instanceof FilterCollection && $ this -> filterLocator -> offsetExists ( $ filterId ) ) { return $ this -> filterLocator -> offsetGet ( $ filterId ) ; } return null ; }
|
Gets a filter with a backward compatibility .
|
3,505
|
private function isRequiredByGroups ( ValidatorPropertyMetadataInterface $ validatorPropertyMetadata , array $ options ) : bool { foreach ( $ options [ 'validation_groups' ] as $ validationGroup ) { if ( ! \ is_string ( $ validationGroup ) ) { continue ; } foreach ( $ validatorPropertyMetadata -> findConstraints ( $ validationGroup ) as $ constraint ) { if ( $ this -> isRequired ( $ constraint ) ) { return true ; } } } return false ; }
|
Tests if the property is required because of its validation groups .
|
3,506
|
private function isRequired ( Constraint $ constraint ) : bool { foreach ( self :: REQUIRED_CONSTRAINTS as $ requiredConstraint ) { if ( $ constraint instanceof $ requiredConstraint ) { return true ; } } return false ; }
|
Is this constraint making the related property required?
|
3,507
|
private function getPopulatedRelations ( $ object , ? string $ format , array $ context , array $ relationships ) : array { $ data = [ ] ; if ( ! isset ( $ context [ 'resource_class' ] ) ) { return $ data ; } unset ( $ context [ 'api_included' ] ) ; foreach ( $ relationships as $ relationshipDataArray ) { $ relationshipName = $ relationshipDataArray [ 'name' ] ; $ attributeValue = $ this -> getAttributeValue ( $ object , $ relationshipName , $ format , $ context ) ; if ( $ this -> nameConverter ) { $ relationshipName = $ this -> nameConverter -> normalize ( $ relationshipName , $ context [ 'resource_class' ] , self :: FORMAT , $ context ) ; } if ( ! $ attributeValue ) { continue ; } $ data [ $ relationshipName ] = [ 'data' => [ ] , ] ; if ( 'one' === $ relationshipDataArray [ 'cardinality' ] ) { unset ( $ attributeValue [ 'data' ] [ 'attributes' ] ) ; $ data [ $ relationshipName ] = $ attributeValue ; continue ; } foreach ( $ attributeValue as $ attributeValueElement ) { if ( ! isset ( $ attributeValueElement [ 'data' ] ) ) { throw new UnexpectedValueException ( sprintf ( 'The JSON API attribute \'%s\' must contain a "data" key.' , $ relationshipName ) ) ; } unset ( $ attributeValueElement [ 'data' ] [ 'attributes' ] ) ; $ data [ $ relationshipName ] [ 'data' ] [ ] = $ attributeValueElement [ 'data' ] ; } } return $ data ; }
|
Populates relationships keys .
|
3,508
|
private function getRelatedResources ( $ object , ? string $ format , array $ context , array $ relationships ) : array { if ( ! isset ( $ context [ 'api_included' ] ) ) { return [ ] ; } $ included = [ ] ; foreach ( $ relationships as $ relationshipDataArray ) { if ( ! \ in_array ( $ relationshipDataArray [ 'name' ] , $ context [ 'api_included' ] , true ) ) { continue ; } $ relationshipName = $ relationshipDataArray [ 'name' ] ; $ relationContext = $ context ; $ attributeValue = $ this -> getAttributeValue ( $ object , $ relationshipName , $ format , $ relationContext ) ; if ( ! $ attributeValue ) { continue ; } if ( 'one' === $ relationshipDataArray [ 'cardinality' ] ) { $ included [ ] = $ attributeValue [ 'data' ] ; continue ; } foreach ( $ attributeValue as $ attributeValueElement ) { if ( isset ( $ attributeValueElement [ 'data' ] ) ) { $ included [ ] = $ attributeValueElement [ 'data' ] ; } } } return $ included ; }
|
Populates included keys .
|
3,509
|
private function getJsonApiCacheKey ( ? string $ format , array $ context ) { try { return md5 ( $ format . serialize ( $ context ) ) ; } catch ( \ Exception $ exception ) { return false ; } }
|
Gets the cache key to use .
|
3,510
|
public function onKernelView ( GetResponseForControllerResultEvent $ event ) : void { $ controllerResult = $ event -> getControllerResult ( ) ; $ request = $ event -> getRequest ( ) ; $ attributes = RequestAttributesExtractor :: extractAttributes ( $ request ) ; if ( $ controllerResult instanceof Response && ( $ attributes [ 'respond' ] ?? false ) ) { $ event -> setResponse ( $ controllerResult ) ; return ; } if ( $ controllerResult instanceof Response || ! ( $ attributes [ 'respond' ] ?? $ request -> attributes -> getBoolean ( '_api_respond' , false ) ) ) { return ; } $ headers = [ 'Content-Type' => sprintf ( '%s; charset=utf-8' , $ request -> getMimeType ( $ request -> getRequestFormat ( ) ) ) , 'Vary' => 'Accept' , 'X-Content-Type-Options' => 'nosniff' , 'X-Frame-Options' => 'deny' , ] ; if ( $ request -> attributes -> has ( '_api_write_item_iri' ) ) { $ headers [ 'Content-Location' ] = $ request -> attributes -> get ( '_api_write_item_iri' ) ; if ( $ request -> isMethod ( 'POST' ) ) { $ headers [ 'Location' ] = $ request -> attributes -> get ( '_api_write_item_iri' ) ; } } $ status = null ; if ( $ this -> resourceMetadataFactory && $ attributes ) { $ resourceMetadata = $ this -> resourceMetadataFactory -> create ( $ attributes [ 'resource_class' ] ) ; if ( $ sunset = $ resourceMetadata -> getOperationAttribute ( $ attributes , 'sunset' , null , true ) ) { $ headers [ 'Sunset' ] = ( new \ DateTimeImmutable ( $ sunset ) ) -> format ( \ DateTime :: RFC1123 ) ; } $ status = $ resourceMetadata -> getOperationAttribute ( $ attributes , 'status' ) ; } $ event -> setResponse ( new Response ( $ controllerResult , $ status ?? self :: METHOD_TO_CODE [ $ request -> getMethod ( ) ] ?? Response :: HTTP_OK , $ headers ) ) ; }
|
Creates a Response to send to the client according to the requested format .
|
3,511
|
public function onKernelRequest ( GetResponseEvent $ event ) : void { $ request = $ event -> getRequest ( ) ; if ( 'html' !== $ request -> getRequestFormat ( '' ) || ! ( $ request -> attributes -> has ( '_api_resource_class' ) || $ request -> attributes -> getBoolean ( '_api_respond' , false ) ) ) { return ; } $ request -> attributes -> set ( '_controller' , 'api_platform.swagger.action.ui' ) ; }
|
Sets SwaggerUiAction as controller if the requested format is HTML .
|
3,512
|
private function getOperation ( string $ method , string $ className ) : stdClass { foreach ( $ this -> getOperations ( $ className ) as $ operation ) { if ( $ operation -> { 'hydra:method' } === $ method ) { return $ operation ; } } throw new \ InvalidArgumentException ( sprintf ( 'Operation "%s" of class "%s" doesn\'t exist.' , $ method , $ className ) ) ; }
|
Gets an operation by its method name .
|
3,513
|
private function getFilterAnnotations ( array $ miscAnnotations ) : \ Iterator { foreach ( $ miscAnnotations as $ miscAnnotation ) { if ( ApiFilter :: class === \ get_class ( $ miscAnnotation ) ) { yield $ miscAnnotation ; } } }
|
Filters annotations to get back only ApiFilter annotations .
|
3,514
|
private function getFilterProperties ( ApiFilter $ filterAnnotation , \ ReflectionClass $ reflectionClass , \ ReflectionProperty $ reflectionProperty = null ) : array { $ properties = [ ] ; if ( $ filterAnnotation -> properties ) { foreach ( $ filterAnnotation -> properties as $ property => $ strategy ) { if ( \ is_int ( $ property ) ) { $ properties [ $ strategy ] = null ; } else { $ properties [ $ property ] = $ strategy ; } } return $ properties ; } if ( null !== $ reflectionProperty ) { $ properties [ $ reflectionProperty -> getName ( ) ] = $ filterAnnotation -> strategy ? : null ; return $ properties ; } if ( $ filterAnnotation -> strategy ) { foreach ( $ reflectionClass -> getProperties ( ) as $ reflectionProperty ) { $ properties [ $ reflectionProperty -> getName ( ) ] = $ filterAnnotation -> strategy ; } } return $ properties ; }
|
Given a filter annotation and reflection elements find out the properties where the filter is applied .
|
3,515
|
private function readFilterAnnotations ( \ ReflectionClass $ reflectionClass , Reader $ reader ) : array { $ filters = [ ] ; foreach ( $ this -> getFilterAnnotations ( $ reader -> getClassAnnotations ( $ reflectionClass ) ) as $ filterAnnotation ) { $ filterClass = $ filterAnnotation -> filterClass ; $ id = $ this -> generateFilterId ( $ reflectionClass , $ filterClass , $ filterAnnotation -> id ) ; if ( ! isset ( $ filters [ $ id ] ) ) { $ filters [ $ id ] = [ $ filterAnnotation -> arguments , $ filterClass ] ; } if ( $ properties = $ this -> getFilterProperties ( $ filterAnnotation , $ reflectionClass ) ) { $ filters [ $ id ] [ 0 ] [ 'properties' ] = $ properties ; } } foreach ( $ reflectionClass -> getProperties ( ) as $ reflectionProperty ) { foreach ( $ this -> getFilterAnnotations ( $ reader -> getPropertyAnnotations ( $ reflectionProperty ) ) as $ filterAnnotation ) { $ filterClass = $ filterAnnotation -> filterClass ; $ id = $ this -> generateFilterId ( $ reflectionClass , $ filterClass , $ filterAnnotation -> id ) ; if ( ! isset ( $ filters [ $ id ] ) ) { $ filters [ $ id ] = [ $ filterAnnotation -> arguments , $ filterClass ] ; } if ( $ properties = $ this -> getFilterProperties ( $ filterAnnotation , $ reflectionClass , $ reflectionProperty ) ) { if ( isset ( $ filters [ $ id ] [ 0 ] [ 'properties' ] ) ) { $ filters [ $ id ] [ 0 ] [ 'properties' ] = array_merge ( $ filters [ $ id ] [ 0 ] [ 'properties' ] , $ properties ) ; } else { $ filters [ $ id ] [ 0 ] [ 'properties' ] = $ properties ; } } } } $ parent = $ reflectionClass -> getParentClass ( ) ; if ( false !== $ parent ) { return array_merge ( $ filters , $ this -> readFilterAnnotations ( $ parent , $ reader ) ) ; } return $ filters ; }
|
Reads filter annotations from a ReflectionClass .
|
3,516
|
private function generateFilterId ( \ ReflectionClass $ reflectionClass , string $ filterClass , string $ filterId = null ) : string { $ suffix = null !== $ filterId ? '_' . $ filterId : $ filterId ; return 'annotated_' . Inflector :: tableize ( str_replace ( '\\' , '' , $ reflectionClass -> getName ( ) . ( new \ ReflectionClass ( $ filterClass ) ) -> getName ( ) . $ suffix ) ) ; }
|
Generates a unique per - class and per - filter identifier prefixed by annotated_ .
|
3,517
|
public static function getClassMetadataFromJoinAlias ( string $ alias , QueryBuilder $ queryBuilder , ManagerRegistry $ managerRegistry ) : ClassMetadata { @ trigger_error ( sprintf ( 'The use of "%s::getClassMetadataFromJoinAlias()" is deprecated since 2.4 and will be removed in 3.0. Use "%s::getEntityClassByAlias()" instead.' , __CLASS__ , QueryBuilderHelper :: class ) , E_USER_DEPRECATED ) ; $ entityClass = QueryBuilderHelper :: getEntityClassByAlias ( $ alias , $ queryBuilder , $ managerRegistry ) ; return $ managerRegistry -> getManagerForClass ( $ entityClass ) -> getClassMetadata ( $ entityClass ) ; }
|
Gets the class metadata from a given join alias .
|
3,518
|
public static function getJoinRelationship ( Join $ join ) : string { @ trigger_error ( sprintf ( 'The use of "%s::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getJoin()" directly instead.' , __CLASS__ , Join :: class ) , E_USER_DEPRECATED ) ; return $ join -> getJoin ( ) ; }
|
Gets the relationship from a Join expression .
|
3,519
|
public static function getJoinAlias ( Join $ join ) : string { @ trigger_error ( sprintf ( 'The use of "%s::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getAlias()" directly instead.' , __CLASS__ , Join :: class ) , E_USER_DEPRECATED ) ; return $ join -> getAlias ( ) ; }
|
Gets the alias from a Join expression .
|
3,520
|
public static function getOrderByParts ( OrderBy $ orderBy ) : array { @ trigger_error ( sprintf ( 'The use of "%s::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getParts()" directly instead.' , __CLASS__ , OrderBy :: class ) , E_USER_DEPRECATED ) ; return $ orderBy -> getParts ( ) ; }
|
Gets the parts from an OrderBy expression .
|
3,521
|
public function onKernelResponse ( FilterResponseEvent $ event ) : void { $ apiDocUrl = $ this -> urlGenerator -> generate ( 'api_doc' , [ '_format' => 'jsonld' ] , UrlGeneratorInterface :: ABS_URL ) ; $ link = new Link ( ContextBuilder :: HYDRA_NS . 'apiDocumentation' , $ apiDocUrl ) ; $ attributes = $ event -> getRequest ( ) -> attributes ; if ( null === $ linkProvider = $ attributes -> get ( '_links' ) ) { $ attributes -> set ( '_links' , new GenericLinkProvider ( [ $ link ] ) ) ; return ; } $ attributes -> set ( '_links' , $ linkProvider -> withLink ( $ link ) ) ; }
|
Sends the Hydra header on each response .
|
3,522
|
public static function parseAndDuplicateRequest ( Request $ request ) : Request { $ query = self :: parseRequestParams ( self :: getQueryString ( $ request ) ?? '' ) ; $ body = self :: parseRequestParams ( $ request -> getContent ( ) ) ; return $ request -> duplicate ( $ query , $ body ) ; }
|
Gets a fixed request .
|
3,523
|
public static function parseRequestParams ( string $ source ) : array { $ source = str_replace ( '%5B' , '[' , $ source ) ; $ source = preg_replace_callback ( '/(^|(?<=&))[^=[&]+/' , function ( $ key ) { return bin2hex ( urldecode ( $ key [ 0 ] ) ) ; } , $ source ) ; parse_str ( $ source , $ params ) ; return array_combine ( array_map ( 'hex2bin' , array_keys ( $ params ) ) , $ params ) ; }
|
Parses request parameters from the specified source .
|
3,524
|
public static function generate ( string $ operationName , string $ resourceShortName , $ operationType ) : string { if ( OperationType :: SUBRESOURCE === $ operationType = OperationTypeDeprecationHelper :: getOperationType ( $ operationType ) ) { throw new InvalidArgumentException ( 'Subresource operations are not supported by the RouteNameGenerator.' ) ; } return sprintf ( '%s%s_%s_%s' , static :: ROUTE_NAME_PREFIX , self :: inflector ( $ resourceShortName ) , $ operationName , $ operationType ) ; }
|
Generates a Symfony route name .
|
3,525
|
public static function inflector ( string $ name , bool $ pluralize = true ) : string { $ name = Inflector :: tableize ( $ name ) ; return $ pluralize ? Inflector :: pluralize ( $ name ) : $ name ; }
|
Transforms a given string to a tableized pluralized string .
|
3,526
|
protected function normalizeValues ( array $ values , string $ property ) : ? array { foreach ( $ values as $ key => $ value ) { if ( ! \ is_int ( $ key ) || ! \ is_string ( $ value ) ) { unset ( $ values [ $ key ] ) ; } } if ( empty ( $ values ) ) { $ this -> getLogger ( ) -> notice ( 'Invalid filter ignored' , [ 'exception' => new InvalidArgumentException ( sprintf ( 'At least one value is required, multiple values should be in "%1$s[]=firstvalue&%1$s[]=secondvalue" format' , $ property ) ) , ] ) ; return null ; } return array_values ( $ values ) ; }
|
Normalize the values array .
|
3,527
|
protected function hasValidValues ( array $ values , $ type = null ) : bool { foreach ( $ values as $ key => $ value ) { if ( self :: DOCTRINE_INTEGER_TYPE === $ type && null !== $ value && false === filter_var ( $ value , FILTER_VALIDATE_INT ) ) { return false ; } } return true ; }
|
When the field should be an integer check that the given value is a valid one .
|
3,528
|
private function shouldDoctrinePaginatorUseOutputWalkers ( QueryBuilder $ queryBuilder , string $ resourceClass = null , string $ operationName = null ) : bool { if ( null !== $ resourceClass ) { $ resourceMetadata = $ this -> resourceMetadataFactory -> create ( $ resourceClass ) ; if ( null !== $ useOutputWalkers = $ resourceMetadata -> getCollectionOperationAttribute ( $ operationName , 'pagination_use_output_walkers' , null , true ) ) { return $ useOutputWalkers ; } } if ( QueryChecker :: hasHavingClause ( $ queryBuilder ) ) { return true ; } if ( QueryChecker :: hasRootEntityWithCompositeIdentifier ( $ queryBuilder , $ this -> managerRegistry ) ) { return true ; } if ( QueryChecker :: hasRootEntityWithForeignKeyIdentifier ( $ queryBuilder , $ this -> managerRegistry ) ) { return true ; } if ( QueryChecker :: hasMaxResults ( $ queryBuilder ) && QueryChecker :: hasOrderByOnFetchJoinedToManyAssociation ( $ queryBuilder , $ this -> managerRegistry ) ) { return true ; } return false ; }
|
Determines whether the Doctrine ORM Paginator should use output walkers .
|
3,529
|
private function addEqualityMatchStrategy ( string $ strategy , string $ field , $ value , bool $ caseSensitive , ClassMetadata $ metadata ) { $ type = $ metadata -> getTypeOfField ( $ field ) ; switch ( $ strategy ) { case MongoDbType :: STRING !== $ type : return MongoDbType :: getType ( $ type ) -> convertToDatabaseValue ( $ value ) ; case null : case self :: STRATEGY_EXACT : return $ caseSensitive ? $ value : new Regex ( "^$value$" , 'i' ) ; case self :: STRATEGY_PARTIAL : return new Regex ( $ value , $ caseSensitive ? '' : 'i' ) ; case self :: STRATEGY_START : return new Regex ( "^$value" , $ caseSensitive ? '' : 'i' ) ; case self :: STRATEGY_END : return new Regex ( "$value$" , $ caseSensitive ? '' : 'i' ) ; case self :: STRATEGY_WORD_START : return new Regex ( "(^$value.*|.*\s$value.*)" , $ caseSensitive ? '' : 'i' ) ; default : throw new InvalidArgumentException ( sprintf ( 'strategy %s does not exist.' , $ strategy ) ) ; } }
|
Add equality match stage according to the strategy .
|
3,530
|
public function onKernelResponse ( FilterResponseEvent $ event ) : void { $ link = new Link ( 'mercure' , $ this -> hub ) ; $ attributes = $ event -> getRequest ( ) -> attributes ; if ( null === ( $ resourceClass = $ attributes -> get ( '_api_resource_class' ) ) || false === $ this -> resourceMetadataFactory -> create ( $ resourceClass ) -> getAttribute ( 'mercure' , false ) ) { return ; } if ( null === $ linkProvider = $ attributes -> get ( '_links' ) ) { $ attributes -> set ( '_links' , new GenericLinkProvider ( [ $ link ] ) ) ; return ; } $ attributes -> set ( '_links' , $ linkProvider -> withLink ( $ link ) ) ; }
|
Sends the Mercure header on each response .
|
3,531
|
private function generateIdentifiersUrl ( array $ identifiers , string $ resourceClass ) : array { if ( 0 === \ count ( $ identifiers ) ) { throw new InvalidArgumentException ( sprintf ( 'No identifiers defined for resource of type "%s"' , $ resourceClass ) ) ; } if ( 1 === \ count ( $ identifiers ) ) { return [ rawurlencode ( ( string ) reset ( $ identifiers ) ) ] ; } foreach ( $ identifiers as $ name => $ value ) { $ identifiers [ $ name ] = sprintf ( '%s=%s' , $ name , $ value ) ; } return array_values ( $ identifiers ) ; }
|
Generate the identifier url .
|
3,532
|
private function phpize ( array $ array , string $ key , string $ type ) { if ( ! isset ( $ array [ $ key ] ) ) { return null ; } switch ( $ type ) { case 'bool' : if ( \ is_bool ( $ array [ $ key ] ) ) { return $ array [ $ key ] ; } break ; case 'string' : if ( \ is_string ( $ array [ $ key ] ) ) { return $ array [ $ key ] ; } break ; } throw new InvalidArgumentException ( sprintf ( 'The property "%s" must be a "%s", "%s" given.' , $ key , $ type , \ gettype ( $ array [ $ key ] ) ) ) ; }
|
Transforms a YAML attribute s value in PHP value .
|
3,533
|
protected function getProperties ( string $ resourceClass ) : \ Traversable { if ( null !== $ this -> properties ) { return yield from array_keys ( $ this -> properties ) ; } try { yield from $ this -> propertyNameCollectionFactory -> create ( $ resourceClass ) ; } catch ( ResourceClassNotFoundException $ e ) { } }
|
Gets all enabled properties for the given resource class .
|
3,534
|
protected function hasProperty ( string $ resourceClass , string $ property ) : bool { return \ in_array ( $ property , iterator_to_array ( $ this -> getProperties ( $ resourceClass ) ) , true ) ; }
|
Is the given property enabled?
|
3,535
|
protected function getMetadata ( string $ resourceClass , string $ property ) : array { $ noop = [ null , null , null , null ] ; if ( ! $ this -> hasProperty ( $ resourceClass , $ property ) ) { return $ noop ; } $ properties = explode ( '.' , $ property ) ; $ totalProperties = \ count ( $ properties ) ; $ currentResourceClass = $ resourceClass ; $ hasAssociation = false ; $ currentProperty = null ; $ type = null ; foreach ( $ properties as $ index => $ currentProperty ) { try { $ propertyMetadata = $ this -> propertyMetadataFactory -> create ( $ currentResourceClass , $ currentProperty ) ; } catch ( PropertyNotFoundException $ e ) { return $ noop ; } if ( null === $ type = $ propertyMetadata -> getType ( ) ) { return $ noop ; } ++ $ index ; $ builtinType = $ type -> getBuiltinType ( ) ; if ( Type :: BUILTIN_TYPE_OBJECT !== $ builtinType && Type :: BUILTIN_TYPE_ARRAY !== $ builtinType ) { if ( $ totalProperties === $ index ) { break ; } return $ noop ; } if ( $ type -> isCollection ( ) && null === $ type = $ type -> getCollectionValueType ( ) ) { return $ noop ; } if ( Type :: BUILTIN_TYPE_ARRAY === $ builtinType && Type :: BUILTIN_TYPE_OBJECT !== $ type -> getBuiltinType ( ) ) { if ( $ totalProperties === $ index ) { break ; } return $ noop ; } if ( null === $ className = $ type -> getClassName ( ) ) { return $ noop ; } if ( $ isResourceClass = $ this -> resourceClassResolver -> isResourceClass ( $ className ) ) { $ currentResourceClass = $ className ; } elseif ( $ totalProperties !== $ index ) { return $ noop ; } $ hasAssociation = $ totalProperties === $ index && $ isResourceClass ; } return [ $ type , $ hasAssociation , $ currentResourceClass , $ currentProperty ] ; }
|
Gets info about the decomposed given property for the given resource class .
|
3,536
|
public static function parseIri ( string $ iri , string $ pageParameterName ) : array { $ parts = parse_url ( $ iri ) ; if ( false === $ parts ) { throw new InvalidArgumentException ( sprintf ( 'The request URI "%s" is malformed.' , $ iri ) ) ; } $ parameters = [ ] ; if ( isset ( $ parts [ 'query' ] ) ) { $ parameters = RequestParser :: parseRequestParams ( $ parts [ 'query' ] ) ; unset ( $ parameters [ $ pageParameterName ] ) ; } return [ 'parts' => $ parts , 'parameters' => $ parameters ] ; }
|
Parses and standardizes the request IRI .
|
3,537
|
public static function createIri ( array $ parts , array $ parameters , string $ pageParameterName = null , float $ page = null , bool $ absoluteUrl = false ) : string { if ( null !== $ page && null !== $ pageParameterName ) { $ parameters [ $ pageParameterName ] = $ page ; } $ query = http_build_query ( $ parameters , '' , '&' , PHP_QUERY_RFC3986 ) ; $ parts [ 'query' ] = preg_replace ( '/%5B\d+%5D/' , '%5B%5D' , $ query ) ; $ url = '' ; if ( $ absoluteUrl && isset ( $ parts [ 'host' ] ) ) { if ( isset ( $ parts [ 'scheme' ] ) ) { $ url .= $ parts [ 'scheme' ] ; } elseif ( isset ( $ parts [ 'port' ] ) && 443 === $ parts [ 'port' ] ) { $ url .= 'https' ; } else { $ url .= 'http' ; } $ url .= '://' ; if ( isset ( $ parts [ 'user' ] ) ) { $ url .= $ parts [ 'user' ] ; if ( isset ( $ parts [ 'pass' ] ) ) { $ url .= ':' . $ parts [ 'pass' ] ; } $ url .= '@' ; } $ url .= $ parts [ 'host' ] ; if ( isset ( $ parts [ 'port' ] ) ) { $ url .= ':' . $ parts [ 'port' ] ; } } $ url .= $ parts [ 'path' ] ; if ( '' !== $ parts [ 'query' ] ) { $ url .= '?' . $ parts [ 'query' ] ; } if ( isset ( $ parts [ 'fragment' ] ) ) { $ url .= '#' . $ parts [ 'fragment' ] ; } return $ url ; }
|
Gets a collection IRI for the given parameters .
|
3,538
|
private function getSearch ( string $ resourceClass , array $ parts , array $ filters ) : array { $ variables = [ ] ; $ mapping = [ ] ; foreach ( $ filters as $ filter ) { foreach ( $ filter -> getDescription ( $ resourceClass ) as $ variable => $ data ) { $ variables [ ] = $ variable ; $ mapping [ ] = [ '@type' => 'IriTemplateMapping' , 'variable' => $ variable , 'property' => $ data [ 'property' ] , 'required' => $ data [ 'required' ] , ] ; } } return [ '@type' => 'hydra:IriTemplate' , 'hydra:template' => sprintf ( '%s{?%s}' , $ parts [ 'path' ] , implode ( ',' , $ variables ) ) , 'hydra:variableRepresentation' => 'BasicRepresentation' , 'hydra:mapping' => $ mapping , ] ; }
|
Returns the content of the Hydra search property .
|
3,539
|
protected function validateType ( string $ attribute , Type $ type , $ value , string $ format = null ) { $ builtinType = $ type -> getBuiltinType ( ) ; if ( Type :: BUILTIN_TYPE_FLOAT === $ builtinType && null !== $ format && false !== strpos ( $ format , 'json' ) ) { $ isValid = \ is_float ( $ value ) || \ is_int ( $ value ) ; } else { $ isValid = \ call_user_func ( 'is_' . $ builtinType , $ value ) ; } if ( ! $ isValid ) { throw new InvalidArgumentException ( sprintf ( 'The type of the "%s" attribute must be "%s", "%s" given.' , $ attribute , $ builtinType , \ gettype ( $ value ) ) ) ; } }
|
Validates the type of the value . Allows using integers as floats for JSON formats .
|
3,540
|
protected function denormalizeCollection ( string $ attribute , PropertyMetadata $ propertyMetadata , Type $ type , string $ className , $ value , ? string $ format , array $ context ) : array { if ( ! \ is_array ( $ value ) ) { throw new InvalidArgumentException ( sprintf ( 'The type of the "%s" attribute must be "array", "%s" given.' , $ attribute , \ gettype ( $ value ) ) ) ; } $ collectionKeyType = $ type -> getCollectionKeyType ( ) ; $ collectionKeyBuiltinType = null === $ collectionKeyType ? null : $ collectionKeyType -> getBuiltinType ( ) ; $ values = [ ] ; foreach ( $ value as $ index => $ obj ) { if ( null !== $ collectionKeyBuiltinType && ! \ call_user_func ( 'is_' . $ collectionKeyBuiltinType , $ index ) ) { throw new InvalidArgumentException ( sprintf ( 'The type of the key "%s" must be "%s", "%s" given.' , $ index , $ collectionKeyBuiltinType , \ gettype ( $ index ) ) ) ; } $ values [ $ index ] = $ this -> denormalizeRelation ( $ attribute , $ propertyMetadata , $ className , $ obj , $ format , $ this -> createChildContext ( $ context , $ attribute ) ) ; } return $ values ; }
|
Denormalizes a collection of objects .
|
3,541
|
protected function denormalizeRelation ( string $ attributeName , PropertyMetadata $ propertyMetadata , string $ className , $ value , ? string $ format , array $ context ) { if ( \ is_string ( $ value ) ) { try { return $ this -> iriConverter -> getItemFromIri ( $ value , $ context + [ 'fetch_data' => true ] ) ; } catch ( ItemNotFoundException $ e ) { throw new InvalidArgumentException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } catch ( InvalidArgumentException $ e ) { } } if ( ! $ this -> resourceClassResolver -> isResourceClass ( $ className ) || $ propertyMetadata -> isWritableLink ( ) ) { $ context [ 'resource_class' ] = $ className ; $ context [ 'api_allow_update' ] = true ; try { if ( ! $ this -> serializer instanceof DenormalizerInterface ) { throw new LogicException ( sprintf ( 'The injected serializer must be an instance of "%s".' , DenormalizerInterface :: class ) ) ; } return $ this -> serializer -> denormalize ( $ value , $ className , $ format , $ context ) ; } catch ( InvalidValueException $ e ) { if ( ! $ this -> allowPlainIdentifiers || null === $ this -> itemDataProvider ) { throw $ e ; } } } if ( ! \ is_array ( $ value ) ) { if ( true === $ this -> allowPlainIdentifiers && $ this -> itemDataProvider ) { $ item = $ this -> itemDataProvider -> getItem ( $ className , $ value , null , $ context + [ 'fetch_data' => true ] ) ; if ( null === $ item ) { throw new ItemNotFoundException ( sprintf ( 'Item not found for "%s".' , $ value ) ) ; } return $ item ; } throw new UnexpectedValueException ( sprintf ( 'Expected IRI or nested document for attribute "%s", "%s" given.' , $ attributeName , \ gettype ( $ value ) ) ) ; } throw new UnexpectedValueException ( sprintf ( 'Nested documents for attribute "%s" are not allowed. Use IRIs instead.' , $ attributeName ) ) ; }
|
Denormalizes a relation .
|
3,542
|
private function setValue ( $ object , string $ attributeName , $ value ) { try { $ this -> propertyAccessor -> setValue ( $ object , $ attributeName , $ value ) ; } catch ( NoSuchPropertyException $ exception ) { } }
|
Sets a value of the object using the PropertyAccess component .
|
3,543
|
protected function getFactoryOptions ( array $ context ) : array { $ options = [ ] ; if ( isset ( $ context [ self :: GROUPS ] ) ) { $ options [ 'serializer_groups' ] = $ context [ self :: GROUPS ] ; } if ( isset ( $ context [ 'collection_operation_name' ] ) ) { $ options [ 'collection_operation_name' ] = $ context [ 'collection_operation_name' ] ; } if ( isset ( $ context [ 'item_operation_name' ] ) ) { $ options [ 'item_operation_name' ] = $ context [ 'item_operation_name' ] ; } return $ options ; }
|
Gets a valid context for property metadata factories .
|
3,544
|
protected function normalizeRelation ( PropertyMetadata $ propertyMetadata , $ relatedObject , string $ resourceClass , ? string $ format , array $ context ) { if ( null === $ relatedObject || ! empty ( $ context [ 'attributes' ] ) || $ propertyMetadata -> isReadableLink ( ) ) { if ( null === $ relatedObject ) { unset ( $ context [ 'resource_class' ] ) ; } else { $ context [ 'resource_class' ] = $ resourceClass ; } if ( ! $ this -> serializer instanceof NormalizerInterface ) { throw new LogicException ( sprintf ( 'The injected serializer must be an instance of "%s".' , NormalizerInterface :: class ) ) ; } return $ this -> serializer -> normalize ( $ relatedObject , $ format , $ context ) ; } $ iri = $ this -> iriConverter -> getIriFromItem ( $ relatedObject ) ; if ( isset ( $ context [ 'resources' ] ) ) { $ context [ 'resources' ] [ $ iri ] = $ iri ; } if ( isset ( $ context [ 'resources_to_push' ] ) && $ propertyMetadata -> getAttribute ( 'push' , false ) ) { $ context [ 'resources_to_push' ] [ $ iri ] = $ iri ; } return $ iri ; }
|
Normalizes a relation as an object if is a Link or as an URI .
|
3,545
|
protected function getDataTransformer ( $ object , string $ to , array $ context = [ ] ) : ? DataTransformerInterface { foreach ( $ this -> dataTransformers as $ dataTransformer ) { if ( $ dataTransformer -> supportsTransformation ( $ object , $ to , $ context ) ) { return $ dataTransformer ; } } return null ; }
|
Finds the first supported data transformer if any .
|
3,546
|
protected function transformOutput ( $ object , array $ context = [ ] ) { $ outputClass = $ this -> getOutputClass ( $ this -> getObjectClass ( $ object ) , $ context ) ; if ( null !== $ outputClass && null !== $ dataTransformer = $ this -> getDataTransformer ( $ object , $ outputClass , $ context ) ) { return $ dataTransformer -> transform ( $ object , $ outputClass , $ context ) ; } return $ object ; }
|
For a given resource it returns an output representation if any If not the resource is returned .
|
3,547
|
public static function extractAttributes ( array $ attributes ) : array { $ result = [ 'resource_class' => $ attributes [ '_api_resource_class' ] ?? null ] ; if ( $ subresourceContext = $ attributes [ '_api_subresource_context' ] ?? null ) { $ result [ 'subresource_context' ] = $ subresourceContext ; } if ( null === $ result [ 'resource_class' ] ) { return [ ] ; } $ hasRequestAttributeKey = false ; foreach ( OperationType :: TYPES as $ operationType ) { $ attribute = "_api_{$operationType}_operation_name" ; if ( isset ( $ attributes [ $ attribute ] ) ) { $ result [ "{$operationType}_operation_name" ] = $ attributes [ $ attribute ] ; $ hasRequestAttributeKey = true ; break ; } } if ( false === $ hasRequestAttributeKey ) { return [ ] ; } $ result += [ 'receive' => ( bool ) ( $ attributes [ '_api_receive' ] ?? true ) , 'respond' => ( bool ) ( $ attributes [ '_api_respond' ] ?? true ) , 'persist' => ( bool ) ( $ attributes [ '_api_persist' ] ?? true ) , ] ; return $ result ; }
|
Extracts resource class operation name and format request attributes . Returns an empty array if the request does not contain required attributes .
|
3,548
|
public function onKernelException ( GetResponseForExceptionEvent $ event ) : void { $ exception = $ event -> getException ( ) ; if ( ! $ exception instanceof ValidationException ) { return ; } $ format = ErrorFormatGuesser :: guessErrorFormat ( $ event -> getRequest ( ) , $ this -> errorFormats ) ; $ event -> setResponse ( new Response ( $ this -> serializer -> serialize ( $ exception -> getConstraintViolationList ( ) , $ format [ 'key' ] ) , Response :: HTTP_BAD_REQUEST , [ 'Content-Type' => sprintf ( '%s; charset=utf-8' , $ format [ 'value' ] [ 0 ] ) , 'X-Content-Type-Options' => 'nosniff' , 'X-Frame-Options' => 'deny' , ] ) ) ; }
|
Returns a list of violations normalized in the Hydra format .
|
3,549
|
protected function addJoinsForNestedProperty ( string $ property , string $ rootAlias , QueryBuilder $ queryBuilder , QueryNameGeneratorInterface $ queryNameGenerator ) : array { if ( \ func_num_args ( ) > 4 ) { $ resourceClass = func_get_arg ( 4 ) ; } else { if ( __CLASS__ !== \ get_class ( $ this ) ) { $ r = new \ ReflectionMethod ( $ this , __FUNCTION__ ) ; if ( __CLASS__ !== $ r -> getDeclaringClass ( ) -> getName ( ) ) { @ trigger_error ( sprintf ( 'Method %s() will have a fifth `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.' , __FUNCTION__ ) , E_USER_DEPRECATED ) ; } } $ resourceClass = null ; } if ( \ func_num_args ( ) > 5 ) { $ joinType = func_get_arg ( 5 ) ; } else { if ( __CLASS__ !== \ get_class ( $ this ) ) { $ r = new \ ReflectionMethod ( $ this , __FUNCTION__ ) ; if ( __CLASS__ !== $ r -> getDeclaringClass ( ) -> getName ( ) ) { @ trigger_error ( sprintf ( 'Method %s() will have a sixth `$joinType` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.3.' , __FUNCTION__ ) , E_USER_DEPRECATED ) ; } } $ joinType = null ; } $ propertyParts = $ this -> splitPropertyParts ( $ property , $ resourceClass ) ; $ parentAlias = $ rootAlias ; $ alias = null ; foreach ( $ propertyParts [ 'associations' ] as $ association ) { $ alias = QueryBuilderHelper :: addJoinOnce ( $ queryBuilder , $ queryNameGenerator , $ parentAlias , $ association , $ joinType ) ; $ parentAlias = $ alias ; } if ( null === $ alias ) { throw new InvalidArgumentException ( sprintf ( 'Cannot add joins for property "%s" - property is not nested.' , $ property ) ) ; } return [ $ alias , $ propertyParts [ 'field' ] , $ propertyParts [ 'associations' ] ] ; }
|
Adds the necessary joins for a nested property .
|
3,550
|
private function addMatch ( Builder $ aggregationBuilder , string $ field , string $ operator , string $ value , string $ nullManagement = null ) : void { try { $ value = new \ DateTime ( $ value ) ; } catch ( \ Exception $ e ) { $ this -> logger -> notice ( 'Invalid filter ignored' , [ 'exception' => new InvalidArgumentException ( sprintf ( 'The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor' , $ field ) ) , ] ) ; return ; } $ operatorValue = [ self :: PARAMETER_BEFORE => '$lte' , self :: PARAMETER_STRICTLY_BEFORE => '$lt' , self :: PARAMETER_AFTER => '$gte' , self :: PARAMETER_STRICTLY_AFTER => '$gt' , ] ; if ( ( self :: INCLUDE_NULL_BEFORE === $ nullManagement && \ in_array ( $ operator , [ self :: PARAMETER_BEFORE , self :: PARAMETER_STRICTLY_BEFORE ] , true ) ) || ( self :: INCLUDE_NULL_AFTER === $ nullManagement && \ in_array ( $ operator , [ self :: PARAMETER_AFTER , self :: PARAMETER_STRICTLY_AFTER ] , true ) ) || ( self :: INCLUDE_NULL_BEFORE_AND_AFTER === $ nullManagement && \ in_array ( $ operator , [ self :: PARAMETER_AFTER , self :: PARAMETER_STRICTLY_AFTER , self :: PARAMETER_BEFORE , self :: PARAMETER_STRICTLY_BEFORE ] , true ) ) ) { $ aggregationBuilder -> match ( ) -> addOr ( $ aggregationBuilder -> matchExpr ( ) -> field ( $ field ) -> operator ( $ operatorValue [ $ operator ] , $ value ) , $ aggregationBuilder -> matchExpr ( ) -> field ( $ field ) -> equals ( null ) ) ; return ; } $ aggregationBuilder -> match ( ) -> addAnd ( $ aggregationBuilder -> matchExpr ( ) -> field ( $ field ) -> operator ( $ operatorValue [ $ operator ] , $ value ) ) ; }
|
Adds the match stage according to the chosen null management .
|
3,551
|
protected function addWhereByStrategy ( string $ strategy , QueryBuilder $ queryBuilder , QueryNameGeneratorInterface $ queryNameGenerator , string $ alias , string $ field , $ value , bool $ caseSensitive ) { $ wrapCase = $ this -> createWrapCase ( $ caseSensitive ) ; $ valueParameter = $ queryNameGenerator -> generateParameterName ( $ field ) ; switch ( $ strategy ) { case null : case self :: STRATEGY_EXACT : $ queryBuilder -> andWhere ( sprintf ( $ wrapCase ( '%s.%s' ) . ' = ' . $ wrapCase ( ':%s' ) , $ alias , $ field , $ valueParameter ) ) -> setParameter ( $ valueParameter , $ value ) ; break ; case self :: STRATEGY_PARTIAL : $ queryBuilder -> andWhere ( sprintf ( $ wrapCase ( '%s.%s' ) . ' LIKE ' . $ wrapCase ( 'CONCAT(\'%%\', :%s, \'%%\')' ) , $ alias , $ field , $ valueParameter ) ) -> setParameter ( $ valueParameter , $ value ) ; break ; case self :: STRATEGY_START : $ queryBuilder -> andWhere ( sprintf ( $ wrapCase ( '%s.%s' ) . ' LIKE ' . $ wrapCase ( 'CONCAT(:%s, \'%%\')' ) , $ alias , $ field , $ valueParameter ) ) -> setParameter ( $ valueParameter , $ value ) ; break ; case self :: STRATEGY_END : $ queryBuilder -> andWhere ( sprintf ( $ wrapCase ( '%s.%s' ) . ' LIKE ' . $ wrapCase ( 'CONCAT(\'%%\', :%s)' ) , $ alias , $ field , $ valueParameter ) ) -> setParameter ( $ valueParameter , $ value ) ; break ; case self :: STRATEGY_WORD_START : $ queryBuilder -> andWhere ( sprintf ( $ wrapCase ( '%1$s.%2$s' ) . ' LIKE ' . $ wrapCase ( 'CONCAT(:%3$s, \'%%\')' ) . ' OR ' . $ wrapCase ( '%1$s.%2$s' ) . ' LIKE ' . $ wrapCase ( 'CONCAT(\'%% \', :%3$s, \'%%\')' ) , $ alias , $ field , $ valueParameter ) ) -> setParameter ( $ valueParameter , $ value ) ; break ; default : throw new InvalidArgumentException ( sprintf ( 'strategy %s does not exist.' , $ strategy ) ) ; } }
|
Adds where clause according to the strategy .
|
3,552
|
protected function createWrapCase ( bool $ caseSensitive ) : \ Closure { return function ( string $ expr ) use ( $ caseSensitive ) : string { if ( $ caseSensitive ) { return $ expr ; } return sprintf ( 'LOWER(%s)' , $ expr ) ; } ; }
|
Creates a function that will wrap a Doctrine expression according to the specified case sensitivity .
|
3,553
|
private function createSubresourceMetadata ( $ subresource , PropertyMetadata $ propertyMetadata ) : ? SubresourceMetadata { if ( ! $ subresource ) { return null ; } $ type = $ propertyMetadata -> getType ( ) ; $ maxDepth = \ is_array ( $ subresource ) ? $ subresource [ 'maxDepth' ] ?? null : null ; if ( null !== $ type ) { $ isCollection = $ type -> isCollection ( ) ; $ resourceClass = $ isCollection && ( $ collectionValueType = $ type -> getCollectionValueType ( ) ) ? $ collectionValueType -> getClassName ( ) : $ type -> getClassName ( ) ; } elseif ( \ is_array ( $ subresource ) && isset ( $ subresource [ 'resourceClass' ] ) ) { $ resourceClass = $ subresource [ 'resourceClass' ] ; $ isCollection = $ subresource [ 'collection' ] ?? true ; } else { return null ; } return new SubresourceMetadata ( $ resourceClass , $ isCollection , $ maxDepth ) ; }
|
Creates a SubresourceMetadata .
|
3,554
|
private function getQueryFields ( string $ resourceClass , ResourceMetadata $ resourceMetadata , string $ queryName , $ itemConfiguration , $ collectionConfiguration ) : array { $ queryFields = [ ] ; $ shortName = $ resourceMetadata -> getShortName ( ) ; $ fieldName = lcfirst ( 'query' === $ queryName ? $ shortName : $ queryName . $ shortName ) ; $ deprecationReason = $ resourceMetadata -> getGraphqlAttribute ( $ queryName , 'deprecation_reason' , '' , true ) ; if ( false !== $ itemConfiguration && $ fieldConfiguration = $ this -> getResourceFieldConfiguration ( $ resourceClass , $ resourceMetadata , null , $ deprecationReason , new Type ( Type :: BUILTIN_TYPE_OBJECT , true , $ resourceClass ) , $ resourceClass , false , $ queryName , null ) ) { $ itemConfiguration [ 'args' ] = $ itemConfiguration [ 'args' ] ?? [ 'id' => [ 'type' => GraphQLType :: nonNull ( GraphQLType :: id ( ) ) ] ] ; $ queryFields [ $ fieldName ] = array_merge ( $ fieldConfiguration , $ itemConfiguration ) ; } if ( false !== $ collectionConfiguration && $ fieldConfiguration = $ this -> getResourceFieldConfiguration ( $ resourceClass , $ resourceMetadata , null , $ deprecationReason , new Type ( Type :: BUILTIN_TYPE_OBJECT , false , null , true , null , new Type ( Type :: BUILTIN_TYPE_OBJECT , false , $ resourceClass ) ) , $ resourceClass , false , $ queryName , null ) ) { $ queryFields [ Inflector :: pluralize ( $ fieldName ) ] = array_merge ( $ fieldConfiguration , $ collectionConfiguration ) ; } return $ queryFields ; }
|
Gets the query fields of the schema .
|
3,555
|
private function getMutationField ( string $ resourceClass , ResourceMetadata $ resourceMetadata , string $ mutationName ) : array { $ shortName = $ resourceMetadata -> getShortName ( ) ; $ resourceType = new Type ( Type :: BUILTIN_TYPE_OBJECT , true , $ resourceClass ) ; $ deprecationReason = $ resourceMetadata -> getGraphqlAttribute ( $ mutationName , 'deprecation_reason' , '' , true ) ; if ( $ fieldConfiguration = $ this -> getResourceFieldConfiguration ( $ resourceClass , $ resourceMetadata , ucfirst ( "{$mutationName}s a $shortName." ) , $ deprecationReason , $ resourceType , $ resourceClass , false , null , $ mutationName ) ) { $ fieldConfiguration [ 'args' ] += [ 'input' => $ this -> getResourceFieldConfiguration ( $ resourceClass , $ resourceMetadata , null , $ deprecationReason , $ resourceType , $ resourceClass , true , null , $ mutationName ) ] ; if ( ! $ this -> isCollection ( $ resourceType ) ) { $ fieldConfiguration [ 'resolve' ] = ( $ this -> itemMutationResolverFactory ) ( $ resourceClass , null , $ mutationName ) ; } } return $ fieldConfiguration ?? [ ] ; }
|
Gets the mutation field for the given operation name .
|
3,556
|
private function convertType ( Type $ type , bool $ input , ? string $ queryName , ? string $ mutationName , int $ depth = 0 ) { switch ( $ builtinType = $ type -> getBuiltinType ( ) ) { case Type :: BUILTIN_TYPE_BOOL : $ graphqlType = GraphQLType :: boolean ( ) ; break ; case Type :: BUILTIN_TYPE_INT : $ graphqlType = GraphQLType :: int ( ) ; break ; case Type :: BUILTIN_TYPE_FLOAT : $ graphqlType = GraphQLType :: float ( ) ; break ; case Type :: BUILTIN_TYPE_STRING : $ graphqlType = GraphQLType :: string ( ) ; break ; case Type :: BUILTIN_TYPE_ARRAY : case Type :: BUILTIN_TYPE_ITERABLE : $ graphqlType = $ this -> graphqlTypes [ 'Iterable' ] ; break ; case Type :: BUILTIN_TYPE_OBJECT : if ( ( $ input && $ depth > 0 ) || is_a ( $ type -> getClassName ( ) , \ DateTimeInterface :: class , true ) ) { $ graphqlType = GraphQLType :: string ( ) ; break ; } $ resourceClass = $ this -> isCollection ( $ type ) && ( $ collectionValueType = $ type -> getCollectionValueType ( ) ) ? $ collectionValueType -> getClassName ( ) : $ type -> getClassName ( ) ; if ( null === $ resourceClass ) { return null ; } try { $ resourceMetadata = $ this -> resourceMetadataFactory -> create ( $ resourceClass ) ; if ( [ ] === $ resourceMetadata -> getGraphql ( ) ?? [ ] ) { return null ; } } catch ( ResourceClassNotFoundException $ e ) { return null ; } $ graphqlType = $ this -> getResourceObjectType ( $ resourceClass , $ resourceMetadata , $ input , $ queryName , $ mutationName , false , $ depth ) ; break ; default : throw new InvalidTypeException ( sprintf ( 'The type "%s" is not supported.' , $ builtinType ) ) ; } if ( $ this -> isCollection ( $ type ) ) { return $ this -> paginationEnabled && ! $ input ? $ this -> getResourcePaginatedCollectionType ( $ graphqlType ) : GraphQLType :: listOf ( $ graphqlType ) ; } return $ type -> isNullable ( ) || ( null !== $ mutationName && 'update' === $ mutationName ) ? $ graphqlType : GraphQLType :: nonNull ( $ graphqlType ) ; }
|
Converts a built - in type to its GraphQL equivalent .
|
3,557
|
private function getResourceObjectTypeFields ( ? string $ resourceClass , ResourceMetadata $ resourceMetadata , bool $ input , ? string $ queryName , ? string $ mutationName , int $ depth = 0 , ? array $ ioMetadata = null ) : array { $ fields = [ ] ; $ idField = [ 'type' => GraphQLType :: nonNull ( GraphQLType :: id ( ) ) ] ; $ clientMutationId = GraphQLType :: string ( ) ; if ( null !== $ ioMetadata && null === $ ioMetadata [ 'class' ] ) { if ( $ input ) { return [ 'clientMutationId' => $ clientMutationId ] ; } return [ ] ; } if ( 'delete' === $ mutationName ) { $ fields = [ 'id' => $ idField , ] ; if ( $ input ) { $ fields [ 'clientMutationId' ] = $ clientMutationId ; } return $ fields ; } if ( ! $ input || 'create' !== $ mutationName ) { $ fields [ 'id' ] = $ idField ; } ++ $ depth ; if ( null !== $ resourceClass ) { foreach ( $ this -> propertyNameCollectionFactory -> create ( $ resourceClass ) as $ property ) { $ propertyMetadata = $ this -> propertyMetadataFactory -> create ( $ resourceClass , $ property , [ 'graphql_operation_name' => $ mutationName ?? $ queryName ?? 'query' ] ) ; if ( null === ( $ propertyType = $ propertyMetadata -> getType ( ) ) || ( ! $ input && false === $ propertyMetadata -> isReadable ( ) ) || ( $ input && null !== $ mutationName && false === $ propertyMetadata -> isWritable ( ) ) ) { continue ; } $ rootResource = $ resourceClass ; if ( null !== $ propertyMetadata -> getSubresource ( ) ) { $ resourceClass = $ propertyMetadata -> getSubresource ( ) -> getResourceClass ( ) ; $ resourceMetadata = $ this -> resourceMetadataFactory -> create ( $ resourceClass ) ; } if ( $ fieldConfiguration = $ this -> getResourceFieldConfiguration ( $ resourceClass , $ resourceMetadata , $ propertyMetadata -> getDescription ( ) , $ propertyMetadata -> getAttribute ( 'deprecation_reason' , '' ) , $ propertyType , $ rootResource , $ input , $ queryName , $ mutationName , $ depth ) ) { $ fields [ 'id' === $ property ? '_id' : $ property ] = $ fieldConfiguration ; } $ resourceClass = $ rootResource ; } } if ( null !== $ mutationName && $ input ) { $ fields [ 'clientMutationId' ] = $ clientMutationId ; } return $ fields ; }
|
Gets the fields of the type of the given resource .
|
3,558
|
private function getResourcePaginatedCollectionType ( GraphQLType $ resourceType ) : GraphQLType { $ shortName = $ resourceType -> name ; if ( isset ( $ this -> graphqlTypes [ "{$shortName}Connection" ] ) ) { return $ this -> graphqlTypes [ "{$shortName}Connection" ] ; } $ edgeObjectTypeConfiguration = [ 'name' => "{$shortName}Edge" , 'description' => "Edge of $shortName." , 'fields' => [ 'node' => $ resourceType , 'cursor' => GraphQLType :: nonNull ( GraphQLType :: string ( ) ) , ] , ] ; $ edgeObjectType = new ObjectType ( $ edgeObjectTypeConfiguration ) ; $ this -> graphqlTypes [ "{$shortName}Edge" ] = $ edgeObjectType ; $ pageInfoObjectTypeConfiguration = [ 'name' => "{$shortName}PageInfo" , 'description' => 'Information about the current page.' , 'fields' => [ 'endCursor' => GraphQLType :: string ( ) , 'startCursor' => GraphQLType :: string ( ) , 'hasNextPage' => GraphQLType :: nonNull ( GraphQLType :: boolean ( ) ) , 'hasPreviousPage' => GraphQLType :: nonNull ( GraphQLType :: boolean ( ) ) , ] , ] ; $ pageInfoObjectType = new ObjectType ( $ pageInfoObjectTypeConfiguration ) ; $ this -> graphqlTypes [ "{$shortName}PageInfo" ] = $ pageInfoObjectType ; $ configuration = [ 'name' => "{$shortName}Connection" , 'description' => "Connection for $shortName." , 'fields' => [ 'edges' => GraphQLType :: listOf ( $ edgeObjectType ) , 'pageInfo' => GraphQLType :: nonNull ( $ pageInfoObjectType ) , 'totalCount' => GraphQLType :: nonNull ( GraphQLType :: int ( ) ) , ] , ] ; return $ this -> graphqlTypes [ "{$shortName}Connection" ] = new ObjectType ( $ configuration ) ; }
|
Gets the type of a paginated collection of the given resource type .
|
3,559
|
private function getApiDoc ( bool $ collection , string $ resourceClass , ResourceMetadata $ resourceMetadata , string $ operationName , array $ resourceHydraDoc , array $ entrypointHydraDoc = [ ] ) : ApiDoc { if ( $ collection ) { $ method = $ this -> operationMethodResolver -> getCollectionOperationMethod ( $ resourceClass , $ operationName ) ; $ route = $ this -> operationMethodResolver -> getCollectionOperationRoute ( $ resourceClass , $ operationName ) ; $ operationHydraDoc = $ this -> getCollectionOperationHydraDoc ( $ resourceMetadata -> getShortName ( ) , $ method , $ entrypointHydraDoc ) ; } else { $ method = $ this -> operationMethodResolver -> getItemOperationMethod ( $ resourceClass , $ operationName ) ; $ route = $ this -> operationMethodResolver -> getItemOperationRoute ( $ resourceClass , $ operationName ) ; $ operationHydraDoc = $ this -> getOperationHydraDoc ( $ method , $ resourceHydraDoc ) ; } $ data = [ 'resource' => $ route -> getPath ( ) , 'description' => $ operationHydraDoc [ 'hydra:title' ] ?? '' , 'resourceDescription' => $ resourceHydraDoc [ 'hydra:title' ] ?? '' , 'section' => $ resourceHydraDoc [ 'hydra:title' ] ?? '' , ] ; if ( isset ( $ operationHydraDoc [ 'expects' ] ) && 'owl:Nothing' !== $ operationHydraDoc [ 'expects' ] ) { $ data [ 'input' ] = sprintf ( '%s:%s:%s' , ApiPlatformParser :: IN_PREFIX , $ resourceClass , $ operationName ) ; } if ( isset ( $ operationHydraDoc [ 'returns' ] ) && 'owl:Nothing' !== $ operationHydraDoc [ 'returns' ] ) { $ data [ 'output' ] = sprintf ( '%s:%s:%s' , ApiPlatformParser :: OUT_PREFIX , $ resourceClass , $ operationName ) ; } if ( $ collection && 'GET' === $ method ) { $ resourceFilters = $ resourceMetadata -> getCollectionOperationAttribute ( $ operationName , 'filters' , [ ] , true ) ; $ data [ 'filters' ] = [ ] ; foreach ( $ resourceFilters as $ filterId ) { if ( $ filter = $ this -> getFilter ( $ filterId ) ) { foreach ( $ filter -> getDescription ( $ resourceClass ) as $ name => $ definition ) { $ data [ 'filters' ] [ ] = [ 'name' => $ name ] + $ definition ; } } } } $ apiDoc = new ApiDoc ( $ data ) ; $ apiDoc -> setRoute ( $ route ) ; return $ apiDoc ; }
|
Builds ApiDoc annotation from ApiPlatform data .
|
3,560
|
private function getResourceHydraDoc ( array $ hydraApiDoc , string $ prefixedShortName ) : ? array { if ( ! isset ( $ hydraApiDoc [ 'hydra:supportedClass' ] ) || ! \ is_array ( $ hydraApiDoc [ 'hydra:supportedClass' ] ) ) { return null ; } foreach ( $ hydraApiDoc [ 'hydra:supportedClass' ] as $ supportedClass ) { if ( isset ( $ supportedClass [ '@id' ] ) && $ supportedClass [ '@id' ] === $ prefixedShortName ) { return $ supportedClass ; } } return null ; }
|
Gets Hydra documentation for the given resource .
|
3,561
|
private function getOperationHydraDoc ( string $ method , array $ hydraDoc ) : array { if ( ! isset ( $ hydraDoc [ 'hydra:supportedOperation' ] ) || ! \ is_array ( $ hydraDoc [ 'hydra:supportedOperation' ] ) ) { return [ ] ; } foreach ( $ hydraDoc [ 'hydra:supportedOperation' ] as $ supportedOperation ) { if ( $ supportedOperation [ 'hydra:method' ] === $ method ) { return $ supportedOperation ; } } return [ ] ; }
|
Gets the Hydra documentation of a given operation .
|
3,562
|
private function getCollectionOperationHydraDoc ( string $ shortName , string $ method , array $ hydraEntrypointDoc ) : array { if ( ! isset ( $ hydraEntrypointDoc [ 'hydra:supportedProperty' ] ) || ! \ is_array ( $ hydraEntrypointDoc [ 'hydra:supportedProperty' ] ) ) { return [ ] ; } $ propertyName = '#Entrypoint/' . lcfirst ( $ shortName ) ; foreach ( $ hydraEntrypointDoc [ 'hydra:supportedProperty' ] as $ supportedProperty ) { if ( isset ( $ supportedProperty [ 'hydra:property' ] [ '@id' ] ) && $ supportedProperty [ 'hydra:property' ] [ '@id' ] === $ propertyName ) { return $ this -> getOperationHydraDoc ( $ method , $ supportedProperty [ 'hydra:property' ] ) ; } } return [ ] ; }
|
Gets the Hydra documentation for the collection operation .
|
3,563
|
private function populateRelation ( array $ data , $ object , ? string $ format , array $ context , array $ components , string $ type ) : array { $ class = $ this -> getObjectClass ( $ object ) ; $ attributesMetadata = \ array_key_exists ( $ class , $ this -> attributesMetadataCache ) ? $ this -> attributesMetadataCache [ $ class ] : $ this -> attributesMetadataCache [ $ class ] = $ this -> classMetadataFactory ? $ this -> classMetadataFactory -> getMetadataFor ( $ class ) -> getAttributesMetadata ( ) : null ; $ key = '_' . $ type ; foreach ( $ components [ $ type ] as $ relation ) { if ( null !== $ attributesMetadata && $ this -> isMaxDepthReached ( $ attributesMetadata , $ class , $ relation [ 'name' ] , $ context ) ) { continue ; } $ attributeValue = $ this -> getAttributeValue ( $ object , $ relation [ 'name' ] , $ format , $ context ) ; if ( empty ( $ attributeValue ) ) { continue ; } $ relationName = $ relation [ 'name' ] ; if ( $ this -> nameConverter ) { $ relationName = $ this -> nameConverter -> normalize ( $ relationName , $ class , $ format , $ context ) ; } if ( 'one' === $ relation [ 'cardinality' ] ) { if ( 'links' === $ type ) { $ data [ $ key ] [ $ relationName ] [ 'href' ] = $ this -> getRelationIri ( $ attributeValue ) ; continue ; } $ data [ $ key ] [ $ relationName ] = $ attributeValue ; continue ; } $ data [ $ key ] [ $ relationName ] = [ ] ; foreach ( $ attributeValue as $ rel ) { if ( 'links' === $ type ) { $ rel = [ 'href' => $ this -> getRelationIri ( $ rel ) ] ; } $ data [ $ key ] [ $ relationName ] [ ] = $ rel ; } } return $ data ; }
|
Populates _links and _embedded keys .
|
3,564
|
private function getRelationIri ( $ rel ) : string { if ( ! ( \ is_array ( $ rel ) || \ is_string ( $ rel ) ) ) { throw new UnexpectedValueException ( 'Expected relation to be an IRI or array' ) ; } return \ is_string ( $ rel ) ? $ rel : $ rel [ '_links' ] [ 'self' ] [ 'href' ] ; }
|
Gets the IRI of the given relation .
|
3,565
|
private function getPropertySerializerGroups ( string $ resourceClass , string $ property ) : array { $ serializerClassMetadata = $ this -> serializerClassMetadataFactory -> getMetadataFor ( $ resourceClass ) ; foreach ( $ serializerClassMetadata -> getAttributesMetadata ( ) as $ serializerAttributeMetadata ) { if ( $ property === $ serializerAttributeMetadata -> getName ( ) ) { return $ serializerAttributeMetadata -> getGroups ( ) ; } } return [ ] ; }
|
Gets the serializer groups defined on a property .
|
3,566
|
private function getResourceSerializerGroups ( string $ resourceClass ) : array { $ serializerClassMetadata = $ this -> serializerClassMetadataFactory -> getMetadataFor ( $ resourceClass ) ; $ groups = [ ] ; foreach ( $ serializerClassMetadata -> getAttributesMetadata ( ) as $ serializerAttributeMetadata ) { $ groups += array_flip ( $ serializerAttributeMetadata -> getGroups ( ) ) ; } return array_keys ( $ groups ) ; }
|
Gets the serializer groups defined in a resource .
|
3,567
|
private function getManager ( string $ resourceClass , $ data ) : ? ObjectManager { $ objectManager = $ this -> managerRegistry -> getManagerForClass ( $ resourceClass ) ; if ( null === $ objectManager || ! \ is_object ( $ data ) ) { return null ; } return $ objectManager ; }
|
Gets the manager if applicable .
|
3,568
|
public function withType ( Type $ type ) : self { $ metadata = clone $ this ; $ metadata -> type = $ type ; return $ metadata ; }
|
Returns a new instance with the given type .
|
3,569
|
public function withDescription ( string $ description ) : self { $ metadata = clone $ this ; $ metadata -> description = $ description ; return $ metadata ; }
|
Returns a new instance with the given description .
|
3,570
|
public function withReadable ( bool $ readable ) : self { $ metadata = clone $ this ; $ metadata -> readable = $ readable ; return $ metadata ; }
|
Returns a new instance of Metadata with the given readable flag .
|
3,571
|
public function withWritable ( bool $ writable ) : self { $ metadata = clone $ this ; $ metadata -> writable = $ writable ; return $ metadata ; }
|
Returns a new instance with the given writable flag .
|
3,572
|
public function withRequired ( bool $ required ) : self { $ metadata = clone $ this ; $ metadata -> required = $ required ; return $ metadata ; }
|
Returns a new instance with the given required flag .
|
3,573
|
public function withWritableLink ( bool $ writableLink ) : self { $ metadata = clone $ this ; $ metadata -> writableLink = $ writableLink ; return $ metadata ; }
|
Returns a new instance with the given writable link flag .
|
3,574
|
public function withReadableLink ( bool $ readableLink ) : self { $ metadata = clone $ this ; $ metadata -> readableLink = $ readableLink ; return $ metadata ; }
|
Returns a new instance with the given readable link flag .
|
3,575
|
public function withIdentifier ( bool $ identifier ) : self { $ metadata = clone $ this ; $ metadata -> identifier = $ identifier ; return $ metadata ; }
|
Returns a new instance with the given identifier flag .
|
3,576
|
public function withChildInherited ( string $ childInherited ) : self { $ metadata = clone $ this ; $ metadata -> childInherited = $ childInherited ; return $ metadata ; }
|
Returns a new instance with the given child inherited class .
|
3,577
|
public function withSubresource ( SubresourceMetadata $ subresource = null ) : self { $ metadata = clone $ this ; $ metadata -> subresource = $ subresource ; return $ metadata ; }
|
Returns a new instance with the given subresource .
|
3,578
|
public function withInitializable ( bool $ initializable ) : self { $ metadata = clone $ this ; $ metadata -> initializable = $ initializable ; return $ metadata ; }
|
Returns a new instance with the given initializable flag .
|
3,579
|
private function addPaths ( bool $ v3 , \ ArrayObject $ paths , \ ArrayObject $ definitions , string $ resourceClass , string $ resourceShortName , ResourceMetadata $ resourceMetadata , array $ mimeTypes , string $ operationType , \ ArrayObject $ links ) { if ( null === $ operations = OperationType :: COLLECTION === $ operationType ? $ resourceMetadata -> getCollectionOperations ( ) : $ resourceMetadata -> getItemOperations ( ) ) { return ; } foreach ( $ operations as $ operationName => $ operation ) { $ path = $ this -> getPath ( $ resourceShortName , $ operationName , $ operation , $ operationType ) ; $ method = OperationType :: ITEM === $ operationType ? $ this -> operationMethodResolver -> getItemOperationMethod ( $ resourceClass , $ operationName ) : $ this -> operationMethodResolver -> getCollectionOperationMethod ( $ resourceClass , $ operationName ) ; $ paths [ $ path ] [ strtolower ( $ method ) ] = $ this -> getPathOperation ( $ v3 , $ operationName , $ operation , $ method , $ operationType , $ resourceClass , $ resourceMetadata , $ mimeTypes , $ definitions , $ links ) ; } }
|
Updates the list of entries in the paths collection .
|
3,580
|
private function getPath ( string $ resourceShortName , string $ operationName , array $ operation , string $ operationType ) : string { $ path = $ this -> operationPathResolver -> resolveOperationPath ( $ resourceShortName , $ operation , $ operationType , $ operationName ) ; if ( '.{_format}' === substr ( $ path , - 10 ) ) { $ path = substr ( $ path , 0 , - 10 ) ; } return $ path ; }
|
Gets the path for an operation .
|
3,581
|
private function getPathOperation ( bool $ v3 , string $ operationName , array $ operation , string $ method , string $ operationType , string $ resourceClass , ResourceMetadata $ resourceMetadata , array $ mimeTypes , \ ArrayObject $ definitions , \ ArrayObject $ links ) : \ ArrayObject { $ pathOperation = new \ ArrayObject ( $ operation [ $ v3 ? 'openapi_context' : 'swagger_context' ] ?? [ ] ) ; $ resourceShortName = $ resourceMetadata -> getShortName ( ) ; $ pathOperation [ 'tags' ] ?? $ pathOperation [ 'tags' ] = [ $ resourceShortName ] ; $ pathOperation [ 'operationId' ] ?? $ pathOperation [ 'operationId' ] = lcfirst ( $ operationName ) . ucfirst ( $ resourceShortName ) . ucfirst ( $ operationType ) ; if ( $ v3 && 'GET' === $ method && OperationType :: ITEM === $ operationType && $ link = $ this -> getLinkObject ( $ resourceClass , $ pathOperation [ 'operationId' ] , $ this -> getPath ( $ resourceShortName , $ operationName , $ operation , $ operationType ) ) ) { $ links [ $ pathOperation [ 'operationId' ] ] = $ link ; } if ( $ resourceMetadata -> getTypedOperationAttribute ( $ operationType , $ operationName , 'deprecation_reason' , null , true ) ) { $ pathOperation [ 'deprecated' ] = true ; } if ( null !== $ this -> formatsProvider ) { $ responseFormats = $ this -> formatsProvider -> getFormatsFromOperation ( $ resourceClass , $ operationName , $ operationType ) ; $ responseMimeTypes = $ this -> extractMimeTypes ( $ responseFormats ) ; } switch ( $ method ) { case 'GET' : return $ this -> updateGetOperation ( $ v3 , $ pathOperation , $ responseMimeTypes ?? $ mimeTypes , $ operationType , $ resourceMetadata , $ resourceClass , $ resourceShortName , $ operationName , $ definitions ) ; case 'POST' : return $ this -> updatePostOperation ( $ v3 , $ pathOperation , $ responseMimeTypes ?? $ mimeTypes , $ operationType , $ resourceMetadata , $ resourceClass , $ resourceShortName , $ operationName , $ definitions , $ links ) ; case 'PATCH' : $ pathOperation [ 'summary' ] ?? $ pathOperation [ 'summary' ] = sprintf ( 'Updates the %s resource.' , $ resourceShortName ) ; case 'PUT' : return $ this -> updatePutOperation ( $ v3 , $ pathOperation , $ responseMimeTypes ?? $ mimeTypes , $ operationType , $ resourceMetadata , $ resourceClass , $ resourceShortName , $ operationName , $ definitions ) ; case 'DELETE' : return $ this -> updateDeleteOperation ( $ v3 , $ pathOperation , $ resourceShortName , $ operationType , $ operationName , $ resourceMetadata ) ; } return $ pathOperation ; }
|
Gets a path Operation Object .
|
3,582
|
private function getDefinitionSchema ( bool $ v3 , string $ resourceClass , ResourceMetadata $ resourceMetadata , \ ArrayObject $ definitions , array $ serializerContext = null ) : \ ArrayObject { $ definitionSchema = new \ ArrayObject ( [ 'type' => 'object' ] ) ; if ( null !== $ description = $ resourceMetadata -> getDescription ( ) ) { $ definitionSchema [ 'description' ] = $ description ; } if ( null !== $ iri = $ resourceMetadata -> getIri ( ) ) { $ definitionSchema [ 'externalDocs' ] = [ 'url' => $ iri ] ; } $ options = isset ( $ serializerContext [ AbstractNormalizer :: GROUPS ] ) ? [ 'serializer_groups' => $ serializerContext [ AbstractNormalizer :: GROUPS ] ] : [ ] ; foreach ( $ this -> propertyNameCollectionFactory -> create ( $ resourceClass , $ options ) as $ propertyName ) { $ propertyMetadata = $ this -> propertyMetadataFactory -> create ( $ resourceClass , $ propertyName ) ; $ normalizedPropertyName = $ this -> nameConverter ? $ this -> nameConverter -> normalize ( $ propertyName , $ resourceClass , self :: FORMAT , $ serializerContext ?? [ ] ) : $ propertyName ; if ( $ propertyMetadata -> isRequired ( ) ) { $ definitionSchema [ 'required' ] [ ] = $ normalizedPropertyName ; } $ definitionSchema [ 'properties' ] [ $ normalizedPropertyName ] = $ this -> getPropertySchema ( $ v3 , $ propertyMetadata , $ definitions , $ serializerContext ) ; } return $ definitionSchema ; }
|
Gets a definition Schema Object .
|
3,583
|
private function getPropertySchema ( bool $ v3 , PropertyMetadata $ propertyMetadata , \ ArrayObject $ definitions , array $ serializerContext = null ) : \ ArrayObject { $ propertySchema = new \ ArrayObject ( $ propertyMetadata -> getAttributes ( ) [ $ v3 ? 'openapi_context' : 'swagger_context' ] ?? [ ] ) ; if ( false === $ propertyMetadata -> isWritable ( ) && ! $ propertyMetadata -> isInitializable ( ) ) { $ propertySchema [ 'readOnly' ] = true ; } if ( null !== $ description = $ propertyMetadata -> getDescription ( ) ) { $ propertySchema [ 'description' ] = $ description ; } if ( null === $ type = $ propertyMetadata -> getType ( ) ) { return $ propertySchema ; } $ isCollection = $ type -> isCollection ( ) ; if ( null === $ valueType = $ isCollection ? $ type -> getCollectionValueType ( ) : $ type ) { $ builtinType = 'string' ; $ className = null ; } else { $ builtinType = $ valueType -> getBuiltinType ( ) ; $ className = $ valueType -> getClassName ( ) ; } $ valueSchema = $ this -> getType ( $ v3 , $ builtinType , $ isCollection , $ className , $ propertyMetadata -> isReadableLink ( ) , $ definitions , $ serializerContext ) ; return new \ ArrayObject ( ( array ) $ propertySchema + $ valueSchema ) ; }
|
Gets a property Schema Object .
|
3,584
|
private function getType ( bool $ v3 , string $ type , bool $ isCollection , ? string $ className , ? bool $ readableLink , \ ArrayObject $ definitions , array $ serializerContext = null ) : array { if ( $ isCollection ) { return [ 'type' => 'array' , 'items' => $ this -> getType ( $ v3 , $ type , false , $ className , $ readableLink , $ definitions , $ serializerContext ) ] ; } if ( Type :: BUILTIN_TYPE_STRING === $ type ) { return [ 'type' => 'string' ] ; } if ( Type :: BUILTIN_TYPE_INT === $ type ) { return [ 'type' => 'integer' ] ; } if ( Type :: BUILTIN_TYPE_FLOAT === $ type ) { return [ 'type' => 'number' ] ; } if ( Type :: BUILTIN_TYPE_BOOL === $ type ) { return [ 'type' => 'boolean' ] ; } if ( Type :: BUILTIN_TYPE_OBJECT === $ type ) { if ( null === $ className ) { return [ 'type' => 'string' ] ; } if ( is_subclass_of ( $ className , \ DateTimeInterface :: class ) ) { return [ 'type' => 'string' , 'format' => 'date-time' ] ; } if ( ! $ this -> resourceClassResolver -> isResourceClass ( $ className ) ) { return [ 'type' => 'string' ] ; } if ( true === $ readableLink ) { return [ '$ref' => sprintf ( $ v3 ? '#/components/schemas/%s' : '#/definitions/%s' , $ this -> getDefinition ( $ v3 , $ definitions , $ resourceMetadata = $ this -> resourceMetadataFactory -> create ( $ className ) , $ className , $ resourceMetadata -> getAttribute ( 'output' ) [ 'class' ] ?? $ className , $ serializerContext ) ) , ] ; } } return [ 'type' => 'string' ] ; }
|
Gets the Swagger s type corresponding to the given PHP s type .
|
3,585
|
private function getFiltersParameters ( bool $ v3 , string $ resourceClass , string $ operationName , ResourceMetadata $ resourceMetadata , \ ArrayObject $ definitions , array $ serializerContext = null ) : array { if ( null === $ this -> filterLocator ) { return [ ] ; } $ parameters = [ ] ; $ resourceFilters = $ resourceMetadata -> getCollectionOperationAttribute ( $ operationName , 'filters' , [ ] , true ) ; foreach ( $ resourceFilters as $ filterId ) { if ( ! $ filter = $ this -> getFilter ( $ filterId ) ) { continue ; } foreach ( $ filter -> getDescription ( $ resourceClass ) as $ name => $ data ) { $ parameter = [ 'name' => $ name , 'in' => 'query' , 'required' => $ data [ 'required' ] , ] ; $ type = $ this -> getType ( $ v3 , $ data [ 'type' ] , $ data [ 'is_collection' ] ?? false , null , null , $ definitions , $ serializerContext ) ; $ v3 ? $ parameter [ 'schema' ] = $ type : $ parameter += $ type ; if ( 'array' === $ type [ 'type' ] ?? '' ) { $ deepObject = \ in_array ( $ data [ 'type' ] , [ Type :: BUILTIN_TYPE_ARRAY , Type :: BUILTIN_TYPE_OBJECT ] , true ) ; if ( $ v3 ) { $ parameter [ 'style' ] = $ deepObject ? 'deepObject' : 'form' ; $ parameter [ 'explode' ] = true ; } else { $ parameter [ 'collectionFormat' ] = $ deepObject ? 'csv' : 'multi' ; } } $ key = $ v3 ? 'openapi' : 'swagger' ; if ( isset ( $ data [ $ key ] ) ) { $ parameter = $ data [ $ key ] + $ parameter ; } $ parameters [ ] = $ parameter ; } } return $ parameters ; }
|
Gets parameters corresponding to enabled filters .
|
3,586
|
private function loadExternalFiles ( RouteCollection $ routeCollection ) : void { if ( $ this -> entrypointEnabled ) { $ routeCollection -> addCollection ( $ this -> fileLoader -> load ( 'api.xml' ) ) ; } if ( $ this -> docsEnabled ) { $ routeCollection -> addCollection ( $ this -> fileLoader -> load ( 'docs.xml' ) ) ; } if ( $ this -> graphqlEnabled ) { $ graphqlCollection = $ this -> fileLoader -> load ( 'graphql.xml' ) ; $ graphqlCollection -> addDefaults ( [ '_graphql' => true ] ) ; $ routeCollection -> addCollection ( $ graphqlCollection ) ; } if ( isset ( $ this -> formats [ 'jsonld' ] ) ) { $ routeCollection -> addCollection ( $ this -> fileLoader -> load ( 'jsonld.xml' ) ) ; } }
|
Load external files .
|
3,587
|
private function addRoute ( RouteCollection $ routeCollection , string $ resourceClass , string $ operationName , array $ operation , ResourceMetadata $ resourceMetadata , string $ operationType ) : void { $ resourceShortName = $ resourceMetadata -> getShortName ( ) ; if ( isset ( $ operation [ 'route_name' ] ) ) { return ; } if ( ! isset ( $ operation [ 'method' ] ) ) { throw new RuntimeException ( sprintf ( 'Either a "route_name" or a "method" operation attribute must exist for the operation "%s" of the resource "%s".' , $ operationName , $ resourceClass ) ) ; } if ( null === $ controller = $ operation [ 'controller' ] ?? null ) { $ controller = sprintf ( '%s%s_%s' , self :: DEFAULT_ACTION_PATTERN , strtolower ( $ operation [ 'method' ] ) , $ operationType ) ; if ( ! $ this -> container -> has ( $ controller ) ) { throw new RuntimeException ( sprintf ( 'There is no builtin action for the %s %s operation. You need to define the controller yourself.' , $ operationType , $ operation [ 'method' ] ) ) ; } } $ path = trim ( trim ( $ resourceMetadata -> getAttribute ( 'route_prefix' , '' ) ) , '/' ) ; $ path .= $ this -> operationPathResolver -> resolveOperationPath ( $ resourceShortName , $ operation , $ operationType , $ operationName ) ; $ route = new Route ( $ path , [ '_controller' => $ controller , '_format' => null , '_api_resource_class' => $ resourceClass , sprintf ( '_api_%s_operation_name' , $ operationType ) => $ operationName , ] + ( $ operation [ 'defaults' ] ?? [ ] ) , $ operation [ 'requirements' ] ?? [ ] , $ operation [ 'options' ] ?? [ ] , $ operation [ 'host' ] ?? '' , $ operation [ 'schemes' ] ?? [ ] , [ $ operation [ 'method' ] ] , $ operation [ 'condition' ] ?? '' ) ; $ routeCollection -> add ( RouteNameGenerator :: generate ( $ operationName , $ resourceShortName , $ operationType ) , $ route ) ; }
|
Creates and adds a route for the given operation to the route collection .
|
3,588
|
protected function isPropertyMapped ( string $ property , string $ resourceClass , bool $ allowAssociation = false ) : bool { if ( $ this -> isPropertyNested ( $ property , $ resourceClass ) ) { $ propertyParts = $ this -> splitPropertyParts ( $ property , $ resourceClass ) ; $ metadata = $ this -> getNestedMetadata ( $ resourceClass , $ propertyParts [ 'associations' ] ) ; $ property = $ propertyParts [ 'field' ] ; } else { $ metadata = $ this -> getClassMetadata ( $ resourceClass ) ; } return $ metadata -> hasField ( $ property ) || ( $ allowAssociation && $ metadata -> hasAssociation ( $ property ) ) ; }
|
Determines whether the given property is mapped .
|
3,589
|
protected function isPropertyNested ( string $ property ) : bool { if ( \ func_num_args ( ) > 1 ) { $ resourceClass = ( string ) func_get_arg ( 1 ) ; } else { if ( __CLASS__ !== \ get_class ( $ this ) ) { $ r = new \ ReflectionMethod ( $ this , __FUNCTION__ ) ; if ( __CLASS__ !== $ r -> getDeclaringClass ( ) -> getName ( ) ) { @ trigger_error ( sprintf ( 'Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.' , __FUNCTION__ ) , E_USER_DEPRECATED ) ; } } $ resourceClass = null ; } $ pos = strpos ( $ property , '.' ) ; if ( false === $ pos ) { return false ; } return null !== $ resourceClass && $ this -> getClassMetadata ( $ resourceClass ) -> hasAssociation ( substr ( $ property , 0 , $ pos ) ) ; }
|
Determines whether the given property is nested .
|
3,590
|
protected function isPropertyEmbedded ( string $ property , string $ resourceClass ) : bool { return false !== strpos ( $ property , '.' ) && $ this -> getClassMetadata ( $ resourceClass ) -> hasField ( $ property ) ; }
|
Determines whether the given property is embedded .
|
3,591
|
protected function splitPropertyParts ( string $ property ) : array { $ resourceClass = null ; $ parts = explode ( '.' , $ property ) ; if ( \ func_num_args ( ) > 1 ) { $ resourceClass = func_get_arg ( 1 ) ; } elseif ( __CLASS__ !== \ get_class ( $ this ) ) { $ r = new \ ReflectionMethod ( $ this , __FUNCTION__ ) ; if ( __CLASS__ !== $ r -> getDeclaringClass ( ) -> getName ( ) ) { @ trigger_error ( sprintf ( 'Method %s() will have a second `$resourceClass` argument in version API Platform 3.0. Not defining it is deprecated since API Platform 2.1.' , __FUNCTION__ ) , E_USER_DEPRECATED ) ; } } if ( null === $ resourceClass ) { return [ 'associations' => \ array_slice ( $ parts , 0 , - 1 ) , 'field' => end ( $ parts ) , ] ; } $ metadata = $ this -> getClassMetadata ( $ resourceClass ) ; $ slice = 0 ; foreach ( $ parts as $ part ) { if ( $ metadata -> hasAssociation ( $ part ) ) { $ metadata = $ this -> getClassMetadata ( $ metadata -> getAssociationTargetClass ( $ part ) ) ; ++ $ slice ; } } if ( \ count ( $ parts ) === $ slice ) { -- $ slice ; } return [ 'associations' => \ array_slice ( $ parts , 0 , $ slice ) , 'field' => implode ( '.' , \ array_slice ( $ parts , $ slice ) ) , ] ; }
|
Splits the given property into parts .
|
3,592
|
protected function getNestedMetadata ( string $ resourceClass , array $ associations ) : ClassMetadata { $ metadata = $ this -> getClassMetadata ( $ resourceClass ) ; foreach ( $ associations as $ association ) { if ( $ metadata -> hasAssociation ( $ association ) ) { $ associationClass = $ metadata -> getAssociationTargetClass ( $ association ) ; $ metadata = $ this -> getClassMetadata ( $ associationClass ) ; } } return $ metadata ; }
|
Gets nested class metadata for the given resource .
|
3,593
|
private function getGroupsForItemAndCollectionOperation ( ResourceMetadata $ resourceMetadata , string $ operationName , string $ io ) : array { $ operation = $ this -> getGroupsContext ( $ resourceMetadata , $ operationName , true ) ; $ operation += $ this -> getGroupsContext ( $ resourceMetadata , $ operationName , false ) ; if ( self :: OUT_PREFIX === $ io ) { return [ 'serializer_groups' => ! empty ( $ operation [ 'normalization_context' ] ) ? $ operation [ 'normalization_context' ] [ AbstractNormalizer :: GROUPS ] : [ ] , ] ; } if ( self :: IN_PREFIX === $ io ) { return [ 'serializer_groups' => ! empty ( $ operation [ 'denormalization_context' ] ) ? $ operation [ 'denormalization_context' ] [ AbstractNormalizer :: GROUPS ] : [ ] , ] ; } return [ ] ; }
|
Returns groups of item & collection .
|
3,594
|
private function getPropertyMetadata ( ResourceMetadata $ resourceMetadata , string $ resourceClass , string $ io , array $ visited , array $ options ) : array { $ data = [ ] ; foreach ( $ this -> propertyNameCollectionFactory -> create ( $ resourceClass , $ options ) as $ propertyName ) { $ propertyMetadata = $ this -> propertyMetadataFactory -> create ( $ resourceClass , $ propertyName ) ; if ( ( $ propertyMetadata -> isReadable ( ) && self :: OUT_PREFIX === $ io ) || ( $ propertyMetadata -> isWritable ( ) && self :: IN_PREFIX === $ io ) ) { $ normalizedPropertyName = $ this -> nameConverter ? $ this -> nameConverter -> normalize ( $ propertyName , $ resourceClass ) : $ propertyName ; $ data [ $ normalizedPropertyName ] = $ this -> parseProperty ( $ resourceMetadata , $ propertyMetadata , $ io , null , $ visited ) ; } } return $ data ; }
|
Returns a property metadata .
|
3,595
|
public function onFlush ( OnFlushEventArgs $ eventArgs ) : void { $ uow = $ eventArgs -> getEntityManager ( ) -> getUnitOfWork ( ) ; foreach ( $ uow -> getScheduledEntityInsertions ( ) as $ entity ) { $ this -> storeEntityToPublish ( $ entity , 'createdEntities' ) ; } foreach ( $ uow -> getScheduledEntityUpdates ( ) as $ entity ) { $ this -> storeEntityToPublish ( $ entity , 'updatedEntities' ) ; } foreach ( $ uow -> getScheduledEntityDeletions ( ) as $ entity ) { $ this -> storeEntityToPublish ( $ entity , 'deletedEntities' ) ; } }
|
Collects created updated and deleted entities .
|
3,596
|
public function postFlush ( ) : void { try { foreach ( $ this -> createdEntities as $ entity ) { $ this -> publishUpdate ( $ entity , $ this -> createdEntities [ $ entity ] ) ; } foreach ( $ this -> updatedEntities as $ entity ) { $ this -> publishUpdate ( $ entity , $ this -> updatedEntities [ $ entity ] ) ; } foreach ( $ this -> deletedEntities as $ entity ) { $ this -> publishUpdate ( $ entity , $ this -> deletedEntities [ $ entity ] ) ; } } finally { $ this -> reset ( ) ; } }
|
Publishes updates for changes collected on flush and resets the store .
|
3,597
|
protected function getFilterDescription ( string $ fieldName , string $ operator ) : array { return [ sprintf ( '%s[%s]' , $ fieldName , $ operator ) => [ 'property' => $ fieldName , 'type' => 'string' , 'required' => false , ] , ] ; }
|
Gets filter description .
|
3,598
|
private function normalizeBetweenValues ( array $ values ) : ? array { if ( 2 !== \ count ( $ values ) ) { $ this -> getLogger ( ) -> notice ( 'Invalid filter ignored' , [ 'exception' => new InvalidArgumentException ( sprintf ( 'Invalid format for "[%s]", expected "<min>..<max>"' , self :: PARAMETER_BETWEEN ) ) , ] ) ; return null ; } if ( ! is_numeric ( $ values [ 0 ] ) || ! is_numeric ( $ values [ 1 ] ) ) { $ this -> getLogger ( ) -> notice ( 'Invalid filter ignored' , [ 'exception' => new InvalidArgumentException ( sprintf ( 'Invalid values for "[%s]" range, expected numbers' , self :: PARAMETER_BETWEEN ) ) , ] ) ; return null ; } return [ $ values [ 0 ] + 0 , $ values [ 1 ] + 0 ] ; }
|
Normalize the values array for between operator .
|
3,599
|
private function normalizeValue ( string $ value , string $ operator ) { if ( ! is_numeric ( $ value ) ) { $ this -> getLogger ( ) -> notice ( 'Invalid filter ignored' , [ 'exception' => new InvalidArgumentException ( sprintf ( 'Invalid value for "[%s]", expected number' , $ operator ) ) , ] ) ; return null ; } return $ value + 0 ; }
|
Normalize the value .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.