2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< ? php  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/*  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  This  file  is  part  of  the  Symfony  package . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  ( c )  Fabien  Potencier  < fabien @ symfony . com > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  For  the  full  copyright  and  license  information ,  please  view  the  LICENSE 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  file  that  was  distributed  with  this  source  code . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  Symfony\Component\Serializer\Mapping\Loader ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								use  Symfony\Component\Serializer\Exception\MappingException ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								use  Symfony\Component\Serializer\Mapping\AttributeMetadata ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								use  Symfony\Component\Serializer\Mapping\ClassMetadataInterface ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								use  Symfony\Component\Yaml\Parser ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  YAML  File  Loader . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  @ author  Kévin  Dunglas  < dunglas @ gmail . com > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  YamlFileLoader  extends  FileLoader  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								{  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  $yamlParser ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** 
							 
						 
					
						
							
								
									
										
										
										
											2015-10-08 11:40:12 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								     *  An  array  of  YAML  class  descriptions . 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ var  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */ 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    private  $classes ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  { @ inheritdoc } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  function  loadClassMetadata ( ClassMetadataInterface  $classMetadata ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( null  ===  $this -> classes )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $this -> classes  =  $this -> getClassesFromYaml (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! $this -> classes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( ! isset ( $this -> classes [ $classMetadata -> getName ()]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  false ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        $yaml  =  $this -> classes [ $classMetadata -> getName ()]; 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 09:56:34 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( isset ( $yaml [ 'attributes' ])  &&  \is_array ( $yaml [ 'attributes' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            $attributesMetadata  =  $classMetadata -> getAttributesMetadata (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            foreach  ( $yaml [ 'attributes' ]  as  $attribute  =>  $data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( isset ( $attributesMetadata [ $attribute ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $attributeMetadata  =  $attributesMetadata [ $attribute ]; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $attributeMetadata  =  new  AttributeMetadata ( $attribute ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $classMetadata -> addAttributeMetadata ( $attributeMetadata ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2016-04-20 09:56:34 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                if  ( isset ( $data [ 'groups' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                    if  ( ! \is_array ( $data [ 'groups' ]))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        throw  new  MappingException ( sprintf ( 'The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".' ,  $this -> file ,  $attribute ,  $classMetadata -> getName ())); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    foreach  ( $data [ 'groups' ]  as  $group )  { 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                        if  ( ! \is_string ( $group ))  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                            throw  new  MappingException ( sprintf ( 'Group names must be strings in "%s" for the attribute "%s" of the class "%s".' ,  $this -> file ,  $attribute ,  $classMetadata -> getName ())); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                        } 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        $attributeMetadata -> addGroup ( $group ); 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ( isset ( $data [ 'max_depth' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  ( ! \is_int ( $data [ 'max_depth' ]))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        throw  new  MappingException ( sprintf ( 'The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".' ,  $this -> file ,  $attribute ,  $classMetadata -> getName ())); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    $attributeMetadata -> setMaxDepth ( $data [ 'max_depth' ]); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                } 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-04-13 15:53:35 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        return  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2018-11-23 12:29:20 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    /** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  Return  the  names  of  the  classes  mapped  in  this  file . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     *  @ return  string []  The  classes  names 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								     */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    public  function  getMappedClasses () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( null  ===  $this -> classes )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $this -> classes  =  $this -> getClassesFromYaml (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  array_keys ( $this -> classes ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    private  function  getClassesFromYaml () 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! stream_is_local ( $this -> file ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            throw  new  MappingException ( sprintf ( 'This is not a local file "%s".' ,  $this -> file )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( null  ===  $this -> yamlParser )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            $this -> yamlParser  =  new  Parser (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        $classes  =  $this -> yamlParser -> parseFile ( $this -> file ); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( empty ( $classes ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  array (); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! \is_array ( $classes ))  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            throw  new  MappingException ( sprintf ( 'The file "%s" must contain a YAML array.' ,  $this -> file )); 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  $classes ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-17 17:00:26 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								}