idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
15,800
private function dimOffset ( ArrayLookupNode $ node ) { $ this -> mustMatch ( '[' , $ node ) ; if ( $ this -> currentType !== ']' ) { $ node -> addChild ( $ this -> expr ( ) , 'key' ) ; } $ this -> mustMatch ( ']' , $ node , NULL , TRUE ) ; }
Parse dimensional offset .
15,801
private function functionCallParameterList ( $ node ) { $ arguments = new CommaListNode ( ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ node -> addChild ( $ arguments , 'arguments' ) ; if ( $ this -> tryMatch ( ')' , $ node , 'closeParen' , TRUE ) ) { return ; } if ( $ this -> currentType === T_YIELD ) { $ arguments -> addChild ( $ this -> _yield ( ) ) ; } else { do { $ arguments -> addChild ( $ this -> functionCallParameter ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ arguments ) ) ; } $ this -> mustMatch ( ')' , $ node , 'closeParen' , TRUE ) ; }
Parse function call parameter list .
15,802
private function functionCallParameter ( ) { switch ( $ this -> currentType ) { case '&' : return $ this -> writeVariable ( ) ; case T_ELLIPSIS : $ node = new SplatNode ( ) ; $ this -> mustMatch ( T_ELLIPSIS , $ node ) ; $ node -> addChild ( $ this -> expr ( ) , 'expression' ) ; return $ node ; default : return $ this -> expr ( ) ; } }
Parse function call parameter .
15,803
private function arrayDeference ( Node $ node ) { while ( $ this -> currentType === '[' ) { $ n = $ node ; $ node = new ArrayLookupNode ( ) ; $ node -> addChild ( $ n , 'array' ) ; $ this -> dimOffset ( $ node ) ; } return $ node ; }
Apply any array deference to operand .
15,804
private function functionDeclaration ( ) { $ node = new FunctionDeclarationNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ this -> mustMatch ( T_FUNCTION , $ node ) ; $ this -> tryMatch ( '&' , $ node , 'reference' ) ; $ name_node = new NameNode ( ) ; $ this -> mustMatch ( T_STRING , $ name_node , NULL , TRUE ) ; $ node -> addChild ( $ name_node , 'name' ) ; $ this -> parameterList ( $ node ) ; $ this -> matchHidden ( $ node ) ; $ this -> body ( $ node ) ; return $ node ; }
Parse function declaration .
15,805
private function parameterList ( ParentNode $ parent ) { $ node = new CommaListNode ( ) ; $ this -> mustMatch ( '(' , $ parent , 'openParen' ) ; $ parent -> addChild ( $ node , 'parameters' ) ; if ( $ this -> tryMatch ( ')' , $ parent , 'closeParen' , TRUE ) ) { return ; } do { $ node -> addChild ( $ this -> parameter ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ node ) ) ; $ this -> mustMatch ( ')' , $ parent , 'closeParen' , TRUE ) ; }
Parse parameter list .
15,806
private function parameter ( ) { $ node = new ParameterNode ( ) ; if ( $ type = $ this -> optionalTypeHint ( ) ) { $ node -> addChild ( $ type , 'typeHint' ) ; } $ this -> tryMatch ( '&' , $ node , 'reference' ) ; $ this -> tryMatch ( T_ELLIPSIS , $ node , 'variadic' ) ; $ this -> mustMatch ( T_VARIABLE , $ node , 'name' , TRUE ) ; if ( $ this -> tryMatch ( '=' , $ node ) ) { $ node -> addChild ( $ this -> staticScalar ( ) , 'value' ) ; } return $ node ; }
Parse parameter .
15,807
private function optionalTypeHint ( ) { static $ array_callable_types = [ T_ARRAY , T_CALLABLE ] ; $ node = NULL ; if ( $ node = $ this -> tryMatchToken ( $ array_callable_types ) ) { return $ node ; } elseif ( in_array ( $ this -> currentType , self :: $ namespacePathTypes ) ) { return $ this -> name ( ) ; } return NULL ; }
Parse optional class type for parameter .
15,808
private function innerStatementList ( StatementBlockNode $ parent , $ terminator ) { while ( $ this -> currentType !== NULL && $ this -> currentType !== $ terminator ) { $ this -> matchHidden ( $ parent ) ; $ parent -> addChild ( $ this -> innerStatement ( ) ) ; } }
Parse inner statement list .
15,809
private function innerStatementBlock ( ) { $ node = new StatementBlockNode ( ) ; $ this -> mustMatch ( '{' , $ node , NULL , FALSE , TRUE ) ; $ this -> innerStatementList ( $ node , '}' ) ; $ this -> mustMatch ( '}' , $ node , NULL , TRUE , TRUE ) ; return $ node ; }
Parse inner statement block .
15,810
private function innerStatement ( ) { switch ( $ this -> currentType ) { case T_HALT_COMPILER : throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , "__halt_compiler can only be used from the outermost scope" ) ; case T_ABSTRACT : case T_FINAL : case T_CLASS : return $ this -> classDeclaration ( ) ; case T_INTERFACE : return $ this -> interfaceDeclaration ( ) ; case T_TRAIT : return $ this -> traitDeclaration ( ) ; default : if ( $ this -> currentType === T_FUNCTION && $ this -> isLookAhead ( T_STRING , '&' ) ) { return $ this -> functionDeclaration ( ) ; } return $ this -> statement ( ) ; } }
Parse an inner statement .
15,811
private function name ( ) { $ node = new NameNode ( ) ; if ( $ this -> tryMatch ( T_NAMESPACE , $ node ) ) { $ this -> mustMatch ( T_NS_SEPARATOR , $ node ) ; } elseif ( $ this -> tryMatch ( T_NS_SEPARATOR , $ node ) ) { } $ this -> mustMatch ( T_STRING , $ node , NULL , TRUE ) ; while ( $ this -> tryMatch ( T_NS_SEPARATOR , $ node ) ) { $ this -> mustMatch ( T_STRING , $ node , NULL , TRUE ) ; } return $ node ; }
Parse a namespace path .
15,812
private function _namespace ( ) { $ node = new NamespaceNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ this -> mustMatch ( T_NAMESPACE , $ node ) ; if ( $ this -> currentType === T_STRING ) { $ name = $ this -> namespaceName ( ) ; $ node -> addChild ( $ name , 'name' ) ; } $ this -> matchHidden ( $ node ) ; $ body = new StatementBlockNode ( ) ; if ( $ this -> tryMatch ( '{' , $ body ) ) { $ this -> topStatementList ( $ body , '}' ) ; $ this -> mustMatch ( '}' , $ body ) ; $ node -> addChild ( $ body , 'body' ) ; } else { $ this -> endStatement ( $ node ) ; $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> namespaceBlock ( ) , 'body' ) ; } return $ node ; }
Parse a namespace declaration .
15,813
private function namespaceBlock ( ) { $ node = new StatementBlockNode ( ) ; $ this -> matchHidden ( $ node ) ; while ( $ this -> currentType !== NULL ) { if ( $ this -> currentType === T_NAMESPACE && ! $ this -> isLookAhead ( T_NS_SEPARATOR ) ) { break ; } $ node -> addChild ( $ this -> topStatement ( ) ) ; $ this -> matchHidden ( $ node ) ; } $ this -> matchHidden ( $ node ) ; return $ node ; }
Parse a list of top level namespace statements .
15,814
private function namespaceName ( ) { $ node = new NameNode ( ) ; $ this -> mustMatch ( T_STRING , $ node , NULL , TRUE ) ; while ( $ this -> tryMatch ( T_NS_SEPARATOR , $ node ) ) { $ this -> mustMatch ( T_STRING , $ node , NULL , TRUE ) ; } return $ node ; }
Parse a namespace name .
15,815
private function useBlock ( ) { $ node = new UseDeclarationBlockNode ( ) ; $ node -> addChild ( $ this -> _use ( ) ) ; while ( $ this -> currentType === T_USE ) { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> _use ( ) ) ; } return $ node ; }
Parse a block of use declaration statements .
15,816
private function _use ( ) { $ node = new UseDeclarationStatementNode ( ) ; $ this -> mustMatch ( T_USE , $ node ) ; $ this -> tryMatch ( T_FUNCTION , $ node , 'useFunction' ) || $ this -> tryMatch ( T_CONST , $ node , 'useConst' ) ; $ declarations = new CommaListNode ( ) ; do { $ declarations -> addChild ( $ this -> useDeclaration ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ declarations ) ) ; $ node -> addChild ( $ declarations , 'declarations' ) ; $ this -> endStatement ( $ node ) ; return $ node ; }
Parse a use declaration list .
15,817
private function useDeclaration ( ) { $ declaration = new UseDeclarationNode ( ) ; $ node = new NameNode ( ) ; $ this -> tryMatch ( T_NS_SEPARATOR , $ node ) ; $ this -> mustMatch ( T_STRING , $ node , NULL , TRUE ) -> getText ( ) ; while ( $ this -> tryMatch ( T_NS_SEPARATOR , $ node ) ) { $ this -> mustMatch ( T_STRING , $ node , NULL , TRUE ) -> getText ( ) ; } $ declaration -> addChild ( $ node , 'name' ) ; if ( $ this -> tryMatch ( T_AS , $ declaration ) ) { $ this -> mustMatch ( T_STRING , $ declaration , 'alias' , TRUE ) -> getText ( ) ; } return $ declaration ; }
Parse a use declaration .
15,818
private function classDeclaration ( ) { $ node = new ClassNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ this -> tryMatch ( T_ABSTRACT , $ node , 'abstract' ) || $ this -> tryMatch ( T_FINAL , $ node , 'final' ) ; $ this -> mustMatch ( T_CLASS , $ node ) ; $ name_node = new NameNode ( ) ; $ this -> mustMatch ( T_STRING , $ name_node , NULL , TRUE ) ; $ node -> addChild ( $ name_node , 'name' ) ; if ( $ this -> tryMatch ( T_EXTENDS , $ node ) ) { $ node -> addChild ( $ this -> name ( ) , 'extends' ) ; } if ( $ this -> tryMatch ( T_IMPLEMENTS , $ node ) ) { $ implements = new CommaListNode ( ) ; do { $ implements -> addChild ( $ this -> name ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ implements ) ) ; $ node -> addChild ( $ implements , 'implements' ) ; } $ this -> matchHidden ( $ node ) ; $ statement_block = new StatementBlockNode ( ) ; $ this -> mustMatch ( '{' , $ statement_block , NULL , FALSE , TRUE ) ; $ is_abstract = $ node -> getAbstract ( ) !== NULL ; while ( $ this -> currentType !== NULL && $ this -> currentType !== '}' ) { $ this -> matchHidden ( $ statement_block ) ; $ statement_block -> addChild ( $ this -> classStatement ( $ is_abstract ) ) ; } $ this -> mustMatch ( '}' , $ statement_block , NULL , TRUE , TRUE ) ; $ node -> addChild ( $ statement_block , 'statements' ) ; return $ node ; }
Parse a class declaration .
15,819
private function classMemberList ( $ doc_comment , ModifiersNode $ modifiers ) { if ( $ modifiers -> getAbstract ( ) ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , "members can not be declared abstract" ) ; } if ( $ modifiers -> getFinal ( ) ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , "members can not be declared final" ) ; } $ node = new ClassMemberListNode ( ) ; $ node -> mergeNode ( $ doc_comment ) ; $ node -> mergeNode ( $ modifiers ) ; $ members = new CommaListNode ( ) ; do { $ members -> addChild ( $ this -> classMember ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ members ) ) ; $ node -> addChild ( $ members , 'members' ) ; $ this -> endStatement ( $ node ) ; return $ node ; }
Parse a class member list .
15,820
private function classMember ( ) { $ node = new ClassMemberNode ( ) ; $ this -> mustMatch ( T_VARIABLE , $ node , 'name' , TRUE ) ; if ( $ this -> tryMatch ( '=' , $ node ) ) { $ node -> addChild ( $ this -> staticScalar ( ) , 'value' ) ; } return $ node ; }
Parse a class member .
15,821
private function classMethod ( $ doc_comment , ModifiersNode $ modifiers ) { $ node = new ClassMethodNode ( ) ; $ node -> mergeNode ( $ doc_comment ) ; $ node -> mergeNode ( $ modifiers ) ; $ this -> mustMatch ( T_FUNCTION , $ node ) ; $ this -> tryMatch ( '&' , $ node , 'reference' ) ; $ this -> mustMatch ( T_STRING , $ node , 'name' ) ; $ this -> parameterList ( $ node ) ; if ( $ modifiers -> getAbstract ( ) ) { $ this -> endStatement ( $ node ) ; return $ node ; } $ this -> matchHidden ( $ node ) ; $ this -> body ( $ node ) ; return $ node ; }
Parse a class method
15,822
private function traitUse ( ) { $ node = new TraitUseNode ( ) ; $ this -> mustMatch ( T_USE , $ node ) ; $ traits = new CommaListNode ( ) ; do { $ traits -> addChild ( $ this -> name ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ traits ) ) ; $ node -> addChild ( $ traits , 'traits' ) ; if ( $ this -> tryMatch ( '{' , $ node ) ) { $ adaptations = new StatementBlockNode ( ) ; while ( $ this -> currentType !== NULL && $ this -> currentType !== '}' ) { $ adaptations -> addChild ( $ this -> traitAdaptation ( ) ) ; $ this -> matchHidden ( $ adaptations ) ; } $ node -> addChild ( $ adaptations , 'adaptations' ) ; $ this -> mustMatch ( '}' , $ node , NULL , TRUE , TRUE ) ; return $ node ; } $ this -> endStatement ( $ node ) ; return $ node ; }
Parse a trait use statement .
15,823
private function traitAdaptation ( ) { $ qualified_name = $ this -> name ( ) ; if ( $ qualified_name -> childCount ( ) === 1 && $ this -> currentType !== T_DOUBLE_COLON ) { return $ this -> traitAlias ( $ qualified_name ) ; } $ node = new TraitMethodReferenceNode ( ) ; $ node -> addChild ( $ qualified_name , 'traitName' ) ; $ this -> mustMatch ( T_DOUBLE_COLON , $ node ) ; $ this -> mustMatch ( T_STRING , $ node , 'methodReference' , TRUE ) ; if ( $ this -> currentType === T_AS ) { return $ this -> traitAlias ( $ node ) ; } $ method_reference_node = $ node ; $ node = new TraitPrecedenceNode ( ) ; $ node -> addChild ( $ method_reference_node , 'traitMethodReference' ) ; $ this -> mustMatch ( T_INSTEADOF , $ node ) ; $ trait_names = new CommaListNode ( ) ; do { $ trait_names -> addChild ( $ this -> name ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ trait_names ) ) ; $ node -> addChild ( $ trait_names , 'traitNames' ) ; $ this -> endStatement ( $ node ) ; return $ node ; }
Parse a trait adaptation statement .
15,824
private function traitAlias ( $ trait_method_reference ) { $ node = new TraitAliasNode ( ) ; $ node -> addChild ( $ trait_method_reference , 'traitMethodReference' ) ; $ this -> mustMatch ( T_AS , $ node ) ; if ( $ trait_modifier = $ this -> tryMatchToken ( self :: $ visibilityTypes ) ) { $ node -> addChild ( $ trait_modifier , 'visibility' ) ; $ this -> tryMatch ( T_STRING , $ node , 'alias' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } $ this -> mustMatch ( T_STRING , $ node , 'alias' ) ; $ this -> endStatement ( $ node ) ; return $ node ; }
Parse a trait alias .
15,825
private function interfaceDeclaration ( ) { $ node = new InterfaceNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ this -> mustMatch ( T_INTERFACE , $ node ) ; $ name_node = new NameNode ( ) ; $ this -> mustMatch ( T_STRING , $ name_node , NULL , TRUE ) ; $ node -> addChild ( $ name_node , 'name' ) ; if ( $ this -> tryMatch ( T_EXTENDS , $ node ) ) { $ extends = new CommaListNode ( ) ; do { $ extends -> addChild ( $ this -> name ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ extends ) ) ; $ node -> addChild ( $ extends , 'extends' ) ; } $ this -> matchHidden ( $ node ) ; $ statement_block = new StatementBlockNode ( ) ; $ this -> mustMatch ( '{' , $ statement_block , NULL , FALSE , TRUE ) ; while ( $ this -> currentType !== NULL && $ this -> currentType !== '}' ) { $ this -> matchHidden ( $ statement_block ) ; if ( $ this -> currentType === T_CONST ) { $ statement_block -> addChild ( $ this -> _const ( ) ) ; } else { $ statement_block -> addChild ( $ this -> interfaceMethod ( ) ) ; } } $ this -> mustMatch ( '}' , $ statement_block , NULL , TRUE , TRUE ) ; $ node -> addChild ( $ statement_block , 'statements' ) ; return $ node ; }
Parse an interface declaration .
15,826
private function interfaceMethod ( ) { static $ visibility_keyword_types = [ T_PUBLIC , T_PROTECTED , T_PRIVATE ] ; $ node = new InterfaceMethodNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ is_static = $ this -> tryMatch ( T_STATIC , $ node , 'static' ) ; while ( in_array ( $ this -> currentType , $ visibility_keyword_types ) ) { if ( $ node -> getVisibility ( ) ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , "can only have one visibility modifier on interface method." ) ; } $ this -> mustMatch ( $ this -> currentType , $ node , 'visibility' ) ; } ! $ is_static && $ this -> tryMatch ( T_STATIC , $ node , 'static' ) ; $ this -> mustMatch ( T_FUNCTION , $ node ) ; $ this -> tryMatch ( '&' , $ node , 'reference' ) ; $ this -> mustMatch ( T_STRING , $ node , 'name' ) ; $ this -> parameterList ( $ node ) ; $ this -> endStatement ( $ node ) ; return $ node ; }
Parse an interface method declaration .
15,827
private function traitDeclaration ( ) { $ node = new TraitNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ this -> mustMatch ( T_TRAIT , $ node ) ; $ name_node = new NameNode ( ) ; $ this -> mustMatch ( T_STRING , $ name_node , NULL , TRUE ) ; $ node -> addChild ( $ name_node , 'name' ) ; if ( $ this -> currentType === T_EXTENDS ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'Traits can only be composed from other traits with the \'use\' keyword.' ) ; } if ( $ this -> currentType === T_IMPLEMENTS ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'Traits can not implement interfaces.' ) ; } $ this -> matchHidden ( $ node ) ; $ statement_block = new StatementBlockNode ( ) ; $ this -> mustMatch ( '{' , $ statement_block , NULL , FALSE , TRUE ) ; while ( $ this -> currentType !== NULL && $ this -> currentType !== '}' ) { $ this -> matchHidden ( $ statement_block ) ; $ statement_block -> addChild ( $ this -> classStatement ( TRUE ) ) ; } $ this -> mustMatch ( '}' , $ statement_block , NULL , TRUE , TRUE ) ; $ node -> addChild ( $ statement_block , 'statements' ) ; return $ node ; }
Parse a trait declaration .
15,828
private function nextToken ( $ capture_doc_comment = FALSE ) { $ this -> iterator -> next ( ) ; $ capture_doc_comment ? $ this -> skipHiddenCaptureDocComment ( ) : $ this -> skipHidden ( ) ; $ this -> current = $ this -> iterator -> current ( ) ; if ( $ this -> current ) { $ this -> currentType = $ this -> current -> getType ( ) ; } else { $ this -> currentType = NULL ; } }
Move iterator to next non hidden token .
15,829
private function isLookAhead ( $ expected_type , $ skip_type = NULL ) { $ token = NULL ; for ( $ offset = 1 ; ; $ offset ++ ) { $ token = $ this -> iterator -> peek ( $ offset ) ; if ( $ token === NULL ) { return FALSE ; } if ( ! ( $ token instanceof HiddenNode ) && $ token -> getType ( ) !== $ skip_type ) { return $ expected_type === $ token -> getType ( ) ; } } return FALSE ; }
Look ahead from current position at tokens and check if the token at offset is of an expected type where the offset ignores hidden tokens .
15,830
public function update ( ContentUpdateEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( null !== $ content = ContentQuery :: create ( ) -> findPk ( $ event -> getContentId ( ) ) ) { $ con = Propel :: getWriteConnection ( ContentTableMap :: DATABASE_NAME ) ; $ con -> beginTransaction ( ) ; $ content -> setDispatcher ( $ dispatcher ) ; try { $ content -> setVisible ( $ event -> getVisible ( ) ) -> setLocale ( $ event -> getLocale ( ) ) -> setTitle ( $ event -> getTitle ( ) ) -> setDescription ( $ event -> getDescription ( ) ) -> setChapo ( $ event -> getChapo ( ) ) -> setPostscriptum ( $ event -> getPostscriptum ( ) ) -> save ( $ con ) ; $ content -> setDefaultFolder ( $ event -> getDefaultFolder ( ) ) ; $ event -> setContent ( $ content ) ; $ con -> commit ( ) ; } catch ( PropelException $ e ) { $ con -> rollBack ( ) ; throw $ e ; } } }
process update content
15,831
public function updateSeo ( UpdateSeoEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { return $ this -> genericUpdateSeo ( ContentQuery :: create ( ) , $ event , $ dispatcher ) ; }
Change Content SEO
15,832
public function viewCheck ( ViewCheckEvent $ event , $ eventName , EventDispatcherInterface $ dispatcher ) { if ( $ event -> getView ( ) == 'content' ) { $ content = ContentQuery :: create ( ) -> filterById ( $ event -> getViewId ( ) ) -> filterByVisible ( 1 ) -> count ( ) ; if ( $ content == 0 ) { $ dispatcher -> dispatch ( TheliaEvents :: VIEW_CONTENT_ID_NOT_VISIBLE , $ event ) ; } } }
Check if is a content view and if content_id is visible
15,833
protected function initParser ( ) { $ this -> parser -> unregisterPlugin ( 'function' , 'intl' ) ; $ this -> parser -> registerPlugin ( 'function' , 'intl' , [ $ this , 'translate' ] ) ; $ this -> parser -> assign ( "locales" , $ this -> locales ) ; }
Initialize the smarty parser .
15,834
public function translate ( $ params , $ smarty ) { $ translation = '' ; if ( empty ( $ params [ "l" ] ) ) { throw new RuntimeException ( 'Translation Error. Key is empty.' ) ; } elseif ( empty ( $ params [ "locale" ] ) ) { throw new RuntimeException ( 'Translation Error. Locale is empty.' ) ; } else { $ inString = ( 0 !== \ intval ( $ params [ "in_string" ] ) ) ; $ useDefault = ( 0 !== \ intval ( $ params [ "use_default" ] ) ) ; $ translation = $ this -> translator -> trans ( $ params [ "l" ] , [ ] , 'install' , $ params [ "locale" ] , $ useDefault ) ; if ( empty ( $ translation ) ) { $ translation = ( $ inString ) ? '' : "NULL" ; } else { $ translation = $ this -> con -> quote ( $ translation ) ; if ( $ inString ) { $ translation = substr ( $ translation , 1 , - 1 ) ; } } } return $ translation ; }
Smarty function that replace the classic intl function .
15,835
public function importChangePosition ( UpdatePositionEvent $ updatePositionEvent , $ eventName , EventDispatcherInterface $ dispatcher ) { $ this -> handler -> getImport ( $ updatePositionEvent -> getObjectId ( ) , true ) ; $ this -> genericUpdatePosition ( new ImportQuery , $ updatePositionEvent , $ dispatcher ) ; }
Handle import change position event
15,836
public function importCategoryChangePosition ( UpdatePositionEvent $ updatePositionEvent , $ eventName , EventDispatcherInterface $ dispatcher ) { $ this -> handler -> getCategory ( $ updatePositionEvent -> getObjectId ( ) , true ) ; $ this -> genericUpdatePosition ( new ImportCategoryQuery , $ updatePositionEvent , $ dispatcher ) ; }
Handle import category change position event
15,837
protected function checkModuleArgument ( $ paramValue ) { if ( ! preg_match ( '#^([a-z0-9]+):([\+-]?[0-9]+|up|down)$#i' , $ paramValue , $ matches ) ) { throw new \ InvalidArgumentException ( 'Arguments must be in format moduleName:[+|-]position where position is an integer or up or down.' ) ; } $ this -> moduleQuery -> clear ( ) ; $ module = $ this -> moduleQuery -> findOneByCode ( $ matches [ 1 ] ) ; if ( $ module === null ) { throw new \ RuntimeException ( sprintf ( '%s module does not exists. Try to refresh first.' , $ matches [ 1 ] ) ) ; } $ this -> modulesList [ ] = $ matches [ 1 ] ; $ this -> positionsList [ ] = $ matches [ 2 ] ; }
Check a module argument format
15,838
protected function checkPositions ( InputInterface $ input , OutputInterface $ output , & $ isAbsolute = false ) { $ isRelative = false ; foreach ( array_count_values ( $ this -> positionsList ) as $ value => $ count ) { if ( \ is_int ( $ value ) && $ value [ 0 ] !== '+' && $ value [ 0 ] !== '-' ) { $ isAbsolute = true ; if ( $ count > 1 ) { throw new \ InvalidArgumentException ( 'Two (or more) absolute positions are identical.' ) ; } } else { $ isRelative = true ; } } if ( $ isAbsolute && $ isRelative ) { $ formatter = $ this -> getHelper ( 'formatter' ) ; $ formattedBlock = $ formatter -> formatBlock ( 'Mix absolute and relative positions may produce unexpected results !' , 'bg=yellow;fg=black' , true ) ; $ output -> writeln ( $ formattedBlock ) ; $ helper = $ this -> getHelper ( 'question' ) ; $ question = new ConfirmationQuestion ( '<question>Do you want to continue ? y/[n]<question>' , false ) ; return $ helper -> ask ( $ input , $ output , $ question ) ; } return true ; }
Check positions consistency
15,839
public function importsClass ( $ class_name = NULL ) { if ( $ this -> useFunction || $ this -> useConst ) { return FALSE ; } if ( $ class_name ) { foreach ( $ this -> getDeclarations ( ) as $ declaration ) { if ( $ declaration -> getName ( ) -> getPath ( ) === $ class_name ) { return TRUE ; } } return FALSE ; } else { return TRUE ; } }
Test whether use declaration imports a class .
15,840
public function importsFunction ( $ function_name = NULL ) { if ( ! $ this -> useFunction ) { return FALSE ; } if ( $ function_name ) { foreach ( $ this -> getDeclarations ( ) as $ declaration ) { if ( $ declaration -> getName ( ) -> getPath ( ) === $ function_name ) { return TRUE ; } } return FALSE ; } else { return TRUE ; } }
Test whether use declaration imports a function .
15,841
public function importsConst ( $ const_name = NULL ) { if ( ! $ this -> useConst ) { return FALSE ; } if ( $ const_name ) { foreach ( $ this -> getDeclarations ( ) as $ declaration ) { if ( $ declaration -> getName ( ) -> getPath ( ) === $ const_name ) { return TRUE ; } } return FALSE ; } else { return TRUE ; } }
Test whether use declaration imports a constant .
15,842
public function getDeliveryAddress ( ) { try { return AddressQuery :: create ( ) -> findPk ( $ this -> getRequest ( ) -> getSession ( ) -> getOrder ( ) -> getChoosenDeliveryAddress ( ) ) ; } catch ( \ Exception $ ex ) { throw new \ LogicException ( "Failed to get delivery address (" . $ ex -> getMessage ( ) . ")" ) ; } }
Return an Address a CouponManager can process
15,843
public function getCartTotalPrice ( $ withItemsInPromo = true ) { $ total = 0 ; $ cartItems = $ this -> getRequest ( ) -> getSession ( ) -> getSessionCart ( $ this -> getDispatcher ( ) ) -> getCartItems ( ) ; foreach ( $ cartItems as $ cartItem ) { if ( $ withItemsInPromo || ! $ cartItem -> getPromo ( ) ) { $ total += $ cartItem -> getRealPrice ( ) * $ cartItem -> getQuantity ( ) ; } } return $ total ; }
Return Products total price
15,844
public function getCurrentCoupons ( ) { $ couponCodes = $ this -> getRequest ( ) -> getSession ( ) -> getConsumedCoupons ( ) ; if ( null === $ couponCodes ) { return array ( ) ; } $ couponFactory = $ this -> container -> get ( 'thelia.coupon.factory' ) ; $ coupons = [ ] ; foreach ( $ couponCodes as $ couponCode ) { try { if ( false !== $ couponInterface = $ couponFactory -> buildCouponFromCode ( $ couponCode ) ) { $ coupons [ ] = $ couponInterface ; } } catch ( \ Exception $ ex ) { Tlog :: getInstance ( ) -> warning ( sprintf ( "Coupon %s ignored, exception occurred: %s" , $ couponCode , $ ex -> getMessage ( ) ) ) ; } } return $ coupons ; }
Return all Coupon given during the Checkout
15,845
public function getParser ( ) { if ( $ this -> parser == null ) { $ this -> parser = $ this -> container -> get ( 'thelia.parser' ) ; $ this -> parser -> setTemplateDefinition ( $ this -> parser -> getTemplateHelper ( ) -> getActiveAdminTemplate ( ) ) ; } return $ this -> parser ; }
Return platform Parser
15,846
public function pushCouponInSession ( $ couponCode ) { $ consumedCoupons = $ this -> getRequest ( ) -> getSession ( ) -> getConsumedCoupons ( ) ; if ( ! isset ( $ consumedCoupons ) || ! $ consumedCoupons ) { $ consumedCoupons = array ( ) ; } if ( ! isset ( $ consumedCoupons [ $ couponCode ] ) ) { $ consumedCoupons [ $ couponCode ] = $ couponCode ; $ this -> getRequest ( ) -> getSession ( ) -> setConsumedCoupons ( $ consumedCoupons ) ; } }
Add a coupon in session
15,847
public function drawBaseBackOfficeInputs ( $ templateName , $ otherFields ) { return $ this -> facade -> getParser ( ) -> render ( $ templateName , array_merge ( $ otherFields , [ 'attribute_field_name' => $ this -> makeCouponFieldName ( self :: ATTRIBUTE ) , 'attribute_value' => $ this -> attribute , 'attribute_av_field_name' => $ this -> makeCouponFieldName ( self :: ATTRIBUTES_AV_LIST ) , 'attribute_av_values' => $ this -> attributeAvList ] ) ) ; }
Renders the template which implements coupon specific user - input using the provided template file and a list of specific input fields .
15,848
protected function addSeoFields ( $ exclude = array ( ) ) { if ( ! \ in_array ( 'url' , $ exclude ) ) { $ this -> formBuilder -> add ( 'url' , 'text' , [ 'required' => false , 'label' => Translator :: getInstance ( ) -> trans ( 'Rewriten URL' ) , 'label_attr' => [ 'for' => 'rewriten_url_field' , ] , 'attr' => [ 'placeholder' => Translator :: getInstance ( ) -> trans ( 'Use the keyword phrase in your URL.' ) , ] ] ) ; } if ( ! \ in_array ( 'meta_title' , $ exclude ) ) { $ this -> formBuilder -> add ( 'meta_title' , 'text' , [ 'required' => false , 'label' => Translator :: getInstance ( ) -> trans ( 'Page Title' ) , 'label_attr' => [ 'for' => 'meta_title' , 'help' => Translator :: getInstance ( ) -> trans ( 'The HTML TITLE element is the most important element on your web page.' ) , ] , 'attr' => [ 'placeholder' => Translator :: getInstance ( ) -> trans ( 'Make sure that your title is clear, and contains many of the keywords within the page itself.' ) , ] ] ) ; } if ( ! \ in_array ( 'meta_description' , $ exclude ) ) { $ this -> formBuilder -> add ( 'meta_description' , 'textarea' , [ 'required' => false , 'label' => Translator :: getInstance ( ) -> trans ( 'Meta Description' ) , 'label_attr' => [ 'for' => 'meta_description' , 'help' => Translator :: getInstance ( ) -> trans ( 'Keep the most important part of your description in the first 150-160 characters.' ) , ] , 'attr' => [ 'rows' => 6 , 'placeholder' => Translator :: getInstance ( ) -> trans ( 'Make sure it uses keywords found within the page itself.' ) , ] ] ) ; } if ( ! \ in_array ( 'meta_keywords' , $ exclude ) ) { $ this -> formBuilder -> add ( 'meta_keywords' , 'textarea' , [ 'required' => false , 'label' => Translator :: getInstance ( ) -> trans ( 'Meta Keywords' ) , 'label_attr' => [ 'for' => 'meta_keywords' , 'help' => Translator :: getInstance ( ) -> trans ( 'You don\'t need to use commas or other punctuations.' ) , ] , 'attr' => [ 'rows' => 3 , 'placeholder' => Translator :: getInstance ( ) -> trans ( 'Don\'t repeat keywords over and over in a row. Rather, put in keyword phrases.' ) , ] ] ) ; } }
Add seo meta title meta description and meta keywords fields
15,849
protected function getCurrentListOrder ( $ update_session = true ) { return $ this -> getListOrderFromSession ( $ this -> objectName , $ this -> orderRequestParameterName , $ this -> defaultListOrder ) ; }
Return the current list order identifier updating it in the same time .
15,850
public function renderToolStyleHeaderAction ( ) { $ melisTool = $ this -> getServiceLocator ( ) -> get ( 'MelisCoreTool' ) ; $ melisTool -> setMelisToolKey ( 'meliscms' , 'meliscms_tool_templates' ) ; $ melisKey = $ this -> params ( ) -> fromRoute ( 'melisKey' , '' ) ; $ zoneConfig = $ this -> params ( ) -> fromRoute ( 'zoneconfig' , array ( ) ) ; $ view = new ViewModel ( ) ; $ view -> melisKey = $ melisKey ; $ view -> title = $ melisTool -> getTitle ( ) ; ; return $ view ; }
This is where you place your buttons for the tools
15,851
public function getStyleByPageId ( $ pageId ) { $ style = "" ; $ pageStyle = $ this -> getServiceLocator ( ) -> get ( 'MelisPageStyle' ) ; if ( $ pageStyle ) { $ dataStyle = $ pageStyle -> getStyleByPageId ( $ pageId ) ; $ style = $ dataStyle ; } return $ style ; }
Return style of a page
15,852
public function insertTemplate ( HookRenderEvent $ event , $ code ) { if ( array_key_exists ( $ code , $ this -> templates ) ) { $ templates = explode ( ';' , $ this -> templates [ $ code ] ) ; $ allArguments = $ event -> getTemplateVars ( ) + $ event -> getArguments ( ) ; foreach ( $ templates as $ template ) { list ( $ type , $ filepath ) = $ this -> getTemplateParams ( $ template ) ; if ( "render" === $ type ) { $ event -> add ( $ this -> render ( $ filepath , $ allArguments ) ) ; continue ; } if ( "dump" === $ type ) { $ event -> add ( $ this -> render ( $ filepath ) ) ; continue ; } if ( "css" === $ type ) { $ event -> add ( $ this -> addCSS ( $ filepath ) ) ; continue ; } if ( "js" === $ type ) { $ event -> add ( $ this -> addJS ( $ filepath ) ) ; continue ; } if ( method_exists ( $ this , $ type ) ) { $ this -> { $ type } ( $ filepath , $ allArguments ) ; } } } }
This function is called when hook uses the automatic insert template .
15,853
public function render ( $ templateName , array $ parameters = array ( ) ) { $ templateDir = $ this -> assetsResolver -> resolveAssetSourcePath ( $ this -> module -> getCode ( ) , false , $ templateName , $ this -> parser ) ; if ( null !== $ templateDir ) { $ content = $ this -> parser -> render ( $ templateDir . DS . $ templateName , $ parameters ) ; } else { $ content = sprintf ( "ERR: Unknown template %s for module %s" , $ templateName , $ this -> module -> getCode ( ) ) ; } return $ content ; }
helper function allowing you to render a template using a template engine
15,854
public function dump ( $ fileName ) { $ fileDir = $ this -> assetsResolver -> resolveAssetSourcePath ( $ this -> module -> getCode ( ) , false , $ fileName , $ this -> parser ) ; if ( null !== $ fileDir ) { $ content = file_get_contents ( $ fileDir . DS . $ fileName ) ; if ( false === $ content ) { $ content = "" ; } } else { $ content = sprintf ( "ERR: Unknown file %s for module %s" , $ fileName , $ this -> module -> getCode ( ) ) ; } return $ content ; }
helper function allowing you to get the content of a file
15,855
public function addCSS ( $ fileName , $ attributes = [ ] , $ filters = [ ] ) { $ tag = "" ; $ url = $ this -> assetsResolver -> resolveAssetURL ( $ this -> module -> getCode ( ) , $ fileName , "css" , $ this -> parser , $ filters ) ; if ( "" !== $ url ) { $ tags = array ( ) ; $ tags [ ] = '<link rel="stylesheet" type="text/css" ' ; $ tags [ ] = ' href="' . $ url . '" ' ; foreach ( $ attributes as $ name => $ val ) { if ( \ is_string ( $ name ) && ! \ in_array ( $ name , [ "href" , "rel" , "type" ] ) ) { $ tags [ ] = $ name . '="' . $ val . '" ' ; } } $ tags [ ] = "/>" ; $ tag = implode ( $ tags ) ; } return $ tag ; }
helper function allowing you to generate the HTML link tag
15,856
protected function getRequest ( ) { if ( null === $ this -> request ) { $ this -> request = $ this -> getParser ( ) -> getRequest ( ) ; } return $ this -> request ; }
get the request
15,857
protected function getSession ( ) { if ( null === $ this -> session ) { if ( null !== $ this -> getRequest ( ) ) { $ this -> session = $ this -> request -> getSession ( ) ; } } return $ this -> session ; }
get the session
15,858
protected function getView ( ) { $ ret = "" ; if ( null !== $ this -> getRequest ( ) ) { $ ret = $ this -> getRequest ( ) -> attributes -> get ( "_view" , "" ) ; } return $ ret ; }
Get the view argument for the request .
15,859
protected function getCart ( ) { if ( null === $ this -> cart ) { $ this -> cart = $ this -> getSession ( ) ? $ this -> getSession ( ) -> getSessionCart ( $ this -> dispatcher ) : null ; } return $ this -> cart ; }
Get the cart from the session
15,860
protected function getOrder ( ) { if ( null === $ this -> order ) { $ this -> order = $ this -> getSession ( ) ? $ this -> getSession ( ) -> getOrder ( ) : null ; } return $ this -> order ; }
Get the order from the session
15,861
protected function getCurrency ( ) { if ( null === $ this -> currency ) { $ this -> currency = $ this -> getSession ( ) ? $ this -> getSession ( ) -> getCurrency ( true ) : Currency :: getDefaultCurrency ( ) ; } return $ this -> currency ; }
Get the current currency used or if not present the default currency for the shop
15,862
protected function getCustomer ( ) { if ( null === $ this -> customer ) { $ this -> customer = $ this -> getSession ( ) ? $ this -> getSession ( ) -> getCustomerUser ( ) : null ; } return $ this -> customer ; }
Get the current customer logged in . If no customer is logged return null
15,863
protected function getLang ( ) { if ( null === $ this -> lang ) { $ this -> lang = $ this -> getSession ( ) ? $ this -> getSession ( ) -> getLang ( true ) : $ this -> lang = Lang :: getDefaultLanguage ( ) ; } return $ this -> lang ; }
Get the current lang used or if not present the default lang for the shop
15,864
public function addTemplate ( $ hookCode , $ value ) { if ( array_key_exists ( $ hookCode , $ this -> templates ) ) { throw new \ InvalidArgumentException ( sprintf ( "The hook '%s' is already used in this class." , $ hookCode ) ) ; } $ this -> templates [ $ hookCode ] = $ value ; }
Add a new template for automatic render
15,865
protected function addHooksMethodCall ( ContainerBuilder $ container , Definition $ definition ) { $ moduleHooks = ModuleHookQuery :: create ( ) -> orderByHookId ( ) -> orderByPosition ( ) -> orderById ( ) -> find ( ) ; $ modulePosition = 0 ; $ hookId = 0 ; foreach ( $ moduleHooks as $ moduleHook ) { if ( ! $ container -> hasDefinition ( $ moduleHook -> getClassname ( ) ) ) { continue ; } $ hook = $ moduleHook -> getHook ( ) ; if ( ! $ this -> isValidHookMethod ( $ container -> getDefinition ( $ moduleHook -> getClassname ( ) ) -> getClass ( ) , $ moduleHook -> getMethod ( ) , $ hook -> getBlock ( ) , true ) ) { $ moduleHook -> delete ( ) ; continue ; } if ( $ hookId !== $ moduleHook -> getHookId ( ) ) { $ hookId = $ moduleHook -> getHookId ( ) ; $ modulePosition = 1 ; } else { $ modulePosition ++ ; } if ( $ moduleHook -> getPosition ( ) === ModuleHook :: MAX_POSITION ) { $ moduleHook -> setPosition ( $ modulePosition ) -> save ( ) ; } else { $ modulePosition = $ moduleHook -> getPosition ( ) ; } if ( $ moduleHook -> getActive ( ) && $ moduleHook -> getModuleActive ( ) && $ moduleHook -> getHookActive ( ) ) { $ eventName = sprintf ( 'hook.%s.%s' , $ hook -> getType ( ) , $ hook -> getCode ( ) ) ; if ( $ hook -> getByModule ( ) ) { $ eventName .= '.' . $ moduleHook -> getModuleId ( ) ; } $ definition -> addMethodCall ( 'addListenerService' , array ( $ eventName , array ( $ moduleHook -> getClassname ( ) , $ moduleHook -> getMethod ( ) ) , ModuleHook :: MAX_POSITION - $ moduleHook -> getPosition ( ) ) ) ; if ( $ moduleHook -> getTemplates ( ) ) { if ( $ container -> hasDefinition ( $ moduleHook -> getClassname ( ) ) ) { $ moduleHookEventName = 'hook.' . $ hook -> getType ( ) . '.' . $ hook -> getCode ( ) ; if ( true === $ moduleHook -> getHook ( ) -> getByModule ( ) ) { $ moduleHookEventName .= '.' . $ moduleHook -> getModuleId ( ) ; } $ container -> getDefinition ( $ moduleHook -> getClassname ( ) ) -> addMethodCall ( 'addTemplate' , array ( $ moduleHookEventName , $ moduleHook -> getTemplates ( ) ) ) ; } } } } }
First the new hooks are positioning next to the last module hook . Next if the module hook and module hook is active a new listener is added to the service definition .
15,866
protected function getHookType ( $ name ) { $ type = TemplateDefinition :: FRONT_OFFICE ; if ( null !== $ name && \ is_string ( $ name ) ) { $ name = preg_replace ( "[^a-z]" , "" , strtolower ( trim ( $ name ) ) ) ; if ( \ in_array ( $ name , array ( 'bo' , 'back' , 'backoffice' ) ) ) { $ type = TemplateDefinition :: BACK_OFFICE ; } elseif ( \ in_array ( $ name , array ( 'email' ) ) ) { $ type = TemplateDefinition :: EMAIL ; } elseif ( \ in_array ( $ name , array ( 'pdf' ) ) ) { $ type = TemplateDefinition :: PDF ; } } return $ type ; }
get the hook type according to the type attribute of the hook tag
15,867
protected function isValidHookMethod ( $ className , $ methodName , $ block , $ failSafe = false ) { try { $ method = new ReflectionMethod ( $ className , $ methodName ) ; $ parameters = $ method -> getParameters ( ) ; $ eventType = ( $ block ) ? HookDefinition :: RENDER_BLOCK_EVENT : HookDefinition :: RENDER_FUNCTION_EVENT ; if ( ! ( $ parameters [ 0 ] -> getClass ( ) -> getName ( ) == $ eventType || is_subclass_of ( $ parameters [ 0 ] -> getClass ( ) -> getName ( ) , $ eventType ) ) ) { $ this -> logAlertMessage ( sprintf ( "Method %s should use an event of type %s. found: %s" , $ methodName , $ eventType , $ parameters [ 0 ] -> getClass ( ) -> getName ( ) ) ) ; return false ; } } catch ( ReflectionException $ ex ) { $ this -> logAlertMessage ( sprintf ( "Method %s does not exist in %s : %s" , $ methodName , $ className , $ ex ) , $ failSafe ) ; return false ; } return true ; }
Test if the method that will handled the hook is valid
15,868
protected function genericUpdatePosition ( ModelCriteria $ query , UpdatePositionEvent $ event , EventDispatcherInterface $ dispatcher = null ) { if ( null !== $ object = $ query -> findPk ( $ event -> getObjectId ( ) ) ) { if ( ! isset ( class_uses ( $ object ) [ 'Thelia\Model\Tools\PositionManagementTrait' ] ) ) { throw new \ InvalidArgumentException ( "Your model does not implement the PositionManagementTrait trait" ) ; } $ object -> setDispatcher ( $ dispatcher !== null ? $ dispatcher : $ event -> getDispatcher ( ) ) ; $ mode = $ event -> getMode ( ) ; if ( $ mode == UpdatePositionEvent :: POSITION_ABSOLUTE ) { $ object -> changeAbsolutePosition ( $ event -> getPosition ( ) ) ; } elseif ( $ mode == UpdatePositionEvent :: POSITION_UP ) { $ object -> movePositionUp ( ) ; } elseif ( $ mode == UpdatePositionEvent :: POSITION_DOWN ) { $ object -> movePositionDown ( ) ; } } }
Changes object position selecting absolute ou relative change .
15,869
protected function genericUpdateSeo ( ModelCriteria $ query , UpdateSeoEvent $ event , EventDispatcherInterface $ dispatcher = null ) { if ( null !== $ object = $ query -> findPk ( $ event -> getObjectId ( ) ) ) { $ object -> setDispatcher ( $ dispatcher !== null ? $ dispatcher : $ event -> getDispatcher ( ) ) -> setLocale ( $ event -> getLocale ( ) ) -> setMetaTitle ( $ event -> getMetaTitle ( ) ) -> setMetaDescription ( $ event -> getMetaDescription ( ) ) -> setMetaKeywords ( $ event -> getMetaKeywords ( ) ) -> save ( ) ; try { $ object -> setRewrittenUrl ( $ event -> getLocale ( ) , $ event -> getUrl ( ) ) ; } catch ( UrlRewritingException $ e ) { throw new FormValidationException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } $ event -> setObject ( $ object ) ; } return $ object ; }
Changes SEO Fields for an object .
15,870
public function genericToggleVisibility ( ModelCriteria $ query , ToggleVisibilityEvent $ event , EventDispatcherInterface $ dispatcher = null ) { if ( null !== $ object = $ query -> findPk ( $ event -> getObjectId ( ) ) ) { $ newVisibility = ! $ object -> getVisible ( ) ; $ object -> setDispatcher ( $ dispatcher !== null ? $ dispatcher : $ event -> getDispatcher ( ) ) -> setVisible ( $ newVisibility ) -> save ( ) ; $ event -> setObject ( $ object ) ; } return $ object ; }
Toggle visibility for an object
15,871
protected function schemaValidate ( \ DOMDocument $ dom , \ SplFileInfo $ xsdFile ) { $ errorMessages = [ ] ; try { libxml_use_internal_errors ( true ) ; if ( ! $ dom -> schemaValidate ( $ xsdFile -> getRealPath ( ) ) ) { $ errors = libxml_get_errors ( ) ; foreach ( $ errors as $ error ) { $ errorMessages [ ] = sprintf ( 'XML error "%s" [%d] (Code %d) in %s on line %d column %d' . "\n" , $ error -> message , $ error -> level , $ error -> code , $ error -> file , $ error -> line , $ error -> column ) ; } libxml_clear_errors ( ) ; } libxml_use_internal_errors ( false ) ; } catch ( \ Exception $ ex ) { libxml_use_internal_errors ( false ) ; } return $ errorMessages ; }
Validate the schema of a XML file with a given xsd file
15,872
public function onKernelView ( GetResponseForControllerResultEvent $ event ) { $ parser = $ this -> container -> get ( 'thelia.parser' ) ; $ templateHelper = $ this -> container -> get ( 'thelia.template_helper' ) ; $ parser -> setTemplateDefinition ( $ templateHelper -> getActiveFrontTemplate ( ) , true ) ; $ request = $ this -> container -> get ( 'request_stack' ) -> getCurrentRequest ( ) ; $ response = null ; try { $ view = $ request -> attributes -> get ( '_view' ) ; $ viewId = $ request -> attributes -> get ( $ view . '_id' ) ; $ this -> eventDispatcher -> dispatch ( TheliaEvents :: VIEW_CHECK , new ViewCheckEvent ( $ view , $ viewId ) ) ; $ content = $ parser -> render ( $ view . '.html' ) ; if ( $ content instanceof Response ) { $ response = $ content ; } else { $ response = new Response ( $ content , $ parser -> getStatus ( ) ? : 200 ) ; } } catch ( ResourceNotFoundException $ e ) { throw new NotFoundHttpException ( ) ; } catch ( OrderException $ e ) { switch ( $ e -> getCode ( ) ) { case OrderException :: CART_EMPTY : $ response = RedirectResponse :: create ( $ this -> container -> get ( 'router.chainRequest' ) -> generate ( $ e -> cartRoute , $ e -> arguments , Router :: ABSOLUTE_URL ) ) ; break ; case OrderException :: UNDEFINED_DELIVERY : $ response = RedirectResponse :: create ( $ this -> container -> get ( 'router.chainRequest' ) -> generate ( $ e -> orderDeliveryRoute , $ e -> arguments , Router :: ABSOLUTE_URL ) ) ; break ; } if ( null === $ response ) { throw $ e ; } } $ event -> setResponse ( $ response ) ; }
Launch the parser defined on the constructor and get the result .
15,873
public function enterNode ( Node $ node ) { if ( $ node instanceof ConstFetch || $ node instanceof FuncCall ) { $ node -> name = null ; } if ( $ node instanceof FullyQualified ) { $ this -> names [ ] = $ node -> toString ( ) ; } return $ node ; }
Enter the node and record the name .
15,874
public function getMethodNames ( ) { return array_map ( function ( ClassMethodNode $ node ) { return $ node -> getName ( ) -> getText ( ) ; } , $ this -> getMethods ( ) -> toArray ( ) ) ; }
Returns the names of all class methods regardless of visibility .
15,875
public function getProperty ( $ name ) { $ name = ltrim ( $ name , '$' ) ; $ properties = $ this -> getProperties ( ) -> filter ( function ( ClassMemberNode $ property ) use ( $ name ) { return ltrim ( $ property -> getName ( ) , '$' ) === $ name ; } ) ; return $ properties -> isEmpty ( ) ? NULL : $ properties [ 0 ] ; }
Returns a property by name if it exists .
15,876
public function createProperty ( $ name , ExpressionNode $ value = NULL , $ visibility = 'public' ) { return $ this -> appendProperty ( ClassMemberNode :: create ( $ name , $ value , $ visibility ) ) ; }
Creates a new property in this class .
15,877
public function appendProperty ( $ property ) { if ( is_string ( $ property ) ) { $ property = ClassMemberListNode :: create ( $ property ) ; } $ properties = $ this -> statements -> children ( Filter :: isInstanceOf ( '\Pharborist\ClassMemberListNode' ) ) ; if ( $ properties -> count ( ) === 0 ) { $ this -> statements -> firstChild ( ) -> after ( $ property ) ; } else { $ properties -> last ( ) -> after ( $ property ) ; } FormatterFactory :: format ( $ this ) ; return $ this ; }
Add property to class .
15,878
public static function create ( $ comment ) { $ comment = trim ( $ comment ) ; $ lines = array_map ( 'trim' , explode ( "\n" , $ comment ) ) ; $ text = "/**\n" ; foreach ( $ lines as $ i => $ line ) { $ text .= ' * ' . $ line . "\n" ; } $ text .= ' */' ; return new DocCommentNode ( T_DOC_COMMENT , $ text ) ; }
Creates a PHPDoc comment .
15,879
public function setIndent ( $ indent ) { $ lines = explode ( "\n" , $ this -> text ) ; if ( count ( $ lines ) === 1 ) { return $ this ; } $ comment = '' ; $ last_index = count ( $ lines ) - 1 ; foreach ( $ lines as $ i => $ line ) { if ( $ i === 0 ) { $ comment .= trim ( $ line ) . "\n" ; } elseif ( $ i === $ last_index ) { $ comment .= $ indent . ' ' . trim ( $ line ) ; } else { $ comment .= $ indent . ' ' . trim ( $ line ) . "\n" ; } } $ this -> setText ( $ comment ) ; return $ this ; }
Set indent for document comment .
15,880
public function getDocBlock ( ) { if ( $ this -> docBlock === NULL ) { $ namespace = '\\' ; $ aliases = array ( ) ; $ namespace_node = $ this -> closest ( Filter :: isInstanceOf ( '\Pharborist\Namespaces\NamespaceNode' ) ) ; if ( $ namespace_node !== NULL ) { $ namespace = $ namespace_node -> getName ( ) ? $ namespace_node -> getName ( ) -> getAbsolutePath ( ) : '' ; $ aliases = $ namespace_node -> getClassAliases ( ) ; } else { $ root_node = $ this -> closest ( Filter :: isInstanceOf ( '\Pharborist\RootNode' ) ) ; if ( $ root_node !== NULL ) { $ aliases = $ root_node -> getClassAliases ( ) ; } } $ context = new DocBlock \ Context ( $ namespace , $ aliases ) ; $ this -> docBlock = new DocBlock ( $ this -> text , $ context ) ; } return $ this -> docBlock ; }
Return the parsed doc comment .
15,881
public function getParametersByName ( ) { $ param_tags = $ this -> getDocBlock ( ) -> getTagsByName ( 'param' ) ; $ parameters = array ( ) ; foreach ( $ param_tags as $ param_tag ) { $ name = ltrim ( $ param_tag -> getVariableName ( ) , '$' ) ; $ parameters [ $ name ] = $ param_tag ; } return $ parameters ; }
Get the parameter tags by name .
15,882
public function getParameter ( $ parameterName ) { $ parameterName = ltrim ( $ parameterName , '$' ) ; $ param_tags = $ this -> getDocBlock ( ) -> getTagsByName ( 'param' ) ; foreach ( $ param_tags as $ param_tag ) { if ( ltrim ( $ param_tag -> getVariableName ( ) , '$' ) === $ parameterName ) { return $ param_tag ; } } return NULL ; }
Get a parameter tag .
15,883
public function make ( array $ config ) { Arr :: requires ( $ config , [ 'token' ] ) ; $ client = new Client ( ) ; return new PagerdutyGateway ( $ client , $ config ) ; }
Create a new pagerduty gateway instance .
15,884
public function fetch ( array $ options = [ ] , array $ modifyVars = [ ] ) { if ( empty ( $ options [ 'overwrite' ] ) ) { $ options [ 'overwrite' ] = true ; } $ overwrite = $ options [ 'overwrite' ] ; unset ( $ options [ 'overwrite' ] ) ; $ matches = $ css = $ less = [ ] ; preg_match_all ( '@(<link[^>]+>)@' , $ this -> _View -> fetch ( 'css' ) , $ matches ) ; if ( empty ( $ matches ) ) { return null ; } $ matches = array_shift ( $ matches ) ; foreach ( $ matches as $ stylesheet ) { if ( strpos ( $ stylesheet , 'rel="stylesheet/less"' ) !== false ) { $ match = [ ] ; preg_match ( '@href="([^"]+)"@' , $ stylesheet , $ match ) ; $ file = rtrim ( array_pop ( $ match ) , '?' ) ; array_push ( $ less , $ this -> less ( $ file , $ options , $ modifyVars ) ) ; continue ; } array_push ( $ css , $ stylesheet ) ; } if ( $ overwrite ) { $ this -> _View -> Blocks -> set ( 'css' , join ( $ css ) ) ; } return join ( $ less ) ; }
Fetches less stylesheets added to css block and compiles them
15,885
public function less ( $ less = 'styles.less' , array $ options = [ ] , array $ modifyVars = [ ] ) { $ options = $ this -> setOptions ( $ options ) ; $ less = ( array ) $ less ; if ( $ options [ 'js' ] [ 'env' ] == 'development' ) { return $ this -> jsBlock ( $ less , $ options ) ; } try { $ css = $ this -> compile ( $ less , $ options [ 'cache' ] , $ options [ 'parser' ] , $ modifyVars ) ; if ( isset ( $ options [ 'tag' ] ) && ! $ options [ 'tag' ] ) { return $ css ; } if ( ! $ options [ 'cache' ] ) { return $ this -> Html -> formatTemplate ( 'style' , [ 'content' => $ css ] ) ; } return $ this -> Html -> css ( $ css ) ; } catch ( \ Exception $ e ) { if ( Configure :: read ( 'debug' ) ) { $ options [ 'js' ] [ 'env' ] = 'development' ; } $ this -> error = $ e -> getMessage ( ) ; Log :: write ( 'error' , "Error compiling less file: " . $ this -> error ) ; return $ this -> jsBlock ( $ less , $ options ) ; } }
Compiles any less files passed and returns the compiled css . In case of error it will load less with the javascritp parser so you ll be able to see any errors on screen . If not check out the error . log file in your CakePHP s logs folder .
15,886
protected function jsBlock ( $ less , array $ options = [ ] ) { $ return = '' ; $ less = ( array ) $ less ; foreach ( $ less as $ les ) { $ return .= $ this -> Html -> meta ( 'link' , null , [ 'link' => $ les , 'rel' => 'stylesheet/less' ] ) ; } $ return .= $ this -> Html -> scriptBlock ( sprintf ( 'less = %s;' , json_encode ( $ options [ 'js' ] , JSON_UNESCAPED_SLASHES ) ) ) ; $ return .= $ this -> Html -> script ( $ options [ 'less' ] ) ; return $ return ; }
Returns the required script and link tags to get less . js working
15,887
protected function compile ( array $ input , $ cache , array $ options = [ ] , array $ modifyVars = [ ] ) { $ parse = $ this -> prepareInputFilesForParsing ( $ input ) ; if ( $ cache ) { $ options += [ 'cache_dir' => $ this -> cssPath ] ; return \ Less_Cache :: Get ( $ parse , $ options , $ modifyVars ) ; } $ lessc = new \ Less_Parser ( $ options ) ; foreach ( $ parse as $ file => $ path ) { $ lessc -> parseFile ( $ file , $ path ) ; } $ lessc -> ModifyVars ( $ modifyVars ) ; return $ lessc -> getCss ( ) ; }
Compiles an input less file to an output css file using the PHP compiler .
15,888
protected function prepareInputFilesForParsing ( array $ input = [ ] ) { $ parse = [ ] ; foreach ( $ input as $ in ) { $ less = realpath ( WWW_ROOT . $ in ) ; list ( $ plugin , $ basefile ) = $ this -> _View -> pluginSplit ( $ in , false ) ; if ( ! empty ( $ plugin ) ) { $ less = realpath ( Plugin :: path ( $ plugin ) . 'webroot' . DS . $ basefile ) ; if ( $ less !== false ) { $ parse [ $ less ] = $ this -> assetBaseUrl ( $ plugin , $ basefile ) ; continue ; } } if ( $ less !== false ) { $ parse [ $ less ] = '' ; continue ; } list ( $ plugin , $ basefile ) = $ this -> assetSplit ( $ in ) ; if ( $ file = $ this -> pluginAssetFile ( [ $ plugin , $ basefile ] ) ) { $ parse [ $ file ] = $ this -> assetBaseUrl ( $ plugin , $ basefile ) ; continue ; } $ parse [ $ in ] = '' ; } return $ parse ; }
Prepares input files as Less . php parser wants them .
15,889
protected function setOptions ( array $ options ) { $ this -> parserDefaults = array_merge ( $ this -> parserDefaults , [ 'import_callback' => function ( $ lessTree ) { if ( $ pathAndUri = $ lessTree -> PathAndUri ( ) ) { return $ pathAndUri ; } $ file = $ lessTree -> getPath ( ) ; list ( $ plugin , $ basefile ) = $ this -> assetSplit ( $ file ) ; $ file = $ this -> pluginAssetFile ( [ $ plugin , $ basefile ] ) ; if ( $ file ) { return [ $ file , $ this -> assetBaseUrl ( $ plugin , $ basefile ) ] ; } return null ; } ] ) ; if ( empty ( $ options [ 'parser' ] ) ) { $ options [ 'parser' ] = [ ] ; } if ( Configure :: read ( 'debug' ) && ! isset ( $ options [ 'parser' ] [ 'sourceMap' ] ) ) { $ options [ 'parser' ] [ 'sourceMap' ] = true ; } $ options [ 'parser' ] = array_merge ( $ this -> parserDefaults , $ options [ 'parser' ] ) ; if ( empty ( $ options [ 'js' ] ) ) { $ options [ 'js' ] = [ ] ; } $ options [ 'js' ] = array_merge ( $ this -> lessjsDefaults , $ options [ 'js' ] ) ; if ( empty ( $ options [ 'less' ] ) ) { $ options [ 'less' ] = 'Less.less.min' ; } if ( ! isset ( $ options [ 'cache' ] ) ) { $ options [ 'cache' ] = true ; } return $ options ; }
Sets the less configuration var options based on the ones given by the user and our default ones .
15,890
protected function assetBaseUrl ( $ plugin , $ asset ) { $ dir = dirname ( $ asset ) ; $ path = ! empty ( $ dir ) && $ dir != '.' ? "/$dir" : null ; return $ this -> Url -> assetUrl ( $ plugin . $ path ) ; }
Returns tha full base url for the given asset
15,891
protected function pluginAssetFile ( array $ url ) { list ( $ plugin , $ basefile ) = $ url ; if ( $ plugin && Plugin :: loaded ( $ plugin ) ) { return realpath ( Plugin :: path ( $ plugin ) . 'webroot' . DS . $ basefile ) ; } return false ; }
Builds asset file path for a plugin based on url .
15,892
protected function assetSplit ( $ url ) { $ basefile = ltrim ( ltrim ( $ url , '.' ) , '/' ) ; $ exploded = explode ( '/' , $ basefile ) ; $ plugin = Inflector :: camelize ( array_shift ( $ exploded ) ) ; $ basefile = implode ( DS , $ exploded ) ; return [ $ plugin , $ basefile ] ; }
Splits an asset URL
15,893
public function make ( array $ config ) { Arr :: requires ( $ config , [ 'token' ] ) ; $ client = new Client ( ) ; return new PushoverGateway ( $ client , $ config ) ; }
Create a new pushover gateway instance .
15,894
public function finalizeRows ( ) { if ( true === $ this -> countable && $ this -> getResultDataCollectionCount ( ) !== $ realCount = $ this -> getCount ( ) ) { foreach ( $ this -> collection as & $ item ) { $ item -> set ( 'LOOP_TOTAL' , $ realCount ) ; } } }
Adjust the collection once all results have been added .
15,895
public static function parse ( string $ amount ) { $ parser = new DecimalMoneyParser ( new ISOCurrencies ( ) ) ; return static :: given ( $ parser -> parse ( $ amount , new Currency ( 'MYR' ) ) -> getAmount ( ) ) ; }
Parse value as ringgit .
15,896
public function findByCountryAndModule ( Country $ country , Module $ module , State $ state = null ) { $ response = null ; $ countryInAreaList = CountryAreaQuery :: findByCountryAndState ( $ country , $ state ) ; foreach ( $ countryInAreaList as $ countryInArea ) { $ response = self :: create ( ) -> filterByAreaId ( $ countryInArea -> getAreaId ( ) ) -> filterByModule ( $ module ) -> findOne ( ) ; if ( $ response !== null ) { break ; } } return $ response ; }
Check if a delivery module is suitable for the given country .
15,897
public function renderPagetabEditionAction ( ) { $ idPage = $ this -> params ( ) -> fromRoute ( 'idPage' , $ this -> params ( ) -> fromQuery ( 'idPage' , '' ) ) ; $ melisKey = $ this -> params ( ) -> fromRoute ( 'melisKey' , '' ) ; $ container = new Container ( 'meliscms' ) ; if ( ! empty ( $ container [ 'content-pages' ] ) ) if ( ! empty ( $ container [ 'content-pages' ] [ $ idPage ] ) ) $ container [ 'content-pages' ] [ $ idPage ] = array ( ) ; $ melisCoreConf = $ this -> getServiceLocator ( ) -> get ( 'MelisConfig' ) ; $ resizeConfig = $ melisCoreConf -> getItem ( 'meliscms/conf' ) [ 'pluginResizable' ] ?? null ; $ melisPage = $ this -> getServiceLocator ( ) -> get ( 'MelisEnginePage' ) ; $ datasPage = $ melisPage -> getDatasPage ( $ idPage , 'saved' ) ; if ( $ datasPage ) { $ datasPageTree = $ datasPage -> getMelisPageTree ( ) ; $ datasTemplate = $ datasPage -> getMelisTemplate ( ) ; } $ this -> loadPageContentPluginsInSession ( $ idPage ) ; $ view = new ViewModel ( ) ; $ view -> idPage = $ idPage ; $ view -> melisKey = $ melisKey ; $ view -> resizablePlugin = $ resizeConfig ; if ( empty ( $ datasPageTree -> page_tpl_id ) || $ datasPageTree -> page_tpl_id == - 1 ) $ view -> noTemplate = true ; else $ view -> noTemplate = false ; if ( ! empty ( $ datasTemplate ) ) $ view -> namespace = $ datasTemplate -> tpl_zf2_website_folder ; else $ view -> namespace = '' ; return $ view ; }
Makes the rendering of the Page Edition Tab
15,898
public function savePageSessionPluginAction ( ) { $ idPage = $ this -> params ( ) -> fromRoute ( 'idPage' , $ this -> params ( ) -> fromQuery ( 'idPage' , '' ) ) ; $ translator = $ this -> serviceLocator -> get ( 'translator' ) ; $ postValues = array ( ) ; $ request = $ this -> getRequest ( ) ; if ( ! empty ( $ idPage ) && $ request -> isPost ( ) ) { $ postValues = get_object_vars ( $ request -> getPost ( ) ) ; $ eventDatas = array ( 'idPage' => $ idPage , 'postValues' => $ postValues ) ; $ this -> getEventManager ( ) -> trigger ( 'meliscms_page_savesession_plugin_start' , $ this , $ eventDatas ) ; $ result = array ( 'success' => 1 , 'errors' => array ( ) ) ; } else { $ result = array ( 'success' => 0 , 'errors' => array ( array ( 'empty' => $ translator -> translate ( 'tr_meliscms_form_common_errors_Empty datas' ) ) ) ) ; } return new JsonModel ( $ result ) ; }
Saves datas edited in a page and posted to this function Save is made in SESSION .
15,899
public function removePageSessionPluginAction ( ) { $ module = $ this -> getRequest ( ) -> getQuery ( 'module' , null ) ; $ pluginName = $ this -> getRequest ( ) -> getQuery ( 'pluginName' , '' ) ; $ pageId = $ this -> getRequest ( ) -> getQuery ( 'pageId' , null ) ; $ pluginId = $ this -> getRequest ( ) -> getQuery ( 'pluginId' , null ) ; $ pluginTag = $ this -> getRequest ( ) -> getQuery ( 'pluginTag' , null ) ; $ parameters = array ( 'module' => $ module , 'pluginName' => $ pluginName , 'pageId' => $ pageId , 'pluginId' => $ pluginId , 'pluginTag' => $ pluginTag , ) ; $ translator = $ this -> serviceLocator -> get ( 'translator' ) ; if ( empty ( $ module ) || empty ( $ pluginName ) || empty ( $ pageId ) || empty ( $ pluginId ) ) { $ result = array ( 'success' => 0 , 'errors' => array ( array ( 'empty' => $ translator -> translate ( 'tr_meliscms_form_common_errors_Empty datas' ) ) ) ) ; } else { $ this -> getEventManager ( ) -> trigger ( 'meliscms_page_removesession_plugin_start' , null , $ parameters ) ; $ container = new Container ( 'meliscms' ) ; if ( ! empty ( $ container [ 'content-pages' ] [ $ pageId ] [ $ pluginTag ] [ $ pluginId ] ) ) unset ( $ container [ 'content-pages' ] [ $ pageId ] [ $ pluginTag ] [ $ pluginId ] ) ; $ this -> getEventManager ( ) -> trigger ( 'meliscms_page_removesession_plugin_end' , null , $ parameters ) ; $ result = array ( 'success' => 1 , 'errors' => array ( ) ) ; } return new JsonModel ( $ result ) ; }
Remove a specific plugin from a pageId Save is made in SESSION .