idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
15,700 | protected function getAvailableCoupons ( ) { $ couponManager = $ this -> container -> get ( 'thelia.coupon.manager' ) ; $ availableCoupons = $ couponManager -> getAvailableCoupons ( ) ; $ cleanedCoupons = [ ] ; foreach ( $ availableCoupons as $ availableCoupon ) { $ condition = [ ] ; $ condition [ 'serviceId' ] = $ availableCoupon -> getServiceId ( ) ; $ condition [ 'name' ] = $ availableCoupon -> getName ( ) ; $ condition [ 'toolTip' ] = $ availableCoupon -> getToolTip ( ) ; $ cleanedCoupons [ ] = $ condition ; } return $ cleanedCoupons ; } | Get all available coupons |
15,701 | protected function cleanConditionForTemplate ( ConditionCollection $ conditions ) { $ cleanedConditions = [ ] ; foreach ( $ conditions as $ index => $ condition ) { $ temp = [ 'serviceId' => $ condition -> getServiceId ( ) , 'index' => $ index , 'name' => $ condition -> getName ( ) , 'toolTip' => $ condition -> getToolTip ( ) , 'summary' => $ condition -> getSummary ( ) , 'validators' => $ condition -> getValidators ( ) ] ; $ cleanedConditions [ ] = $ temp ; } return $ cleanedConditions ; } | Clean condition for template |
15,702 | protected function feedCouponCreateOrUpdateEvent ( Form $ form , Coupon $ model = null ) { $ data = $ form -> getData ( ) ; $ serviceId = $ data [ 'type' ] ; $ coupon = $ this -> container -> get ( $ serviceId ) ; $ couponEvent = new CouponCreateOrUpdateEvent ( $ data [ 'code' ] , $ serviceId , $ data [ 'title' ] , $ coupon -> getEffects ( $ data ) , $ data [ 'shortDescription' ] , $ data [ 'description' ] , $ data [ 'isEnabled' ] , \ DateTime :: createFromFormat ( $ this -> getDefaultDateFormat ( ) , $ data [ 'expirationDate' ] ) , $ data [ 'isAvailableOnSpecialOffers' ] , $ data [ 'isCumulative' ] , $ data [ 'isRemovingPostage' ] , $ data [ 'maxUsage' ] , $ data [ 'locale' ] , $ data [ 'freeShippingForCountries' ] , $ data [ 'freeShippingForModules' ] , $ data [ 'perCustomerUsageCount' ] , empty ( $ data [ 'startDate' ] ) ? null : \ DateTime :: createFromFormat ( $ this -> getDefaultDateFormat ( ) , $ data [ 'startDate' ] ) ) ; if ( isset ( $ model ) ) { $ couponEvent -> setCouponModel ( $ model ) ; } return $ couponEvent ; } | Feed the Coupon Create or Update event with the User inputs |
15,703 | protected function buildConditionFromRequest ( ) { $ request = $ this -> getRequest ( ) ; $ post = $ request -> request -> getIterator ( ) ; $ serviceId = $ request -> request -> get ( 'categoryCondition' ) ; $ operators = [ ] ; $ values = [ ] ; foreach ( $ post as $ key => $ input ) { if ( isset ( $ input [ 'operator' ] ) && isset ( $ input [ 'value' ] ) ) { $ operators [ $ key ] = $ input [ 'operator' ] ; $ values [ $ key ] = $ input [ 'value' ] ; } } $ conditionFactory = $ this -> container -> get ( 'thelia.condition.factory' ) ; $ conditionToSave = $ conditionFactory -> build ( $ serviceId , $ operators , $ values ) ; return $ conditionToSave ; } | Build ConditionInterface from request |
15,704 | protected function manageConditionUpdate ( Coupon $ coupon , ConditionCollection $ conditions ) { $ couponEvent = new CouponCreateOrUpdateEvent ( $ coupon -> getCode ( ) , $ coupon -> getType ( ) , $ coupon -> getTitle ( ) , $ coupon -> getEffects ( ) , $ coupon -> getShortDescription ( ) , $ coupon -> getDescription ( ) , $ coupon -> getIsEnabled ( ) , $ coupon -> getExpirationDate ( ) , $ coupon -> getIsAvailableOnSpecialOffers ( ) , $ coupon -> getIsCumulative ( ) , $ coupon -> getIsRemovingPostage ( ) , $ coupon -> getMaxUsage ( ) , $ coupon -> getLocale ( ) , $ coupon -> getFreeShippingForCountries ( ) , $ coupon -> getFreeShippingForModules ( ) , $ coupon -> getPerCustomerUsageCount ( ) , $ coupon -> getStartDate ( ) ) ; $ couponEvent -> setCouponModel ( $ coupon ) ; $ couponEvent -> setConditions ( $ conditions ) ; $ eventToDispatch = TheliaEvents :: COUPON_CONDITION_UPDATE ; $ this -> dispatch ( $ eventToDispatch , $ couponEvent ) ; $ this -> adminLogAppend ( AdminResources :: COUPON , AccessManager :: UPDATE , sprintf ( 'Coupon %s (ID %s) conditions updated' , $ couponEvent -> getCouponModel ( ) -> getTitle ( ) , $ couponEvent -> getCouponModel ( ) -> getType ( ) ) , $ couponEvent -> getCouponModel ( ) -> getId ( ) ) ; } | Manage how a Condition is updated |
15,705 | public function getModelInstance ( $ fileType , $ parentType ) { if ( ! isset ( $ this -> supportedFileModels [ $ this -> getFileTypeIdentifier ( $ fileType , $ parentType ) ] ) ) { throw new FileException ( sprintf ( "Unsupported file type '%s' for parent type '%s'" , $ fileType , $ parentType ) ) ; } $ className = $ this -> supportedFileModels [ $ this -> getFileTypeIdentifier ( $ fileType , $ parentType ) ] ; $ instance = new $ className ; if ( ! $ instance instanceof FileModelInterface ) { throw new FileException ( sprintf ( "Wrong class type for file type '%s', parent type '%s'. Class '%s' should implements FileModelInterface" , $ fileType , $ parentType , $ className ) ) ; } return $ instance ; } | Create a new FileModelInterface instance from the supportedFileModels table |
15,706 | public function addFileModel ( $ fileType , $ parentType , $ fullyQualifiedClassName ) { $ this -> supportedFileModels [ $ this -> getFileTypeIdentifier ( $ fileType , $ parentType ) ] = $ fullyQualifiedClassName ; } | A a new FileModelInterface class name to the supported class list . |
15,707 | public function copyUploadedFile ( FileModelInterface $ model , UploadedFile $ uploadedFile , ConnectionInterface $ con = null ) { $ newUploadedFile = null ; if ( $ uploadedFile !== null ) { $ directory = $ model -> getUploadDir ( ) ; $ fileName = $ this -> renameFile ( $ model -> getId ( ) , $ uploadedFile ) ; $ newUploadedFile = $ uploadedFile -> move ( $ directory , $ fileName ) ; $ model -> setFile ( $ fileName ) ; if ( ! $ model -> save ( $ con ) ) { throw new ImageException ( sprintf ( 'Failed to update model after copy of uploaded file %s to %s' , $ uploadedFile , $ model -> getFile ( ) ) ) ; } } return $ newUploadedFile ; } | Copy UploadedFile into the server storage directory |
15,708 | public function deleteFile ( FileModelInterface $ model ) { $ url = $ model -> getUploadDir ( ) . DS . $ model -> getFile ( ) ; @ unlink ( str_replace ( '..' , '' , $ url ) ) ; $ model -> delete ( ) ; } | Delete image from file storage and database |
15,709 | public function renameFile ( $ modelId , UploadedFile $ uploadedFile ) { $ extension = $ uploadedFile -> getClientOriginalExtension ( ) ; if ( ! empty ( $ extension ) ) { $ extension = '.' . strtolower ( $ extension ) ; } $ fileName = $ this -> sanitizeFileName ( str_replace ( $ extension , '' , $ uploadedFile -> getClientOriginalName ( ) ) . '-' . $ modelId . $ extension ) ; return $ fileName ; } | Rename file with image model id |
15,710 | public function isImage ( $ mimeType ) { $ isValid = false ; $ allowedType = array ( 'image/jpeg' , 'image/png' , 'image/gif' ) ; if ( \ in_array ( $ mimeType , $ allowedType ) ) { $ isValid = true ; } return $ isValid ; } | Check if a file is an image Check based on mime type |
15,711 | protected function ensureSettings ( ) { if ( ! $ this -> fs -> exists ( Platform :: webDir ( ) . '/sites/default' ) ) { $ this -> fs -> mkdir ( Platform :: webDir ( ) . '/sites/default' , 0775 ) ; } else { $ this -> fs -> chmod ( Platform :: webDir ( ) . '/sites/default' , 0775 ) ; } $ has_settings = $ this -> fs -> exists ( Platform :: webDir ( ) . '/sites/default/settings.php' ) ; if ( $ has_settings ) { $ this -> fs -> chmod ( Platform :: webDir ( ) . '/sites/default/settings.php' , 0664 ) ; } switch ( $ this -> version ) { case DrupalStackHelper :: DRUPAL7 : if ( ! $ has_settings ) { $ this -> fs -> copy ( CLI_ROOT . '/resources/stacks/drupal7/settings.php' , Platform :: webDir ( ) . '/sites/default/settings.php' , true ) ; } break ; case DrupalStackHelper :: DRUPAL8 : if ( ! $ has_settings ) { $ this -> fs -> copy ( CLI_ROOT . '/resources/stacks/drupal8/settings.php' , Platform :: webDir ( ) . '/sites/default/settings.php' , true ) ; } $ this -> fs -> mkdir ( [ Platform :: sharedDir ( ) . '/config' , Platform :: sharedDir ( ) . '/config/active' , Platform :: sharedDir ( ) . '/config/staging' , ] ) ; break ; default : throw new \ Exception ( 'Unsupported version of Drupal. Write a pull reuqest!' ) ; } } | Ensures that the Drupal settings . php is available . |
15,712 | public function drushrc ( ) { switch ( $ this -> version ) { case DrupalStackHelper :: DRUPAL7 : $ this -> fs -> copy ( CLI_ROOT . '/resources/stacks/drupal7/drushrc.php' , Platform :: sharedDir ( ) . '/drushrc.php' , true ) ; break ; case DrupalStackHelper :: DRUPAL8 : $ this -> fs -> copy ( CLI_ROOT . '/resources/stacks/drupal8/drushrc.php' , Platform :: sharedDir ( ) . '/drushrc.php' , true ) ; break ; default : throw new \ Exception ( 'Unsupported version of Drupal. Write a pull reuqest!' ) ; } $ localSettings = file_get_contents ( Platform :: sharedDir ( ) . '/drushrc.php' ) ; $ localSettings = str_replace ( '{{ project_domain }}' , $ this -> projectName . '.' . $ this -> projectTld , $ localSettings ) ; file_put_contents ( Platform :: sharedDir ( ) . '/drushrc.php' , $ localSettings ) ; if ( ! file_exists ( Platform :: webDir ( ) . '/sites/default/drushrc.php' ) ) { $ this -> fs -> symlink ( $ this -> getRelativeLinkToShared ( ) . 'drushrc.php' , Platform :: webDir ( ) . '/sites/default/drushrc.php' ) ; } } | Write a drushrc |
15,713 | public function addPrompt ( $ prompt ) { $ added = false ; if ( ! $ this -> isPrompt ( $ prompt [ 'name' ] ) && ! $ this -> isPluginDismissed ( $ prompt [ 'plugin' ] ) ) { $ prompt [ 'time_added' ] = time ( ) ; $ prompts = $ this -> getPrompts ( ) ; $ prompts [ ] = $ prompt ; $ added = $ this -> savePrompts ( $ prompts ) ; } return $ added ; } | Add a prompt . |
15,714 | public function admin_notices ( ) { if ( ! current_user_can ( $ this -> userRole ) ) { return ; } $ prompt = $ this -> getNext ( ) ; if ( empty ( $ prompt ) ) { return ; } $ slides = $ this -> getPromptSlides ( $ prompt ) ; if ( ! empty ( $ slides ) ) { echo '<div class="notice notice-success bglib-rating-prompt is-dismissible" data-slide-name="' . esc_attr ( $ prompt [ 'name' ] ) . '">' ; foreach ( $ slides as $ slide ) { echo $ slide ; } wp_nonce_field ( 'bglib-rating-prompt' ) ; echo '</div>' ; } } | Add admin notices . |
15,715 | public function ajaxDismiss ( ) { if ( ! current_user_can ( $ this -> userRole ) ) { wp_send_json_error ( __ ( 'Permission denied.' , 'boldgrid-library' ) ) ; } if ( ! check_ajax_referer ( 'bglib-rating-prompt' , 'security' , false ) ) { wp_send_json_error ( __ ( 'Invalid nonce.' , 'boldgrid-library' ) ) ; } $ name = sanitize_text_field ( $ _POST [ 'name' ] ) ; $ type = sanitize_text_field ( $ _POST [ 'type' ] ) ; $ snooze_length = ( int ) $ _POST [ 'length' ] ; switch ( $ type ) { case 'dismiss' : $ dismissed = $ this -> updatePromptKey ( $ name , 'time_dismissed' , time ( ) ) ; $ dismissed ? wp_send_json_success ( ) : wp_send_json_error ( __ ( 'Error dismissing prompt' , 'boldgrid-library' ) ) ; break ; case 'snooze' : $ time_snoozed_set = $ this -> updatePromptKey ( $ name , 'time_snoozed' , time ( ) ) ; $ snoozed = $ this -> updatePromptKey ( $ name , 'time_snoozed_until' , time ( ) + $ snooze_length ) ; $ time_snoozed_set && $ snoozed ? wp_send_json_success ( ) : wp_send_json_error ( __ ( 'Error snoozing prompt' , 'boldgrid-library' ) ) ; break ; default : wp_send_json_error ( __ ( 'Unknown action.' , 'boldgrid-library' ) ) ; } } | Dismiss a rating prompt via ajax . |
15,716 | public function getLastDismissal ( ) { $ lastDismissal = 0 ; $ prompts = $ this -> getPrompts ( ) ; foreach ( $ prompts as $ prompt ) { $ promptDismissal = 0 ; if ( ! empty ( $ prompt [ 'time_dismissed' ] ) ) { $ promptDismissal = $ prompt [ 'time_dismissed' ] ; } elseif ( ! empty ( $ prompt [ 'time_snoozed' ] ) ) { $ promptDismissal = $ prompt [ 'time_snoozed' ] ; } $ lastDismissal = $ promptDismissal > $ lastDismissal ? $ promptDismissal : $ lastDismissal ; } return $ lastDismissal ; } | Get the time of the last dismissal or snooze whichever is latest . |
15,717 | public function admin_enqueue_scripts ( ) { if ( ! current_user_can ( $ this -> userRole ) ) { return ; } $ prompt = $ this -> getNext ( ) ; if ( ! empty ( $ prompt ) ) { wp_enqueue_script ( 'bglib-rating-prompt-js' , Library \ Configs :: get ( 'libraryUrl' ) . 'src/assets/js/rating-prompt.js' , 'jquery' , date ( 'Ymd' ) ) ; wp_enqueue_style ( 'bglib-rating-prompt-css' , Library \ Configs :: get ( 'libraryUrl' ) . 'src/assets/css/rating-prompt.css' , array ( ) , date ( 'Ymd' ) ) ; } } | Admin enqueue scripts . |
15,718 | public function getPromptSlides ( $ prompt ) { $ slides = array ( ) ; if ( ! empty ( $ prompt [ 'slides' ] ) ) { foreach ( $ prompt [ 'slides' ] as $ slide_id => $ slide ) { $ slideMarkup = $ this -> getSlideMarkup ( $ slide_id , $ slide ) ; $ slides [ $ slide_id ] = $ slideMarkup ; } } return $ slides ; } | Return the markup of a prompt s slides . |
15,719 | public function getSlideMarkup ( $ slide_id , $ slide ) { $ slideMarkup = '<div data-slide-id="' . esc_attr ( $ slide_id ) . '">' ; $ slideMarkup .= '<p>' . $ slide [ 'text' ] . '</p>' ; if ( ! empty ( $ slide [ 'decisions' ] ) ) { $ slide_decisions = array ( ) ; foreach ( $ slide [ 'decisions' ] as $ decision ) { $ attributes = $ this -> getDecisionAttributes ( $ decision ) ; $ markup = '<a ' ; foreach ( $ attributes as $ key => $ value ) { $ markup .= $ key . '="' . $ value . '" ' ; } $ markup .= '>' . esc_html ( $ decision [ 'text' ] ) . '</a>' ; $ slide_decisions [ ] = $ markup ; } $ slideMarkup .= '<ul><li>' . implode ( '</li><li>' , $ slide_decisions ) . '</li></ul>' ; } $ slideMarkup .= '</div>' ; return $ slideMarkup ; } | Get the markup for an individual slide . |
15,720 | public function getPrompt ( $ name ) { $ prompt_found = array ( ) ; $ prompts = $ this -> getPrompts ( ) ; foreach ( $ prompts as $ prompt ) { if ( $ name === $ prompt [ 'name' ] ) { $ prompt_found = $ prompt ; break ; } } return $ prompt_found ; } | Get a prompt by name . |
15,721 | public function isPluginDismissed ( $ plugin ) { $ dismissed = false ; $ plugin_prompts = $ this -> getPluginPrompts ( $ plugin ) ; foreach ( $ plugin_prompts as $ prompt ) { if ( ! empty ( $ prompt [ 'time_dismissed' ] ) ) { $ dismissed = true ; } } return $ dismissed ; } | Determine whether or not a given plugin has any dismissed notices . |
15,722 | public function getPluginPrompts ( $ plugin ) { $ pluginPrompts = array ( ) ; $ prompts = $ this -> getPrompts ( ) ; foreach ( $ prompts as $ prompt ) { if ( $ prompt [ 'plugin' ] === $ plugin ) { $ pluginPrompts [ ] = $ prompt ; } } return $ pluginPrompts ; } | Get all prompts for a plugin . |
15,723 | public function getNext ( ) { $ nextPrompt = array ( ) ; $ prompts = $ this -> getPrompts ( ) ; foreach ( $ prompts as $ prompt ) { $ isDismissed = isset ( $ prompt [ 'time_dismissed' ] ) ; $ isOlder = empty ( $ nextPrompt ) || ( ! $ isDismissed && $ prompt [ 'time_added' ] < $ nextPrompt [ 'time_added' ] ) ; $ isStillSnoozing = ! empty ( $ prompt [ 'time_snoozed_until' ] ) && $ prompt [ 'time_snoozed_until' ] > time ( ) ; if ( ! $ isDismissed && $ isOlder && ! $ isStillSnoozing ) { $ nextPrompt = $ prompt ; } } if ( ! $ this -> isMinInterval ( ) ) { $ nextPrompt = array ( ) ; } return $ nextPrompt ; } | Get the next prompt to display . |
15,724 | public function updatePrompt ( $ prompt_to_save ) { $ found = false ; $ prompts = $ this -> getPrompts ( ) ; foreach ( $ prompts as $ key => $ prompt ) { if ( $ prompt_to_save [ 'name' ] === $ prompt [ 'name' ] ) { $ found = true ; $ prompts [ $ key ] = $ prompt_to_save ; break ; } } return $ found ? $ this -> savePrompts ( $ prompts ) : false ; } | Update an existing prompt . |
15,725 | public function updatePromptKey ( $ name , $ key , $ value ) { $ prompt = $ this -> getPrompt ( $ name ) ; $ prompt [ $ key ] = $ value ; return $ this -> updatePrompt ( $ prompt ) ; } | Update an attribute for a prompt . |
15,726 | public static function create ( $ name ) { $ name = ( string ) $ name ; $ name = ltrim ( $ name , '\\' ) ; $ namespace_node = Parser :: parseSnippet ( "namespace $name;" ) ; return $ namespace_node ; } | Create namespace declaration . |
15,727 | public function isPaymentModuleFor ( Order $ order ) { $ model = $ this -> getModuleModel ( ) ; return $ order -> getPaymentModuleId ( ) == $ model -> getId ( ) ; } | Check if this module is the payment module for a given order |
15,728 | public function isDeliveryModuleFor ( Order $ order ) { $ model = $ this -> getModuleModel ( ) ; return $ order -> getDeliveryModuleId ( ) == $ model -> getId ( ) ; } | Check if this module is the delivery module for a given order |
15,729 | private function initializeCoreI18n ( ) { if ( $ this -> hasContainer ( ) ) { $ translator = $ this -> container -> get ( 'thelia.translator' ) ; if ( null !== $ translator ) { $ i18nPath = sprintf ( '%s%s/I18n/' , THELIA_MODULE_DIR , $ this -> getCode ( ) ) ; $ languages = LangQuery :: create ( ) -> find ( ) ; foreach ( $ languages as $ language ) { $ locale = $ language -> getLocale ( ) ; $ i18nFile = sprintf ( '%s%s.php' , $ i18nPath , $ locale ) ; if ( is_file ( $ i18nFile ) && is_readable ( $ i18nFile ) ) { $ translator -> addResource ( 'php' , $ i18nFile , $ locale , strtolower ( self :: getModuleCode ( ) ) ) ; } } } } } | Add core translations of the module to use in preActivation and postActivation when the module is not yest activated and translations are not available |
15,730 | protected function setArgs ( $ args ) { if ( $ this -> getKey ( ) ) { $ args = wp_parse_args ( $ args , array ( 'key' => $ this -> getKey ( ) ) ) ; } if ( $ this -> getSiteHash ( ) ) { $ args = wp_parse_args ( $ args , array ( 'site_hash' => $ this -> getSiteHash ( ) ) ) ; } return $ this -> args = array ( 'timeout' => 15 , 'body' => $ args ) ; } | Sets the args class property . |
15,731 | private function call ( ) { if ( 'get' === $ this -> method ) { $ response = wp_remote_get ( $ this -> url , $ this -> args ) ; } else { $ response = wp_remote_post ( $ this -> url , $ this -> args ) ; } $ this -> response = json_decode ( wp_remote_retrieve_body ( $ response ) ) ; if ( $ this -> validateResponse ( $ response ) === false ) { return false ; } if ( ! is_object ( $ this -> response ) ) { $ this -> error = __ ( 'An invalid response was returned.' , 'boldgrid-library' ) ; return false ; } return true ; } | Makes the API call . |
15,732 | private function validateResponse ( $ response ) { if ( is_wp_error ( $ response ) ) { $ this -> error = $ response -> get_error_message ( ) ; return false ; } $ responseCode = wp_remote_retrieve_response_code ( $ response ) ; if ( false === strstr ( $ responseCode , '200' ) ) { $ responseMessage = wp_remote_retrieve_response_message ( $ response ) ; $ this -> error = "{$responseCode} {$responseMessage}" ; return false ; } if ( isset ( $ this -> response -> status ) && 200 !== $ this -> response -> status ) { $ this -> error = $ this -> response -> result -> data ; return false ; } return true ; } | Validates the API response . |
15,733 | public function buildTree ( TokenIterator $ iterator ) { $ this -> skipped = [ ] ; $ this -> skipParent = NULL ; $ this -> docComment = NULL ; $ this -> skippedDocComment = [ ] ; $ this -> iterator = $ iterator ; $ this -> current = $ this -> iterator -> current ( ) ; $ this -> currentType = $ this -> current ? $ this -> current -> getType ( ) : NULL ; $ top = new RootNode ( ) ; $ this -> top = $ top ; if ( $ this -> currentType && $ this -> currentType !== T_OPEN_TAG ) { $ node = new TemplateNode ( ) ; $ this -> templateStatementList ( $ node ) ; $ top -> addChild ( $ node ) ; } if ( $ this -> tryMatch ( T_OPEN_TAG , $ top , NULL , TRUE , TRUE ) ) { $ this -> topStatementList ( $ top ) ; } return $ top ; } | Build a syntax tree from the token iterator . |
15,734 | public static function parseFile ( $ filename ) { $ source = @ file_get_contents ( $ filename ) ; if ( $ source === FALSE ) { return FALSE ; } return self :: parseSource ( $ source , $ filename ) ; } | Parse a file and return the parsed tree |
15,735 | public static function parseSource ( $ source , $ filename = NULL ) { static $ tokenizer , $ parser = NULL ; if ( ! isset ( $ parser ) ) { $ tokenizer = new Tokenizer ( ) ; $ parser = new self ( ) ; } $ tokens = $ tokenizer -> getAll ( $ source , $ filename ) ; $ parser -> filename = $ filename ; return $ parser -> buildTree ( new TokenIterator ( $ tokens ) ) ; } | Parse PHP source code and return the parsed tree . |
15,736 | public static function parseExpression ( $ expression ) { $ tree = self :: parseSource ( '<?php ' . $ expression . ';' ) ; $ statement_node = $ tree -> firstChild ( ) -> next ( ) ; return $ statement_node -> getExpression ( ) -> remove ( ) ; } | Parse a PHP expression . |
15,737 | private function templateStatementList ( ParentNode $ node ) { while ( $ this -> current ) { if ( $ this -> currentType === T_OPEN_TAG ) { return ; } elseif ( $ this -> currentType === T_INLINE_HTML ) { $ node -> addChild ( $ this -> mustMatchToken ( T_INLINE_HTML ) ) ; } elseif ( $ this -> currentType === T_OPEN_TAG_WITH_ECHO ) { $ node -> addChild ( $ this -> echoTagStatement ( ) ) ; } else { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'expected PHP opening tag, but got ' . $ this -> iterator -> current ( ) -> getText ( ) ) ; } } } | Parse zero or more template statements . |
15,738 | private function topStatementList ( StatementBlockNode $ node , $ terminator = '' ) { $ this -> matchHidden ( $ node ) ; while ( $ this -> currentType !== NULL && $ this -> currentType !== $ terminator ) { $ node -> addChild ( $ this -> topStatement ( ) ) ; $ this -> matchHidden ( $ node ) ; } $ this -> matchHidden ( $ node ) ; $ this -> matchDocComment ( $ node , NULL ) ; } | Parse a list of top level statements . |
15,739 | private function topStatement ( ) { switch ( $ this -> currentType ) { case T_USE : return $ this -> useBlock ( ) ; case T_CONST : return $ this -> _const ( ) ; case T_ABSTRACT : case T_FINAL : case T_CLASS : return $ this -> classDeclaration ( ) ; case T_INTERFACE : return $ this -> interfaceDeclaration ( ) ; case T_TRAIT : return $ this -> traitDeclaration ( ) ; case T_HALT_COMPILER : $ node = new HaltCompilerNode ( ) ; $ this -> mustMatch ( T_HALT_COMPILER , $ node , 'name' ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ this -> mustMatch ( ')' , $ node , 'closeParen' ) ; $ this -> endStatement ( $ node ) ; $ this -> tryMatch ( T_INLINE_HTML , $ node ) ; return $ node ; default : if ( $ this -> currentType === T_FUNCTION && $ this -> isLookAhead ( T_STRING , '&' ) ) { return $ this -> functionDeclaration ( ) ; } elseif ( $ this -> currentType === T_NAMESPACE && ! $ this -> isLookAhead ( T_NS_SEPARATOR ) ) { return $ this -> _namespace ( ) ; } return $ this -> statement ( ) ; } } | Parse a top level statement . |
15,740 | private function _const ( ) { $ node = new ConstantDeclarationStatementNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ this -> mustMatch ( T_CONST , $ node ) ; $ declarations = new CommaListNode ( ) ; do { $ declarations -> addChild ( $ this -> constDeclaration ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ declarations ) ) ; $ node -> addChild ( $ declarations , 'declarations' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a constant declaration list . |
15,741 | private function constDeclaration ( ) { $ node = new ConstantDeclarationNode ( ) ; $ name_node = new NameNode ( ) ; $ this -> mustMatch ( T_STRING , $ name_node , NULL , TRUE ) ; $ node -> addChild ( $ name_node , 'name' ) ; if ( $ this -> mustMatch ( '=' , $ node ) ) { $ node -> addChild ( $ this -> staticScalar ( ) , 'value' ) ; } return $ node ; } | Parse a constant declaration . |
15,742 | private function statement ( ) { switch ( $ this -> currentType ) { case T_CLOSE_TAG : $ node = new TemplateNode ( ) ; $ this -> mustMatch ( T_CLOSE_TAG , $ node ) ; $ this -> templateStatementList ( $ node ) ; if ( $ this -> iterator -> hasNext ( ) ) { $ this -> mustMatch ( T_OPEN_TAG , $ node , NULL , TRUE , TRUE ) ; } return $ node ; case T_IF : return $ this -> _if ( ) ; case T_WHILE : return $ this -> _while ( ) ; case T_DO : return $ this -> doWhile ( ) ; case T_FOR : return $ this -> _for ( ) ; case T_SWITCH : return $ this -> _switch ( ) ; case T_BREAK : return $ this -> _break ( ) ; case T_CONTINUE : return $ this -> _continue ( ) ; case T_RETURN : return $ this -> _return ( ) ; case T_YIELD : $ node = new YieldStatementNode ( ) ; $ node -> addChild ( $ this -> _yield ( ) ) ; $ this -> endStatement ( $ node ) ; return $ node ; case T_GLOBAL : return $ this -> _global ( ) ; case T_ECHO : return $ this -> _echo ( ) ; case T_UNSET : return $ this -> _unset ( ) ; case T_FOREACH : return $ this -> _foreach ( ) ; case T_DECLARE : return $ this -> _declare ( ) ; case T_TRY : return $ this -> _try ( ) ; case T_THROW : return $ this -> _throw ( ) ; case T_GOTO : return $ this -> _goto ( ) ; case '{' : return $ this -> innerStatementBlock ( ) ; case ';' : $ node = new BlankStatementNode ( ) ; $ this -> endStatement ( $ node ) ; return $ node ; case T_STATIC : if ( $ this -> isLookAhead ( T_VARIABLE ) ) { return $ this -> staticVariableList ( ) ; } else { return $ this -> exprStatement ( ) ; } case T_STRING : if ( $ this -> isLookAhead ( ':' ) ) { $ node = new GotoLabelNode ( ) ; $ this -> mustMatch ( T_STRING , $ node , 'label' ) ; $ this -> mustMatch ( ':' , $ node , NULL , TRUE , TRUE ) ; return $ node ; } else { return $ this -> exprStatement ( ) ; } default : return $ this -> exprStatement ( ) ; } } | Parse a statement . |
15,743 | private function staticVariableList ( ) { $ node = new StaticVariableStatementNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ this -> mustMatch ( T_STATIC , $ node ) ; $ variables = new CommaListNode ( ) ; do { $ variables -> addChild ( $ this -> staticVariable ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ variables ) ) ; $ node -> addChild ( $ variables , 'variables' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a static variable list . |
15,744 | private function staticVariable ( ) { $ node = new StaticVariableNode ( ) ; $ this -> mustMatch ( T_VARIABLE , $ node , 'name' , TRUE ) ; if ( $ this -> tryMatch ( '=' , $ node ) ) { $ node -> addChild ( $ this -> staticScalar ( ) , 'initialValue' ) ; } return $ node ; } | Parse a static variable . |
15,745 | private function exprStatement ( ) { $ node = new ExpressionStatementNode ( ) ; $ this -> matchDocComment ( $ node ) ; $ node -> addChild ( $ this -> expr ( ) , 'expression' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse expression statement . |
15,746 | private function condition ( ParentNode $ node , $ property_name ) { $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; if ( $ this -> currentType === T_YIELD ) { $ node -> addChild ( $ this -> _yield ( ) , $ property_name ) ; } else { $ node -> addChild ( $ this -> expr ( ) , $ property_name ) ; } $ this -> mustMatch ( ')' , $ node , 'closeParen' ) ; } | Parse condition . |
15,747 | private function _if ( ) { $ node = new IfNode ( ) ; $ this -> mustMatch ( T_IF , $ node ) ; $ this -> condition ( $ node , 'condition' ) ; if ( $ this -> tryMatch ( ':' , $ node , 'openColon' , FALSE , TRUE ) ) { $ node -> addChild ( $ this -> innerIfInnerStatementList ( ) , 'then' ) ; while ( $ this -> currentType === T_ELSEIF ) { $ this -> matchHidden ( $ node ) ; $ elseIf = new ElseIfNode ( ) ; $ this -> mustMatch ( T_ELSEIF , $ elseIf ) ; $ this -> condition ( $ elseIf , 'condition' ) ; $ this -> mustMatch ( ':' , $ elseIf , 'openColon' , FALSE , TRUE ) ; $ elseIf -> addChild ( $ this -> innerIfInnerStatementList ( ) , 'then' ) ; $ node -> addChild ( $ elseIf ) ; } if ( $ this -> tryMatch ( T_ELSE , $ node , 'elseKeyword' ) ) { $ this -> mustMatch ( ':' , $ node , 'elseColon' , FALSE , TRUE ) ; $ node -> addChild ( $ this -> innerStatementListNode ( T_ENDIF ) , 'else' ) ; } $ this -> mustMatch ( T_ENDIF , $ node , 'endKeyword' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } else { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> statement ( ) , 'then' ) ; while ( $ this -> currentType === T_ELSEIF ) { $ this -> matchHidden ( $ node ) ; $ elseIf = new ElseIfNode ( ) ; $ this -> mustMatch ( T_ELSEIF , $ elseIf ) ; $ this -> condition ( $ elseIf , 'condition' ) ; $ this -> matchHidden ( $ elseIf ) ; $ elseIf -> addChild ( $ this -> statement ( ) , 'then' ) ; $ node -> addChild ( $ elseIf ) ; } if ( $ this -> tryMatch ( T_ELSE , $ node , 'elseKeyword' , FALSE , TRUE ) ) { $ node -> addChild ( $ this -> statement ( ) , 'else' ) ; } return $ node ; } } | Parse if control structure . |
15,748 | private function innerIfInnerStatementList ( ) { static $ terminators = [ T_ELSEIF , T_ELSE , T_ENDIF ] ; $ node = new StatementBlockNode ( ) ; while ( $ this -> currentType !== NULL && ! in_array ( $ this -> currentType , $ terminators ) ) { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> innerStatement ( ) ) ; } return $ node ; } | Parse statements for alternative if syntax . |
15,749 | private function _while ( ) { $ node = new WhileNode ( ) ; $ this -> mustMatch ( T_WHILE , $ node ) ; $ this -> condition ( $ node , 'condition' ) ; if ( $ this -> tryMatch ( ':' , $ node , 'openColon' , FALSE , TRUE ) ) { $ node -> addChild ( $ this -> innerStatementListNode ( T_ENDWHILE ) , 'body' ) ; $ this -> mustMatch ( T_ENDWHILE , $ node , 'endKeyword' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } else { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> statement ( ) , 'body' ) ; return $ node ; } } | Parse while control structure . |
15,750 | private function doWhile ( ) { $ node = new DoWhileNode ( ) ; $ this -> mustMatch ( T_DO , $ node , NULL , FALSE , TRUE ) ; $ node -> addChild ( $ this -> statement ( ) , 'body' ) ; $ this -> mustMatch ( T_WHILE , $ node , 'whileKeyword' ) ; $ this -> condition ( $ node , 'condition' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse do while control stucture . |
15,751 | private function _for ( ) { $ node = new ForNode ( ) ; $ this -> mustMatch ( T_FOR , $ node ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ this -> forExpr ( $ node , ';' , 'initial' ) ; $ this -> forExpr ( $ node , ';' , 'condition' ) ; $ this -> forExpr ( $ node , ')' , 'step' , TRUE , 'closeParen' ) ; if ( $ this -> tryMatch ( ':' , $ node , 'openColon' , FALSE , TRUE ) ) { $ node -> addChild ( $ this -> innerStatementListNode ( T_ENDFOR ) , 'body' ) ; $ this -> mustMatch ( T_ENDFOR , $ node , 'endKeyword' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } else { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> statement ( ) , 'body' ) ; return $ node ; } } | Parse for control structure . |
15,752 | private function forExpr ( ForNode $ parent , $ terminator , $ property_name , $ is_last = FALSE , $ terminator_name = NULL ) { if ( $ this -> tryMatch ( $ terminator , $ parent ) ) { $ parent -> addChild ( new CommaListNode ( ) , $ property_name ) ; return ; } $ parent -> addChild ( $ this -> exprList ( ) , $ property_name ) ; $ this -> mustMatch ( $ terminator , $ parent , $ terminator_name , $ is_last , FALSE ) ; } | Parse a for expression . |
15,753 | private function _switch ( ) { $ node = new SwitchNode ( ) ; $ this -> mustMatch ( T_SWITCH , $ node ) ; $ this -> condition ( $ node , 'switchOn' ) ; if ( $ this -> tryMatch ( ':' , $ node , 'openColon' ) ) { $ this -> tryMatch ( ';' , $ node ) ; while ( $ this -> currentType !== NULL && $ this -> currentType !== T_ENDSWITCH ) { $ node -> addChild ( $ this -> caseStatement ( T_ENDSWITCH ) ) ; $ this -> matchHidden ( $ node ) ; } $ this -> mustMatch ( T_ENDSWITCH , $ node , 'endKeyword' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } else { $ this -> mustMatch ( '{' , $ node ) ; $ this -> tryMatch ( ';' , $ node ) ; while ( $ this -> currentType !== NULL && $ this -> currentType !== '}' ) { $ node -> addChild ( $ this -> caseStatement ( '}' ) ) ; $ this -> matchHidden ( $ node ) ; } $ this -> mustMatch ( '}' , $ node , NULL , TRUE ) ; return $ node ; } } | Parse a switch control structure . |
15,754 | private function caseStatement ( $ terminator ) { static $ terminators = [ T_CASE , T_DEFAULT ] ; if ( $ this -> currentType === T_CASE ) { $ node = new CaseNode ( ) ; $ this -> mustMatch ( T_CASE , $ node ) ; $ node -> addChild ( $ this -> expr ( ) , 'matchOn' ) ; if ( ! $ this -> tryMatch ( ':' , $ node , NULL , TRUE , TRUE ) && ! $ this -> tryMatch ( ';' , $ node , NULL , TRUE , TRUE ) ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'expected :' ) ; } if ( $ this -> currentType !== $ terminator && ! in_array ( $ this -> currentType , $ terminators ) ) { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> innerCaseStatementList ( $ terminator ) , 'body' ) ; } return $ node ; } elseif ( $ this -> currentType === T_DEFAULT ) { $ node = new DefaultNode ( ) ; $ this -> mustMatch ( T_DEFAULT , $ node ) ; if ( ! $ this -> tryMatch ( ':' , $ node , NULL , TRUE , TRUE ) && ! $ this -> tryMatch ( ';' , $ node , NULL , TRUE , TRUE ) ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'expected :' ) ; } if ( $ this -> currentType !== $ terminator && ! in_array ( $ this -> currentType , $ terminators ) ) { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> innerCaseStatementList ( $ terminator ) , 'body' ) ; } return $ node ; } throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , "expected case or default" ) ; } | Parse a case statement . |
15,755 | private function innerCaseStatementList ( $ terminator ) { static $ terminators = [ T_CASE , T_DEFAULT ] ; $ node = new StatementBlockNode ( ) ; while ( $ this -> currentType !== NULL && $ this -> currentType !== $ terminator && ! in_array ( $ this -> currentType , $ terminators ) ) { $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> innerStatement ( ) ) ; } return $ node ; } | Parse the inner statements for a case statement . |
15,756 | private function _break ( ) { $ node = new BreakStatementNode ( ) ; $ this -> mustMatch ( T_BREAK , $ node ) ; if ( $ this -> tryMatch ( ';' , $ node , NULL , TRUE , TRUE ) || $ this -> currentType === T_CLOSE_TAG ) { return $ node ; } $ this -> parseLevel ( $ node ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a break statement . |
15,757 | private function _continue ( ) { $ node = new ContinueStatementNode ( ) ; $ this -> mustMatch ( T_CONTINUE , $ node ) ; if ( $ this -> tryMatch ( ';' , $ node , NULL , TRUE , TRUE ) || $ this -> currentType === T_CLOSE_TAG ) { return $ node ; } $ this -> parseLevel ( $ node ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a continue statement . |
15,758 | private function _return ( ) { $ node = new ReturnStatementNode ( ) ; $ this -> mustMatch ( T_RETURN , $ node ) ; if ( $ this -> tryMatch ( ';' , $ node , NULL , TRUE , TRUE ) || $ this -> currentType === T_CLOSE_TAG ) { return $ node ; } $ node -> addChild ( $ this -> expr ( ) , 'expression' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a return statement . |
15,759 | private function _yield ( ) { $ node = new YieldNode ( ) ; $ this -> mustMatch ( T_YIELD , $ node ) ; $ expr = $ this -> expr ( ) ; if ( $ this -> tryMatch ( T_DOUBLE_ARROW , $ node ) ) { $ node -> addChild ( $ expr , 'key' ) ; $ node -> addChild ( $ this -> expr ( ) , 'value' ) ; } else { $ node -> addChild ( $ expr , 'value' ) ; } return $ node ; } | Parse a yield expression . |
15,760 | private function _global ( ) { $ node = new GlobalStatementNode ( ) ; $ this -> mustMatch ( T_GLOBAL , $ node ) ; $ variables = new CommaListNode ( ) ; do { $ variables -> addChild ( $ this -> globalVar ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ variables ) ) ; $ node -> addChild ( $ variables , 'variables' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a global variable declaration list . |
15,761 | private function globalVar ( ) { if ( $ this -> currentType === T_VARIABLE ) { return $ this -> mustMatchToken ( T_VARIABLE ) ; } elseif ( $ this -> currentType === '$' ) { if ( $ this -> isLookAhead ( '{' ) ) { return $ this -> _compoundVariable ( ) ; } else { $ node = new VariableVariableNode ( ) ; $ this -> mustMatch ( '$' , $ node ) ; $ node -> addChild ( $ this -> variable ( ) ) ; return $ node ; } } throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'expected a global variable (eg. T_VARIABLE)' ) ; } | Parse global variable . |
15,762 | private function _echo ( ) { $ node = new EchoStatementNode ( ) ; $ this -> mustMatch ( T_ECHO , $ node ) ; $ expressions = new CommaListNode ( ) ; do { $ expressions -> addChild ( $ this -> expr ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ expressions ) ) ; $ node -> addChild ( $ expressions , 'expressions' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse echo statement . |
15,763 | private function _unset ( ) { $ statement_node = new UnsetStatementNode ( ) ; $ node = new UnsetNode ( ) ; $ this -> mustMatch ( T_UNSET , $ node , 'name' ) ; $ arguments = new CommaListNode ( ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ node -> addChild ( $ arguments , 'arguments' ) ; do { $ arguments -> addChild ( $ this -> variable ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ arguments ) ) ; $ this -> mustMatch ( ')' , $ node , 'closeParen' , FALSE ) ; $ statement_node -> addChild ( $ node , 'functionCall' ) ; $ this -> endStatement ( $ statement_node ) ; return $ statement_node ; } | Parse an unset statement . |
15,764 | private function _foreach ( ) { $ node = new ForeachNode ( ) ; $ this -> mustMatch ( T_FOREACH , $ node ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ node -> addChild ( $ this -> expr ( ) , 'onEach' ) ; $ this -> mustMatch ( T_AS , $ node ) ; $ value = $ this -> foreachVariable ( ) ; if ( $ this -> currentType === T_DOUBLE_ARROW ) { $ node -> addChild ( $ value , 'key' ) ; $ this -> mustMatch ( T_DOUBLE_ARROW , $ node ) ; $ node -> addChild ( $ this -> foreachVariable ( ) , 'value' ) ; } else { $ node -> addChild ( $ value , 'value' ) ; } $ this -> mustMatch ( ')' , $ node , 'closeParen' , FALSE , TRUE ) ; if ( $ this -> tryMatch ( ':' , $ node , NULL , FALSE , TRUE ) ) { $ node -> addChild ( $ this -> innerStatementListNode ( T_ENDFOREACH ) , 'body' ) ; $ this -> mustMatch ( T_ENDFOREACH , $ node ) ; $ this -> endStatement ( $ node ) ; return $ node ; } else { $ node -> addChild ( $ this -> statement ( ) , 'body' ) ; return $ node ; } } | Parse foreach control structure . |
15,765 | private function foreachVariable ( ) { if ( $ this -> currentType === T_LIST ) { return $ this -> _list ( ) ; } else { if ( $ this -> currentType === '&' ) { return $ this -> writeVariable ( ) ; } else { return $ this -> variable ( ) ; } } } | Parse a foreach variable . |
15,766 | private function _declare ( ) { $ node = new DeclareNode ( ) ; $ this -> mustMatch ( T_DECLARE , $ node ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ directives = new CommaListNode ( ) ; $ node -> addChild ( $ directives , 'directives' ) ; if ( ! $ this -> tryMatch ( ')' , $ node , 'closeParen' , FALSE , TRUE ) ) { do { $ declare_directive = new DeclareDirectiveNode ( ) ; $ this -> tryMatch ( T_STRING , $ declare_directive , 'name' ) ; if ( $ this -> tryMatch ( '=' , $ declare_directive ) ) { $ declare_directive -> addChild ( $ this -> staticScalar ( ) , 'value' ) ; } $ directives -> addChild ( $ declare_directive ) ; } while ( $ this -> tryMatch ( ',' , $ directives ) ) ; $ this -> mustMatch ( ')' , $ node , 'closeParen' , FALSE , TRUE ) ; } if ( $ this -> tryMatch ( ':' , $ node , NULL , FALSE , TRUE ) ) { $ node -> addChild ( $ this -> innerStatementListNode ( T_ENDDECLARE ) , 'body' ) ; $ this -> mustMatch ( T_ENDDECLARE , $ node ) ; $ this -> endStatement ( $ node ) ; return $ node ; } else { $ node -> addChild ( $ this -> statement ( ) , 'body' ) ; return $ node ; } } | Parse a declare statement . |
15,767 | private function _try ( ) { $ node = new TryCatchNode ( ) ; $ this -> mustMatch ( T_TRY , $ node ) ; $ node -> addChild ( $ this -> innerStatementBlock ( ) , 'try' ) ; $ catch_node = new CatchNode ( ) ; while ( $ this -> tryMatch ( T_CATCH , $ catch_node ) ) { $ this -> mustMatch ( '(' , $ catch_node , 'openParen' ) ; $ catch_node -> addChild ( $ this -> name ( ) , 'exceptionType' ) ; $ this -> mustMatch ( T_VARIABLE , $ catch_node , 'variable' ) ; $ this -> mustMatch ( ')' , $ catch_node , 'closeParen' , FALSE , TRUE ) ; $ catch_node -> addChild ( $ this -> innerStatementBlock ( ) , 'body' ) ; $ node -> addChild ( $ catch_node ) ; $ catch_node = new CatchNode ( ) ; } if ( $ this -> tryMatch ( T_FINALLY , $ node ) ) { $ node -> addChild ( $ this -> innerStatementBlock ( ) , 'finally' ) ; } return $ node ; } | Parse a try control structure . |
15,768 | private function _throw ( ) { $ node = new ThrowStatementNode ( ) ; $ this -> mustMatch ( T_THROW , $ node ) ; $ node -> addChild ( $ this -> expr ( ) , 'expression' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a throw statement . |
15,769 | private function _goto ( ) { $ node = new GotoStatementNode ( ) ; $ this -> mustMatch ( T_GOTO , $ node ) ; $ this -> mustMatch ( T_STRING , $ node , 'label' ) ; $ this -> endStatement ( $ node ) ; return $ node ; } | Parse a goto statement . |
15,770 | private function exprList ( ) { $ node = new CommaListNode ( ) ; do { $ node -> addChild ( $ this -> expr ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ node ) ) ; return $ node ; } | Parse a list of expressions . |
15,771 | private function staticScalar ( ) { if ( $ this -> currentType === T_ARRAY ) { $ node = new ArrayNode ( ) ; $ this -> mustMatch ( T_ARRAY , $ node ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ this -> staticArrayPairList ( $ node , ')' ) ; $ this -> mustMatch ( ')' , $ node , 'closeParen' , TRUE ) ; return $ node ; } elseif ( $ this -> currentType === '[' ) { $ node = new ArrayNode ( ) ; $ this -> mustMatch ( '[' , $ node ) ; $ this -> staticArrayPairList ( $ node , ']' ) ; $ this -> mustMatch ( ']' , $ node , NULL , TRUE ) ; return $ node ; } else { return $ this -> expr ( TRUE ) ; } } | Parse a static scalar expression . |
15,772 | private function staticOperand ( ) { static $ scalar_types = [ T_STRING_VARNAME , T_CLASS_C , T_LNUMBER , T_DNUMBER , T_CONSTANT_ENCAPSED_STRING , T_LINE , T_FILE , T_DIR , T_TRAIT_C , T_METHOD_C , T_FUNC_C , T_NS_C , ] ; if ( $ scalar = $ this -> tryMatchToken ( $ scalar_types ) ) { return $ scalar ; } elseif ( $ this -> currentType === '(' ) { $ node = new ParenthesisNode ( ) ; $ this -> mustMatch ( '(' , $ node , 'openParen' ) ; $ node -> addChild ( $ this -> staticScalar ( ) , 'expression' ) ; $ this -> mustMatch ( ')' , $ node , 'closeParen' , TRUE ) ; return $ node ; } elseif ( in_array ( $ this -> currentType , self :: $ namespacePathTypes ) ) { $ namespace_path = $ this -> name ( ) ; if ( $ this -> currentType === T_DOUBLE_COLON ) { $ colon_node = new PartialNode ( ) ; $ this -> mustMatch ( T_DOUBLE_COLON , $ colon_node ) ; if ( $ this -> currentType === T_CLASS ) { return $ this -> classNameScalar ( $ namespace_path , $ colon_node ) ; } else { $ class_constant = $ this -> mustMatchToken ( T_STRING ) ; return $ this -> classConstant ( $ namespace_path , $ colon_node , $ class_constant ) ; } } else { $ node = new ConstantNode ( ) ; $ node -> addChild ( $ namespace_path , 'constantName' ) ; return $ node ; } } elseif ( $ this -> currentType === T_STATIC ) { $ static_node = $ this -> mustMatchToken ( T_STATIC ) ; $ colon_node = new PartialNode ( ) ; $ this -> mustMatch ( T_DOUBLE_COLON , $ colon_node ) ; if ( $ this -> currentType === T_CLASS ) { return $ this -> classNameScalar ( $ static_node , $ colon_node ) ; } else { $ class_constant = $ this -> mustMatchToken ( T_STRING ) ; return $ this -> classConstant ( $ static_node , $ colon_node , $ class_constant ) ; } } elseif ( $ this -> currentType === T_START_HEREDOC ) { $ node = new HeredocNode ( ) ; $ this -> mustMatch ( T_START_HEREDOC , $ node ) ; if ( $ this -> tryMatch ( T_END_HEREDOC , $ node ) ) { return $ node ; } $ this -> mustMatch ( T_ENCAPSED_AND_WHITESPACE , $ node ) ; $ this -> mustMatch ( T_END_HEREDOC , $ node ) ; return $ node ; } else { return NULL ; } } | Parse static operand . |
15,773 | private function expr ( $ static = FALSE ) { static $ end_expression_types = [ ':' , ';' , ',' , ')' , ']' , '}' , T_AS , T_DOUBLE_ARROW , T_CLOSE_TAG ] ; $ expression_nodes = [ ] ; while ( $ this -> currentType !== NULL && ! in_array ( $ this -> currentType , $ end_expression_types ) ) { if ( $ op = $ this -> exprOperator ( $ static ) ) { $ expression_nodes [ ] = $ op ; if ( $ op -> type === T_INSTANCEOF ) { $ expression_nodes [ ] = $ this -> classNameReference ( ) ; } } elseif ( $ operand = ( $ static ? $ this -> staticOperand ( ) : $ this -> exprOperand ( ) ) ) { $ expression_nodes [ ] = $ operand ; } else { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , "invalid expression" ) ; } } return $ this -> expressionParser -> parse ( $ expression_nodes , $ this -> filename ) ; } | Parse an expression . |
15,774 | private function exprOperator ( $ static = FALSE ) { $ token_type = $ this -> currentType ; if ( $ operator = OperatorFactory :: createOperator ( $ token_type , $ static ) ) { $ this -> mustMatch ( $ token_type , $ operator , 'operator' ) ; if ( $ token_type === '?' ) { if ( $ this -> currentType === ':' ) { $ colon = new PartialNode ( ) ; $ this -> mustMatch ( ':' , $ colon ) ; return OperatorFactory :: createElvisOperator ( $ operator , $ colon ) ; } else { $ operator -> then = $ static ? $ this -> staticScalar ( ) : $ this -> expr ( ) ; $ colon = new PartialNode ( ) ; $ this -> mustMatch ( ':' , $ colon ) ; $ operator -> colon = $ colon ; return $ operator ; } } elseif ( $ token_type === '=' && $ this -> currentType === '&' ) { $ by_ref_node = new PartialNode ( ) ; $ this -> mustMatch ( '&' , $ by_ref_node ) ; return OperatorFactory :: createAssignReferenceOperator ( $ operator , $ by_ref_node ) ; } return $ operator ; } return NULL ; } | Parse an expression operator . |
15,775 | private function backtick ( ) { $ node = new BacktickNode ( ) ; $ this -> mustMatch ( '`' , $ node ) ; $ this -> encapsList ( $ node , '`' , TRUE ) ; $ this -> mustMatch ( '`' , $ node , NULL , TRUE ) ; return $ node ; } | Parse a backtick expression . |
15,776 | private function anonymousFunction ( Node $ static = NULL ) { $ node = new AnonymousFunctionNode ( ) ; if ( $ static ) { $ node -> addChild ( $ static ) ; } $ this -> mustMatch ( T_FUNCTION , $ node ) ; $ this -> tryMatch ( '&' , $ node , 'reference' ) ; $ this -> parameterList ( $ node ) ; if ( $ this -> tryMatch ( T_USE , $ node , 'lexicalUse' ) ) { $ this -> mustMatch ( '(' , $ node , 'lexicalOpenParen' ) ; $ lexical_vars_node = new CommaListNode ( ) ; do { if ( $ this -> currentType === '&' ) { $ var = new ReferenceVariableNode ( ) ; $ this -> mustMatch ( '&' , $ var ) ; $ this -> mustMatch ( T_VARIABLE , $ var , 'variable' , TRUE ) ; $ lexical_vars_node -> addChild ( $ var ) ; } else { $ this -> mustMatch ( T_VARIABLE , $ lexical_vars_node , NULL , TRUE ) ; } } while ( $ this -> tryMatch ( ',' , $ lexical_vars_node ) ) ; $ node -> addChild ( $ lexical_vars_node , 'lexicalVariables' ) ; $ this -> mustMatch ( ')' , $ node , 'lexicalCloseParen' ) ; } $ this -> matchHidden ( $ node ) ; $ node -> addChild ( $ this -> innerStatementBlock ( ) , 'body' ) ; return $ node ; } | Parse an anonymous function declaration . |
15,777 | private function newExpr ( ) { $ node = new NewNode ( ) ; $ this -> mustMatch ( T_NEW , $ node ) ; $ node -> addChild ( $ this -> classNameReference ( ) , 'className' ) ; if ( $ this -> currentType === '(' ) { $ this -> functionCallParameterList ( $ node ) ; } return $ node ; } | Parse a new expression . |
15,778 | private function classNameReference ( ) { switch ( $ this -> currentType ) { case T_STRING : case T_NS_SEPARATOR : case T_NAMESPACE : $ namespace_path = $ this -> name ( ) ; if ( $ this -> currentType === T_DOUBLE_COLON ) { $ node = $ this -> staticMember ( $ namespace_path ) ; return $ this -> dynamicClassNameReference ( $ node ) ; } else { return $ namespace_path ; } case T_STATIC : $ static_node = $ this -> mustMatchToken ( T_STATIC ) ; if ( $ this -> currentType === T_DOUBLE_COLON ) { $ node = $ this -> staticMember ( $ static_node ) ; return $ this -> dynamicClassNameReference ( $ node ) ; } else { return $ static_node ; } default : if ( $ this -> currentType === '$' && ! $ this -> isLookAhead ( '{' ) ) { return $ this -> dynamicClassNameReference ( $ this -> indirectReference ( ) ) ; } $ var_node = $ this -> referenceVariable ( ) ; if ( $ this -> currentType === T_DOUBLE_COLON ) { $ var_node = $ this -> staticMember ( $ var_node ) ; } return $ this -> dynamicClassNameReference ( $ var_node ) ; } } | Parse a class name reference . |
15,779 | private function staticMember ( $ var_node ) { $ node = new ClassMemberLookupNode ( ) ; $ node -> addChild ( $ var_node , 'className' ) ; $ this -> mustMatch ( T_DOUBLE_COLON , $ node ) ; $ node -> addChild ( $ this -> indirectReference ( ) , 'memberName' ) ; return $ node ; } | Parse static member . |
15,780 | private function dynamicClassNameReference ( Node $ object ) { $ node = $ object ; while ( $ this -> currentType === T_OBJECT_OPERATOR ) { $ node = new ObjectPropertyNode ( ) ; $ node -> addChild ( $ object , 'object' ) ; $ this -> mustMatch ( T_OBJECT_OPERATOR , $ node ) ; $ node -> addChild ( $ this -> objectProperty ( ) , 'property' ) ; $ object = $ this -> offsetVariable ( $ node ) ; } return $ node ; } | Parse a dynamic class name reference . |
15,781 | private function arrayPairList ( ArrayNode $ node , $ terminator ) { $ elements = new CommaListNode ( ) ; do { if ( $ this -> currentType === $ terminator ) { break ; } $ this -> matchHidden ( $ elements ) ; $ elements -> addChild ( $ this -> arrayPair ( ) ) ; } while ( $ this -> tryMatch ( ',' , $ elements , NULL , TRUE ) ) ; $ node -> addChild ( $ elements , 'elements' ) ; } | Parse array pair list . |
15,782 | private function staticArrayPairList ( ArrayNode $ node , $ terminator ) { $ elements = new CommaListNode ( ) ; do { if ( $ this -> currentType === $ terminator ) { break ; } $ this -> matchHidden ( $ elements ) ; $ value = $ this -> staticScalar ( ) ; if ( $ this -> currentType === T_DOUBLE_ARROW ) { $ pair = new ArrayPairNode ( ) ; $ pair -> addChild ( $ value , 'key' ) ; $ this -> mustMatch ( T_DOUBLE_ARROW , $ pair ) ; $ pair -> addChild ( $ this -> staticScalar ( ) , 'value' ) ; $ elements -> addChild ( $ pair ) ; } else { $ elements -> addChild ( $ value ) ; } } while ( $ this -> tryMatch ( ',' , $ elements , NULL , TRUE ) ) ; $ node -> addChild ( $ elements , 'elements' ) ; } | Parse static array pair list . |
15,783 | private function arrayPair ( ) { if ( $ this -> currentType === '&' ) { return $ this -> writeVariable ( ) ; } $ node = $ this -> expr ( ) ; if ( $ this -> currentType === T_DOUBLE_ARROW ) { $ expr = $ node ; $ node = new ArrayPairNode ( ) ; $ node -> addChild ( $ expr , 'key' ) ; $ this -> mustMatch ( T_DOUBLE_ARROW , $ node ) ; if ( $ this -> currentType === '&' ) { $ node -> addChild ( $ this -> writeVariable ( ) , 'value' ) ; } else { $ node -> addChild ( $ this -> expr ( ) , 'value' ) ; } } return $ node ; } | Parse an array pair . |
15,784 | private function writeVariable ( ) { $ node = new ReferenceVariableNode ( ) ; $ this -> mustMatch ( '&' , $ node ) ; $ node -> addChild ( $ this -> variable ( ) , 'variable' ) ; return $ node ; } | Parse a write variable . |
15,785 | private function encapsList ( $ node , $ terminator , $ encaps_whitespace_allowed = FALSE ) { if ( ! $ encaps_whitespace_allowed ) { if ( $ this -> tryMatch ( T_ENCAPSED_AND_WHITESPACE , $ node ) ) { $ node -> addChild ( $ this -> encapsVar ( ) ) ; } } while ( $ this -> currentType !== NULL && $ this -> currentType !== $ terminator ) { $ this -> tryMatch ( T_ENCAPSED_AND_WHITESPACE , $ node ) || $ node -> addChild ( $ this -> encapsVar ( ) ) ; } } | Parse an encaps list . |
15,786 | private function encapsVar ( ) { static $ offset_types = [ T_STRING , T_NUM_STRING , T_VARIABLE ] ; $ node = new StringVariableNode ( ) ; if ( $ this -> tryMatch ( T_DOLLAR_OPEN_CURLY_BRACES , $ node ) ) { if ( $ this -> tryMatch ( T_STRING_VARNAME , $ node ) ) { if ( $ this -> tryMatch ( '[' , $ node ) ) { $ node -> addChild ( $ this -> expr ( ) ) ; $ this -> mustMatch ( ']' , $ node ) ; } } else { $ node -> addChild ( $ this -> expr ( ) ) ; } $ this -> mustMatch ( '}' , $ node ) ; return $ node ; } elseif ( $ this -> tryMatch ( T_CURLY_OPEN , $ node ) ) { $ node -> addChild ( $ this -> variable ( ) ) ; $ this -> mustMatch ( '}' , $ node ) ; return $ node ; } elseif ( $ this -> mustMatch ( T_VARIABLE , $ node ) ) { if ( $ this -> tryMatch ( '[' , $ node ) ) { if ( ! in_array ( $ this -> currentType , $ offset_types ) ) { throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'expected encaps_var_offset (T_STRING or T_NUM_STRING or T_VARIABLE)' ) ; } $ node -> addChild ( $ this -> tryMatchToken ( $ offset_types ) ) ; $ this -> mustMatch ( ']' , $ node ) ; } elseif ( $ this -> tryMatch ( T_OBJECT_OPERATOR , $ node ) ) { $ this -> mustMatch ( T_STRING , $ node ) ; } return $ node ; } throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , 'expected encaps variable' ) ; } | Parse an encaps variable . |
15,787 | private function exprClass ( Node $ class_name ) { $ colon_node = new PartialNode ( ) ; $ this -> mustMatch ( T_DOUBLE_COLON , $ colon_node ) ; if ( $ this -> currentType === T_STRING ) { $ class_constant = $ this -> mustMatchToken ( T_STRING ) ; if ( $ this -> currentType === '(' ) { return $ this -> classMethodCall ( $ class_name , $ colon_node , $ class_constant ) ; } else { return $ this -> classConstant ( $ class_name , $ colon_node , $ class_constant ) ; } } elseif ( $ this -> currentType === T_CLASS ) { return $ this -> classNameScalar ( $ class_name , $ colon_node ) ; } else { return $ this -> classVariable ( $ class_name , $ colon_node ) ; } } | Parse expression operand given class name . |
15,788 | private function classConstant ( $ class_name , $ colon_node , $ class_constant ) { $ node = new ClassConstantLookupNode ( ) ; $ node -> addChild ( $ class_name , 'className' ) ; $ node -> mergeNode ( $ colon_node ) ; $ node -> addChild ( $ class_constant , 'constantName' ) ; return $ node ; } | Construct a class constant . |
15,789 | private function classMethodCall ( $ class_name , $ colon_node , $ method_name ) { $ node = new ClassMethodCallNode ( ) ; $ node -> addChild ( $ class_name , 'className' ) ; $ node -> mergeNode ( $ colon_node ) ; $ node -> addChild ( $ method_name , 'methodName' ) ; $ this -> functionCallParameterList ( $ node ) ; return $ this -> objectDereference ( $ this -> arrayDeference ( $ node ) ) ; } | Construct a class method call . |
15,790 | private function classNameScalar ( $ class_name , $ colon_node ) { $ node = new ClassNameScalarNode ( ) ; $ node -> addChild ( $ class_name , 'className' ) ; $ node -> mergeNode ( $ colon_node ) ; $ this -> mustMatch ( T_CLASS , $ node , NULL , TRUE ) ; return $ node ; } | Construct a class name scalar . |
15,791 | private function variable ( ) { switch ( $ this -> currentType ) { case T_STRING : case T_NS_SEPARATOR : case T_NAMESPACE : $ namespace_path = $ this -> name ( ) ; if ( $ this -> currentType === '(' ) { return $ this -> functionCall ( $ namespace_path ) ; } elseif ( $ this -> currentType === T_DOUBLE_COLON ) { return $ this -> varClass ( $ namespace_path ) ; } break ; case T_STATIC : $ class_name = $ this -> mustMatchToken ( T_STATIC ) ; return $ this -> varClass ( $ class_name ) ; case '$' : case T_VARIABLE : $ var = $ this -> indirectReference ( ) ; if ( $ this -> currentType === '(' ) { return $ this -> functionCall ( $ var , TRUE ) ; } elseif ( ! ( $ var instanceof VariableVariableNode ) && $ this -> currentType === T_DOUBLE_COLON ) { return $ this -> varClass ( $ var ) ; } else { return $ this -> objectDereference ( $ var ) ; } } throw new ParserException ( $ this -> filename , $ this -> iterator -> getLineNumber ( ) , $ this -> iterator -> getColumnNumber ( ) , "expected variable" ) ; } | Parse variable . |
15,792 | private function varClass ( Node $ class_name ) { $ colon_node = new PartialNode ( ) ; $ this -> mustMatch ( T_DOUBLE_COLON , $ colon_node ) ; if ( $ this -> currentType === T_STRING ) { $ method_name = $ this -> mustMatchToken ( T_STRING ) ; return $ this -> classMethodCall ( $ class_name , $ colon_node , $ method_name ) ; } else { return $ this -> classVariable ( $ class_name , $ colon_node ) ; } } | Parse variable given class name . |
15,793 | private function functionCall ( Node $ function_reference , $ dynamic = FALSE ) { if ( $ dynamic ) { $ node = new CallbackCallNode ( ) ; $ node -> addChild ( $ function_reference , 'callback' ) ; } else { if ( $ function_reference instanceof NameNode && $ function_reference -> childCount ( ) === 1 && $ function_reference == 'define' ) { $ node = new DefineNode ( ) ; } else { $ node = new FunctionCallNode ( ) ; } $ node -> addChild ( $ function_reference , 'name' ) ; } $ this -> functionCallParameterList ( $ node ) ; return $ this -> objectDereference ( $ this -> arrayDeference ( $ node ) ) ; } | Apply any function call array and object deference . |
15,794 | private function objectDereference ( Node $ object ) { while ( $ this -> currentType === T_OBJECT_OPERATOR ) { $ operator_node = new PartialNode ( ) ; $ this -> mustMatch ( T_OBJECT_OPERATOR , $ operator_node , 'operator' ) ; $ object_property = $ this -> objectProperty ( ) ; if ( $ this -> currentType === '(' ) { $ node = new ObjectMethodCallNode ( ) ; $ node -> addChild ( $ object , 'object' ) ; $ node -> mergeNode ( $ operator_node ) ; $ node -> addChild ( $ object_property , 'methodName' ) ; $ this -> functionCallParameterList ( $ node ) ; $ node = $ this -> arrayDeference ( $ node ) ; } else { $ node = new ObjectPropertyNode ( ) ; $ node -> addChild ( $ object , 'object' ) ; $ node -> mergeNode ( $ operator_node ) ; $ node -> addChild ( $ object_property , 'property' ) ; $ node = $ this -> offsetVariable ( $ node ) ; if ( $ this -> currentType === '(' ) { $ call = new CallbackCallNode ( ) ; $ call -> addChild ( $ node , 'callback' ) ; $ this -> functionCallParameterList ( $ call ) ; $ node = $ this -> arrayDeference ( $ call ) ; } } $ object = $ node ; } return $ object ; } | Apply any object dereference to object operand . |
15,795 | private function objectProperty ( ) { if ( $ this -> currentType === T_STRING ) { return $ this -> mustMatchToken ( T_STRING ) ; } elseif ( $ this -> currentType === '{' ) { return $ this -> bracesExpr ( ) ; } else { return $ this -> indirectReference ( ) ; } } | Parse object property . |
15,796 | private function indirectReference ( ) { if ( $ this -> currentType === '$' && ! $ this -> isLookAhead ( '{' ) ) { $ node = new VariableVariableNode ( ) ; $ this -> mustMatch ( '$' , $ node ) ; $ node -> addChild ( $ this -> indirectReference ( ) , 'variable' ) ; return $ node ; } return $ this -> referenceVariable ( ) ; } | Parse indirect variable reference . |
15,797 | private function offsetVariable ( Node $ var ) { if ( $ this -> currentType === '{' ) { $ node = new ArrayLookupNode ( ) ; $ node -> addChild ( $ var , 'array' ) ; $ this -> mustMatch ( '{' , $ node ) ; $ node -> addChild ( $ this -> expr ( ) , 'key' ) ; $ this -> mustMatch ( '}' , $ node , NULL , TRUE ) ; return $ this -> offsetVariable ( $ node ) ; } elseif ( $ this -> currentType === '[' ) { $ node = new ArrayLookupNode ( ) ; $ node -> addChild ( $ var , 'array' ) ; $ this -> dimOffset ( $ node ) ; return $ this -> offsetVariable ( $ node ) ; } else { return $ var ; } } | Apply any offset to variable . |
15,798 | private function _compoundVariable ( ) { $ node = new CompoundVariableNode ( ) ; $ this -> mustMatch ( '$' , $ node ) ; $ this -> mustMatch ( '{' , $ node ) ; $ node -> addChild ( $ this -> expr ( ) , 'expression' ) ; $ this -> mustMatch ( '}' , $ node , NULL , TRUE ) ; return $ node ; } | Parse compound variable . |
15,799 | private function bracesExpr ( ) { $ node = new NameExpressionNode ( ) ; $ this -> mustMatch ( '{' , $ node ) ; $ node -> addChild ( $ this -> expr ( ) ) ; $ this -> mustMatch ( '}' , $ node , NULL , TRUE ) ; return $ node ; } | Parse braces expression . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.