idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
20,600 | protected function nodeRemove ( $ key , RedBlackNode $ node ) : ? RedBlackNode { $ comp = $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) ; if ( $ comp < 0 ) { $ node = $ this -> nodeRemoveLeft ( $ key , $ node ) ; } else { if ( $ this -> isRed ( $ node -> left ( ) ) ) { $ node = $ this -> rotateRight ( $ node ) ; } if ( $ comp === 0 && $ node -> right ( ) === null ) { return null ; } $ node = $ this -> nodeRemoveRight ( $ key , $ node ) ; } return $ this -> balanceOnRemove ( $ node ) ; } | Deletes a node by key and subtree |
20,601 | protected function nodeRemoveLeft ( $ key , RedBlackNode $ node ) : RedBlackNode { if ( ! $ this -> isRed ( $ node -> left ( ) ) && ! $ this -> isRed ( $ node -> left ( ) -> left ( ) ) ) { $ node = $ this -> moveRedLeft ( $ node ) ; } $ node -> setLeft ( $ this -> nodeRemove ( $ key , $ node -> left ( ) ) ) ; return $ node ; } | Deletes a node to the left by key and subtree |
20,602 | protected function nodeRemoveRight ( $ key , RedBlackNode $ node ) : RedBlackNode { if ( ! $ this -> isRed ( $ node -> right ( ) ) && ! $ this -> isRed ( $ node -> right ( ) -> left ( ) ) ) { $ node = $ this -> moveRedRight ( $ node ) ; } if ( $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) === 0 ) { $ link = $ this -> nodeMin ( $ node -> right ( ) ) ; $ node -> setKey ( $ link -> key ( ) ) ; $ node -> setValue ( $ link -> value ( ) ) ; $ node -> setRight ( $ this -> nodeRemoveMin ( $ node -> right ( ) ) ) ; } else { $ node -> setRight ( $ this -> nodeRemove ( $ key , $ node -> right ( ) ) ) ; } return $ node ; } | Deletes a node to the right by key and subtree |
20,603 | protected function fillKeys ( Queue $ queue , $ lo , $ hi , ? RedBlackNode $ node ) : void { if ( $ node === null ) { return ; } $ complo = $ this -> comparator -> compare ( $ lo , $ node -> key ( ) ) ; $ comphi = $ this -> comparator -> compare ( $ hi , $ node -> key ( ) ) ; if ( $ complo < 0 ) { $ this -> fillKeys ( $ queue , $ lo , $ hi , $ node -> left ( ) ) ; } if ( $ complo <= 0 && $ comphi >= 0 ) { $ queue -> enqueue ( $ node -> key ( ) ) ; } if ( $ comphi > 0 ) { $ this -> fillKeys ( $ queue , $ lo , $ hi , $ node -> right ( ) ) ; } } | Fills a queue with keys between lo and hi in a subtree |
20,604 | protected function nodeMin ( RedBlackNode $ node ) : RedBlackNode { if ( $ node -> left ( ) === null ) { return $ node ; } return $ this -> nodeMin ( $ node -> left ( ) ) ; } | Retrieves the node with the minimum key in a subtree |
20,605 | protected function nodeMax ( RedBlackNode $ node ) : RedBlackNode { if ( $ node -> right ( ) === null ) { return $ node ; } return $ this -> nodeMax ( $ node -> right ( ) ) ; } | Retrieves the node with the maximum key in a subtree |
20,606 | protected function nodeRemoveMin ( RedBlackNode $ node ) : ? RedBlackNode { if ( $ node -> left ( ) === null ) { return null ; } if ( ! $ this -> isRed ( $ node -> left ( ) ) && ! $ this -> isRed ( $ node -> left ( ) -> left ( ) ) ) { $ node = $ this -> moveRedLeft ( $ node ) ; } $ node -> setLeft ( $ this -> nodeRemoveMin ( $ node -> left ( ) ) ) ; return $ this -> balanceOnRemove ( $ node ) ; } | Removes the node with the minimum key in a subtree |
20,607 | protected function nodeRemoveMax ( RedBlackNode $ node ) : ? RedBlackNode { if ( $ this -> isRed ( $ node -> left ( ) ) ) { $ node = $ this -> rotateRight ( $ node ) ; } if ( $ node -> right ( ) === null ) { return null ; } if ( ! $ this -> isRed ( $ node -> right ( ) ) && ! $ this -> isRed ( $ node -> right ( ) -> left ( ) ) ) { $ node = $ this -> moveRedRight ( $ node ) ; } $ node -> setRight ( $ this -> nodeRemoveMax ( $ node -> right ( ) ) ) ; return $ this -> balanceOnRemove ( $ node ) ; } | Removes the node with the maximum key in a subtree |
20,608 | protected function nodeFloor ( $ key , ? RedBlackNode $ node ) : ? RedBlackNode { if ( $ node === null ) { return null ; } $ comp = $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) ; if ( $ comp === 0 ) { return $ node ; } if ( $ comp < 0 ) { return $ this -> nodeFloor ( $ key , $ node -> left ( ) ) ; } $ right = $ this -> nodeFloor ( $ key , $ node -> right ( ) ) ; if ( $ right !== null ) { return $ right ; } return $ node ; } | Retrieves the node with the largest key < = to a key in a subtree |
20,609 | protected function nodeCeiling ( $ key , ? RedBlackNode $ node ) : ? RedBlackNode { if ( $ node === null ) { return null ; } $ comp = $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) ; if ( $ comp === 0 ) { return $ node ; } if ( $ comp > 0 ) { return $ this -> nodeCeiling ( $ key , $ node -> right ( ) ) ; } $ left = $ this -> nodeCeiling ( $ key , $ node -> left ( ) ) ; if ( $ left !== null ) { return $ left ; } return $ node ; } | Retrieves the node with the smallest key > = to a key in a subtree |
20,610 | protected function nodeRank ( $ key , ? RedBlackNode $ node ) : int { if ( $ node === null ) { return 0 ; } $ comp = $ this -> comparator -> compare ( $ key , $ node -> key ( ) ) ; if ( $ comp < 0 ) { return $ this -> nodeRank ( $ key , $ node -> left ( ) ) ; } if ( $ comp > 0 ) { return 1 + $ this -> nodeSize ( $ node -> left ( ) ) + $ this -> nodeRank ( $ key , $ node -> right ( ) ) ; } return $ this -> nodeSize ( $ node -> left ( ) ) ; } | Retrieves the rank for a key in a subtree |
20,611 | protected function nodeSelect ( int $ rank , RedBlackNode $ node ) : RedBlackNode { $ size = $ this -> nodeSize ( $ node -> left ( ) ) ; if ( $ size > $ rank ) { return $ this -> nodeSelect ( $ rank , $ node -> left ( ) ) ; } if ( $ size < $ rank ) { return $ this -> nodeSelect ( $ rank - $ size - 1 , $ node -> right ( ) ) ; } return $ node ; } | Retrieves the node with the key of a given rank in a subtree |
20,612 | protected function rotateLeft ( RedBlackNode $ node ) : RedBlackNode { $ link = $ node -> right ( ) ; $ node -> setRight ( $ link -> left ( ) ) ; $ link -> setLeft ( $ node ) ; $ link -> setColor ( $ node -> color ( ) ) ; $ node -> setColor ( RedBlackNode :: RED ) ; $ link -> setSize ( $ node -> size ( ) ) ; $ node -> setSize ( 1 + $ this -> nodeSize ( $ node -> left ( ) ) + $ this -> nodeSize ( $ node -> right ( ) ) ) ; return $ link ; } | Rotates a right - learning link to the left |
20,613 | protected function flipColors ( RedBlackNode $ node ) : void { $ node -> setColor ( ! ( $ node -> color ( ) ) ) ; $ node -> left ( ) -> setColor ( ! ( $ node -> left ( ) -> color ( ) ) ) ; $ node -> right ( ) -> setColor ( ! ( $ node -> right ( ) -> color ( ) ) ) ; } | Flips the colors of a node and its two children |
20,614 | protected function moveRedLeft ( RedBlackNode $ node ) : RedBlackNode { $ this -> flipColors ( $ node ) ; if ( $ this -> isRed ( $ node -> right ( ) -> left ( ) ) ) { $ node -> setRight ( $ this -> rotateRight ( $ node -> right ( ) ) ) ; $ node = $ this -> rotateLeft ( $ node ) ; $ this -> flipColors ( $ node ) ; } return $ node ; } | Makes a left link or child red |
20,615 | protected function moveRedRight ( RedBlackNode $ node ) : RedBlackNode { $ this -> flipColors ( $ node ) ; if ( $ this -> isRed ( $ node -> left ( ) -> left ( ) ) ) { $ node = $ this -> rotateRight ( $ node ) ; $ this -> flipColors ( $ node ) ; } return $ node ; } | Makes a right link or child red |
20,616 | protected function balanceOnInsert ( RedBlackNode $ node ) : RedBlackNode { if ( $ this -> isRed ( $ node -> right ( ) ) && ! $ this -> isRed ( $ node -> left ( ) ) ) { $ node = $ this -> rotateLeft ( $ node ) ; } if ( $ this -> isRed ( $ node -> left ( ) ) && $ this -> isRed ( $ node -> left ( ) -> left ( ) ) ) { $ node = $ this -> rotateRight ( $ node ) ; } if ( $ this -> isRed ( $ node -> left ( ) ) && $ this -> isRed ( $ node -> right ( ) ) ) { $ this -> flipColors ( $ node ) ; } $ node -> setSize ( 1 + $ this -> nodeSize ( $ node -> left ( ) ) + $ this -> nodeSize ( $ node -> right ( ) ) ) ; return $ node ; } | Restores red - black tree invariant on insert |
20,617 | public function to ( string ... $ pathParts ) : string { return $ this -> rootpath . DIRECTORY_SEPARATOR . join ( DIRECTORY_SEPARATOR , $ pathParts ) ; } | returns absolute path to given local path |
20,618 | private function detectRootPath ( ) : string { static $ rootpath = null ; if ( null === $ rootpath ) { if ( \ Phar :: running ( ) !== '' ) { $ rootpath = dirname ( \ Phar :: running ( false ) ) ; } elseif ( file_exists ( __DIR__ . '/../../../../../autoload.php' ) ) { $ rootpath = realpath ( __DIR__ . '/../../../../../../' ) ; } else { $ rootpath = realpath ( __DIR__ . '/../../../' ) ; } } return $ rootpath ; } | detects root path |
20,619 | public function getRouteParams ( ) { if ( empty ( $ this -> routeParams ) ) { $ this -> routeParams = Base :: instance ( ) -> get ( 'PARAMS' ) ; unset ( $ this -> routeParams [ 0 ] ) ; } return $ this -> routeParams ; } | Get route params |
20,620 | public function getRequestPage ( $ default = 1 ) { if ( empty ( $ this -> requestPage ) ) { $ this -> requestPage = abs ( $ this -> getRequestArg ( $ this -> pageArgName , $ default ) ) ; } return $ this -> requestPage ; } | Get request page |
20,621 | public function path ( $ disable , $ page ) { if ( $ disable ) { return '#' ; } return Route :: instance ( ) -> build ( $ this -> getRoute ( ) , $ this -> getRouteParams ( ) , [ $ this -> pageArgName => $ page ] + ( $ _GET ? : [ ] ) ) ; } | Build pagination route |
20,622 | protected function _ ( $ key , $ group = '' , $ p1 = '' , $ p2 = '' , $ p3 = '' , $ p4 = '' , $ p5 = '' ) { return $ this -> getText ( $ key , $ group , $ p1 , $ p2 , $ p3 , $ p4 , $ p5 ) ; } | Shortcut for getText function |
20,623 | public function updateCMSFields ( FieldList $ fields ) { $ fields -> addFieldToTab ( 'Root.Main' , $ field = new OptionsetField ( 'DefaultPreviewMode' , _t ( 'UserPreviewPreference.DEFAULT_MODE' , '_Default Preview Mode' ) , array ( 'content' => _t ( 'UserPreviewPreference.CONTENT_MODE' , '_Content Mode: Only menu and content areas are shown' ) , 'split' => _t ( 'UserPreviewPreference.SPLIT_MODE' , '_Split Mode: Side by Side editing and previewing' ) , 'preview' => _t ( 'UserPreviewPreference.PREVIEW_MODE' , '_Preview Mode: Only menu and preview areas are shown' ) ) , Config :: inst ( ) -> get ( 'UserPreviewPreference' , 'DefaultMode' ) ) ) ; if ( Controller :: curr ( ) -> getRequest ( ) -> getSession ( ) -> get ( 'ShowPreviewSettingChangeReload' ) == true ) { $ field -> setMessage ( _t ( 'UserPreviewPreference.CHANGE_REFRESH' , '_You have updated your preview preference, you must refresh your browser to see the updated setting' ) , 'warning' ) ; Requirements :: javascript ( 'webbuilders-group/silverstripe-cmspreviewpreference: javascript/clear-local-preference.js' ) ; if ( $ this -> isSaving == false ) { Controller :: curr ( ) -> getRequest ( ) -> getSession ( ) -> clear ( 'ShowPreviewSettingChangeReload' ) ; } } } | Updates the fields used in the cms |
20,624 | public function onBeforeWrite ( ) { parent :: onBeforeWrite ( ) ; if ( empty ( $ this -> owner -> DefaultPreviewMode ) ) { $ this -> owner -> DefaultPreviewMode = Config :: inst ( ) -> get ( 'UserPreviewPreference' , 'DefaultMode' ) ; } if ( $ this -> owner -> isChanged ( 'DefaultPreviewMode' ) ) { Controller :: curr ( ) -> getRequest ( ) -> getSession ( ) -> set ( 'ShowPreviewSettingChangeReload' , true ) ; $ this -> isSaving = true ; } } | Ensures config defaults are enforced on write |
20,625 | public function where ( $ field , $ condition = false , $ operator = '=' ) { if ( func_num_args ( ) >= 2 ) { $ this -> where -> addCondition ( $ field , $ condition , $ operator ) ; } else { $ this -> where -> addCondition ( $ field ) ; } return $ this ; } | Sets the where conditions for the query . |
20,626 | public function orWhere ( $ field , $ condition = false , $ operator = '=' ) { if ( func_num_args ( ) >= 2 ) { $ this -> where -> addOrCondition ( $ field , $ condition , $ operator ) ; } else { $ this -> where -> addOrCondition ( $ field ) ; } return $ this ; } | Adds a where or condition to the query . |
20,627 | public function whereInfix ( $ field , $ operator = '=' , $ condition = false ) { $ numArgs = func_num_args ( ) ; if ( $ numArgs > 2 ) { $ this -> where -> addCondition ( $ field , $ condition , $ operator ) ; } elseif ( $ numArgs == 2 ) { $ this -> where -> addCondition ( $ field , $ operator , '=' ) ; } else { $ this -> where -> addCondition ( $ field ) ; } return $ this ; } | Sets the where conditions for the query with infix style arguments . |
20,628 | public function orWhereInfix ( $ field , $ operator = '=' , $ condition = false ) { $ numArgs = func_num_args ( ) ; if ( $ numArgs > 2 ) { $ this -> where -> addOrCondition ( $ field , $ condition , $ operator ) ; } elseif ( $ numArgs == 2 ) { $ this -> where -> addOrCondition ( $ field , $ operator , '=' ) ; } else { $ this -> where -> addOrCondition ( $ field ) ; } return $ this ; } | Adds a where or condition to the query with infix style arguments . |
20,629 | public function not ( $ field , $ condition = true ) { $ this -> where -> addCondition ( $ field , $ condition , '<>' ) ; return $ this ; } | Adds a where not condition to the query . |
20,630 | public function between ( $ field , $ a , $ b ) { $ this -> where -> addBetweenCondition ( $ field , $ a , $ b ) ; return $ this ; } | Adds a where between condition to the query . |
20,631 | public function notBetween ( $ field , $ a , $ b ) { $ this -> where -> addNotBetweenCondition ( $ field , $ a , $ b ) ; return $ this ; } | Adds a where not between condition to the query . |
20,632 | public function newAction ( ) { $ entity = new Brand ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; } | Displays a form to create a new Brand entity . |
20,633 | public function create ( string $ file ) : ModularParser { $ clone = clone $ this ; $ clone -> valid = null ; $ clone -> file = false ; $ clone -> class = null ; return $ clone -> setFileToLoad ( $ file ) ; } | Create Instance ModularParser |
20,634 | public function cloneRepository ( $ uri , $ folder = null , $ branch = null ) { $ command = new Command ; $ command -> binary ( 'git' ) -> argument ( 'clone' ) -> argument ( $ uri ) ; if ( null !== $ folder ) { $ command -> argument ( $ folder ) ; } if ( null !== $ branch ) { $ command -> option ( 'branch' , $ branch ) ; } return 0 === $ this -> execute ( $ command ) ; } | Clones a git repository . |
20,635 | public function build ( $ locale , $ domain = 'gui' ) { $ cache = new ConfigCache ( $ this -> cacheDir . '/translations-' . $ locale . '.js' , $ this -> debug ) ; if ( ! $ cache -> isFresh ( ) ) { $ content = $ this -> buildContent ( $ locale , $ domain ) ; $ cache -> write ( $ content -> getContent ( ) , $ content -> getResources ( ) ) ; if ( ! $ this -> debug ) { $ this -> compressor -> compressFile ( ( string ) $ cache ) ; } } return new Asset ( ( string ) $ cache ) ; } | Get all Translations for the given section . |
20,636 | public static function move_callback ( $ from , $ to ) { if ( static :: $ with_ftp ) { return static :: $ with_ftp -> upload ( $ from , $ to , \ Config :: get ( 'upload.ftp_mode' ) , \ Config :: get ( 'upload.ftp_permissions' ) ) ; } return false ; } | Move callback function custom method to move an uploaded file . In Fuel 1 . x this method is used for FTP uploads only |
20,637 | public static function get_files ( $ index = null ) { is_string ( $ index ) and $ index = str_replace ( ':' , '.' , $ index ) ; $ files = static :: $ upload -> getValidFiles ( $ index ) ; $ result = array ( ) ; foreach ( $ files as $ file ) { $ data = array ( ) ; foreach ( $ file as $ item => $ value ) { $ item == 'element' and $ item = 'field' ; $ item == 'tmp_name' and $ item = 'file' ; $ item == 'filename' and $ item = 'saved_as' ; $ item == 'path' and $ item = 'saved_to' ; $ data [ $ item ] = $ value ; } $ data [ 'field' ] = str_replace ( '.' , ':' , $ data [ 'field' ] ) ; $ data [ 'error' ] = ! $ file -> isValid ( ) ; $ data [ 'errors' ] = array ( ) ; $ result [ ] = $ data ; } if ( func_num_args ( ) and count ( $ result ) == 1 ) { return reset ( $ result ) ; } else { return $ result ; } } | Get the list of validated files |
20,638 | public static function get_errors ( $ index = null ) { is_string ( $ index ) and $ index = str_replace ( ':' , '.' , $ index ) ; $ files = static :: $ upload -> getInvalidFiles ( $ index ) ; $ result = array ( ) ; foreach ( $ files as $ file ) { $ data = array ( ) ; foreach ( $ file as $ item => $ value ) { $ item == 'element' and $ item = 'field' ; $ item == 'tmp_name' and $ item = 'file' ; $ item == 'filename' and $ item = 'saved_as' ; $ item == 'path' and $ item = 'saved_to' ; $ data [ $ item ] = $ value ; } $ data [ 'field' ] = str_replace ( '.' , ':' , $ data [ 'field' ] ) ; $ data [ 'error' ] = ! $ file -> isValid ( ) ; $ data [ 'errors' ] = array ( ) ; foreach ( $ file -> getErrors ( ) as $ error ) { $ data [ 'errors' ] [ ] = array ( 'error' => $ error -> getError ( ) , 'message' => $ error -> getMessage ( ) ) ; } $ result [ ] = $ data ; } if ( func_num_args ( ) and count ( $ result ) == 1 ) { return reset ( $ result ) ; } else { return $ result ; } } | Get the list of non - validated files |
20,639 | public static function process ( $ config = array ( ) ) { foreach ( static :: $ upload -> getAllFiles ( ) as $ file ) { $ file -> setConfig ( $ config ) ; $ file -> validate ( ) ; } } | Process the uploaded files and run the validation |
20,640 | public static function with_ftp ( $ config = 'default' , $ connect = true ) { if ( static :: $ with_ftp = \ Ftp :: forge ( $ config , $ connect ) ) { static :: $ upload -> setConfig ( 'moveCallback' , '\\Upload\\move_callback' ) ; } else { static :: $ upload -> setConfig ( 'moveCallback' , null ) ; } } | Upload files with FTP |
20,641 | protected function loadDependencies ( ) { if ( ! $ this -> validate ) { $ this -> validate = Validate :: getInstance ( ) ; if ( ! $ this -> config ) { try { if ( class_exists ( '\\SimpleComplex\\Config\\EnvSectionedConfig' ) ) { $ this -> config = call_user_func ( '\\SimpleComplex\\Config\\EnvSectionedConfig::getInstance' ) ; } else { $ this -> config = new SectionedMap ( ) ; } } catch ( \ Throwable $ ignore ) { $ this -> config = new SectionedMap ( ) ; } } if ( ! $ this -> unicode ) { $ this -> unicode = Unicode :: getInstance ( ) ; } if ( ! $ this -> sanitize ) { $ this -> sanitize = Sanitize :: getInstance ( ) ; } } } | Load dependencies on demand . |
20,642 | public function variable ( $ subject , $ options = [ ] ) : Inspector { $ this -> loadDependencies ( ) ; $ options [ 'kind' ] = 'variable' ; $ class_inspector = static :: CLASS_INSPECTOR ; return new $ class_inspector ( $ this , $ subject , $ options ) ; } | Force variable inspection even if subject is a throwable . |
20,643 | public function setContent ( string $ content ) : void { $ temp = $ this -> root_path . DIRECTORY_SEPARATOR . $ content ; $ this -> view -> setContent ( is_file ( $ temp ) ? $ temp : $ content ) ; } | passes content to our view |
20,644 | public function redirect ( string $ url ) : void { if ( ! filter_var ( $ url , FILTER_VALIDATE_URL ) ) { throw new ResponseException ( "Invalid URL: $url" , ResponseException :: INVALID_URL ) ; } $ this -> setType ( "redirect" ) ; $ this -> data [ "url" ] = $ url ; } | sets the appropriate type and data for a redirection |
20,645 | public function bindRoute ( string $ templateDir ) { $ this -> routeBindings = [ ] ; if ( strlen ( $ templateDir ) === 0 ) return ; $ dirsOrVars = explode ( '/' , trim ( $ templateDir , '/' ) ) ; $ varValues = explode ( '/' , trim ( $ this -> path , '/' ) ) ; for ( $ i = 0 ; $ i < count ( $ dirsOrVars ) ; $ i ++ ) { $ dirOrVar = $ dirsOrVars [ $ i ] ; if ( $ dirOrVar [ 0 ] !== '$' ) continue ; $ boundVar = substr ( $ dirOrVar , 1 ) ; $ extStart = strpos ( $ boundVar , '.' ) ; if ( $ extStart !== false ) { $ boundVar = substr ( $ boundVar , 0 , $ extStart ) ; } $ this -> routeBindings [ $ boundVar ] = $ varValues [ $ i ] ; } } | Takes in a template directory and matches variables with values in the path . Should not be called outside Babble core! |
20,646 | public function get ( $ name , $ usePeeringServiceManagers = true ) { try { return parent :: get ( $ name , $ usePeeringServiceManagers ) ; } catch ( ServiceNotFoundException $ e ) { if ( isset ( $ this -> _decoree ) ) return $ this -> getDecoree ( ) -> get ( $ name , $ usePeeringServiceManagers ) ; else throw $ e ; } } | Retrieve a registered instance |
20,647 | protected static function rawData ( $ object ) { if ( is_object ( $ object ) ) { $ hash = spl_object_hash ( $ object ) ; if ( isset ( self :: $ rawCheck [ $ hash ] ) ) { return array ( '#recursion#' => $ hash ) ; } self :: $ rawCheck [ $ hash ] = true ; } $ object = ( array ) $ object ; foreach ( $ object as $ key => $ value ) { if ( is_array ( $ value ) || is_object ( $ value ) ) { $ object [ $ key ] = self :: rawData ( $ value ) ; } } return ( object ) $ object ; } | Convert data to raw object |
20,648 | public function logException ( Exception $ exception , $ priority = Logger :: CRIT ) { $ logger = $ this -> getServiceLocator ( ) -> get ( 'Zork\Log\LoggerManager' ) ; if ( $ logger -> hasLogger ( 'exception' ) ) { $ logger -> getLogger ( 'exception' ) -> log ( $ priority , '<pre>' . $ exception . PHP_EOL . '</pre>' . PHP_EOL ) ; } } | Log a single exception |
20,649 | private function getUrlToOldApi ( $ method , array $ params , $ format ) { $ queryString = sprintf ( '?apikey=%s&format=%s&method=%s%s' , $ this -> getApiKey ( ) , $ format , $ method , $ this -> paramsQueryStringBuilder ( $ params ) ) ; return sprintf ( $ this :: API_URL , $ this -> getDc ( ) , $ this -> getApiVersion ( ) , $ queryString ) ; } | Gets the url for Mailchimp API version < 2 . 0 |
20,650 | private function getUrl ( $ method ) { return sprintf ( $ this :: API_URL , $ this -> getDc ( ) , $ this -> getApiVersion ( ) , $ method ) ; } | Gets the url for Mailchimp API version > = 2 . 0 |
20,651 | protected function readValue ( User $ user , string $ attribute ) : void { $ user -> $ attribute = $ this -> prompt ( mb_convert_case ( $ attribute , MB_CASE_TITLE , 'utf-8' ) . ':' , [ 'validator' => function ( $ input , & $ error ) use ( $ user , $ attribute ) { $ user -> $ attribute = $ input ; if ( $ user -> validate ( [ $ attribute ] ) ) { return true ; } else { $ error = implode ( ',' , $ user -> getErrors ( $ attribute ) ) ; return false ; } } , ] ) ; } | Get the value of the console . |
20,652 | protected function log ( bool $ success ) : void { if ( $ success ) { $ this -> stdout ( 'Success!' , Console :: FG_GREEN , Console :: BOLD ) ; } else { $ this -> stderr ( 'Error!' , Console :: FG_RED , Console :: BOLD ) ; } $ this -> stdout ( PHP_EOL ) ; } | Console log . |
20,653 | public function actionRequest ( ) { if ( ! $ this -> module -> enablePasswordRecovery ) { throw new NotFoundHttpException ( ) ; } $ model = Yii :: createObject ( [ 'class' => RecoveryForm :: className ( ) , 'scenario' => 'request' , ] ) ; $ event = $ this -> getFormEvent ( $ model ) ; $ this -> performAjaxValidation ( $ model ) ; $ this -> trigger ( self :: EVENT_BEFORE_REQUEST , $ event ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> sendRecoveryMessage ( ) ) { $ this -> trigger ( self :: EVENT_AFTER_REQUEST , $ event ) ; return $ this -> render ( '/message' , [ 'title' => Yii :: t ( 'users' , 'Recovery message sent' ) , 'module' => $ this -> module , ] ) ; } return $ this -> render ( 'request' , [ 'model' => $ model , ] ) ; } | Shows page where user can request password recovery . |
20,654 | public function actionReset ( $ id , $ code ) { if ( ! $ this -> module -> enablePasswordRecovery ) { throw new NotFoundHttpException ( ) ; } $ token = Token :: find ( ) -> where ( [ 'userId' => $ id , 'code' => $ code , 'type' => Token :: TYPE_RECOVERY ] ) -> one ( ) ; $ event = $ this -> getResetPasswordEvent ( $ token ) ; $ this -> trigger ( self :: EVENT_BEFORE_TOKEN_VALIDATE , $ event ) ; if ( $ token === null || $ token -> isExpired || $ token -> user === null ) { $ this -> trigger ( self :: EVENT_AFTER_TOKEN_VALIDATE , $ event ) ; Yii :: $ app -> session -> setFlash ( 'danger' , Yii :: t ( 'users' , 'Recovery link is invalid or expired. Please try requesting a new one.' ) ) ; return $ this -> render ( '/message' , [ 'title' => Yii :: t ( 'users' , 'Invalid or expired link' ) , 'module' => $ this -> module , ] ) ; } $ model = Yii :: createObject ( [ 'class' => RecoveryForm :: className ( ) , 'scenario' => 'reset' , ] ) ; $ event -> setForm ( $ model ) ; $ this -> performAjaxValidation ( $ model ) ; $ this -> trigger ( self :: EVENT_BEFORE_RESET , $ event ) ; if ( $ model -> load ( Yii :: $ app -> getRequest ( ) -> post ( ) ) && $ model -> resetPassword ( $ token ) ) { $ this -> trigger ( self :: EVENT_AFTER_RESET , $ event ) ; return $ this -> render ( '/message' , [ 'title' => Yii :: t ( 'users' , 'Password has been changed' ) , 'module' => $ this -> module , ] ) ; } return $ this -> render ( 'reset' , [ 'model' => $ model , ] ) ; } | Displays page where user can reset password . |
20,655 | public function hasVisibleChildren ( ) { if ( is_array ( $ this -> children ) && count ( $ this -> children ) ) { foreach ( $ this -> children as $ child ) { if ( ! $ child -> isHidden ( ) ) { return true ; } } } return false ; } | Tests if category has any visible children . |
20,656 | public function processActions ( ) { $ Eresus = Eresus_CMS :: getLegacyKernel ( ) ; $ this -> parse ( ) ; $ actionsElement = $ this -> xml -> getElementsByTagNameNS ( self :: NS , 'actions' ) ; if ( $ actionsElement ) { $ actions = $ actionsElement -> item ( 0 ) -> childNodes ; for ( $ i = 0 ; $ i < $ actions -> length ; $ i ++ ) { $ action = $ actions -> item ( $ i ) ; if ( $ action -> nodeType == XML_ELEMENT_NODE ) { $ this -> processAction ( $ action ) ; } } } if ( $ this -> redirect ) { $ url = $ this -> redirect ; if ( ! is_null ( $ this -> marker ) ) { $ url .= '#' . $ this -> marker ; } HTTP :: redirect ( $ url ) ; } elseif ( ! $ this -> html ) { HTTP :: redirect ( $ Eresus -> request [ 'referer' ] ) ; } return $ this -> html ; } | Process form actions |
20,657 | protected function setActionAttribute ( ) { $ Eresus = Eresus_CMS :: getLegacyKernel ( ) ; $ form = $ this -> xml -> getElementsByTagName ( 'form' ) -> item ( 0 ) ; $ url = $ Eresus -> request [ 'path' ] ; $ markers = $ this -> xml -> getElementsByTagNameNS ( self :: NS , 'marker' ) ; $ redirects = $ this -> xml -> getElementsByTagNameNS ( self :: NS , 'redirect' ) ; if ( $ markers -> length > 0 && 0 == $ redirects -> length ) { $ marker = $ markers -> item ( $ markers -> length - 1 ) ; $ url .= '#' . $ marker -> getAttribute ( 'value' ) ; } $ form -> setAttribute ( 'action' , $ url ) ; } | Set form s action attribute |
20,658 | protected function setActionTags ( ) { $ form = $ this -> xml -> getElementsByTagName ( 'form' ) -> item ( 0 ) ; $ div = $ this -> xml -> createElement ( 'div' ) ; $ input = $ this -> xml -> createElement ( 'input' ) ; $ input -> setAttribute ( 'type' , 'hidden' ) ; $ input -> setAttribute ( 'name' , 'ext' ) ; $ input -> setAttribute ( 'value' , $ this -> owner -> name ) ; $ div -> appendChild ( $ input ) ; $ input = $ this -> xml -> createElement ( 'input' ) ; $ input -> setAttribute ( 'type' , 'hidden' ) ; $ input -> setAttribute ( 'name' , 'form' ) ; $ input -> setAttribute ( 'value' , $ this -> name ) ; $ div -> appendChild ( $ input ) ; $ form -> appendChild ( $ div ) ; } | Adds hidden inputs to form |
20,659 | protected function getFormData ( ) { $ data = array ( ) ; $ inputTagNames = array ( 'input' , 'textarea' , 'select' ) ; $ skipNames = array ( 'ext' , 'form' ) ; $ element = $ this -> xml -> getElementsByTagName ( 'form' ) -> item ( 0 ) ; $ elements = $ element -> getElementsByTagName ( '*' ) ; for ( $ i = 0 ; $ i < $ elements -> length ; $ i ++ ) { $ element = $ elements -> item ( $ i ) ; $ isElement = $ element -> nodeType == XML_ELEMENT_NODE ; $ isInputTag = $ isElement && in_array ( $ element -> nodeName , $ inputTagNames ) ; if ( $ isInputTag ) { $ name = $ element -> getAttribute ( 'name' ) ; if ( in_array ( $ name , $ skipNames ) ) { continue ; } if ( $ name ) { if ( $ element -> getAttribute ( 'type' ) == 'file' ) { $ data [ $ name ] [ 'file' ] = $ _FILES [ $ name ] ; } else { $ data [ $ name ] [ 'data' ] = arg ( $ name ) ; } $ data [ $ name ] [ 'label' ] = $ this -> getLabelAttr ( $ element ) ; if ( ! $ data [ $ name ] [ 'label' ] ) { $ data [ $ name ] [ 'label' ] = $ name ; } switch ( $ element -> nodeName ) { case 'input' : switch ( $ element -> getAttribute ( 'type' ) ) { case 'checkbox' : $ data [ $ name ] [ 'data' ] = $ data [ $ name ] [ 'data' ] ? strYes : strNo ; break ; } break ; } } } } return $ data ; } | Return posted form data |
20,660 | protected function processAction ( DOMNode $ action ) { $ actionName = substr ( $ action -> nodeName , strlen ( $ action -> lookupPrefix ( self :: NS ) ) + 1 ) ; $ methodName = 'action' . $ actionName ; if ( method_exists ( $ this , $ methodName ) ) { $ this -> $ methodName ( $ action ) ; } } | Process action directive |
20,661 | protected function actionRedirect ( $ action ) { if ( $ this -> redirect ) { return ; } $ this -> redirect = $ action -> getAttribute ( 'uri' ) ; $ page = Eresus_Kernel :: app ( ) -> getPage ( ) ; $ this -> redirect = $ page -> replaceMacros ( $ this -> redirect ) ; } | Process redirect action |
20,662 | protected function actionHtml ( $ action ) { $ elements = $ action -> childNodes ; if ( $ elements -> length ) { $ html = '' ; for ( $ i = 0 ; $ i < $ elements -> length ; $ i ++ ) { $ html .= $ this -> xml -> saveXML ( $ elements -> item ( $ i ) ) ; } $ this -> html .= $ html ; } } | Process html action |
20,663 | public function edit_post_type ( ) { if ( ! isset ( $ _GET [ 'post_type' ] ) ) { $ this -> mf_flash ( 'Oops! something was wrong, you will be redirected a safe place in a few seconds' ) ; } $ post_type = $ this -> get_post_type ( $ _GET [ 'post_type' ] ) ; if ( ! $ post_type ) { $ this -> mf_flash ( 'error' ) ; } else { $ data = $ this -> fields_form ( ) ; $ post_type_support = array ( ) ; if ( isset ( $ post_type [ 'support' ] ) ) { foreach ( $ post_type [ 'support' ] as $ k => $ v ) { array_push ( $ post_type_support , $ k ) ; } $ data [ 'posttype_support' ] = $ post_type_support ; } $ post_type_taxonomy = array ( ) ; if ( isset ( $ post_type [ 'taxonomy' ] ) ) { foreach ( $ post_type [ 'taxonomy' ] as $ k => $ v ) { array_push ( $ post_type_taxonomy , $ k ) ; } $ data [ 'posttype_taxonomy' ] = $ post_type_taxonomy ; } $ perm = array ( 'core' , 'option' , 'label' ) ; foreach ( $ post_type as $ key => $ value ) { if ( in_array ( $ key , $ perm ) ) { foreach ( $ value as $ id => $ val ) { $ data [ $ key ] [ $ id ] [ 'value' ] = $ val ; } } } $ this -> form_post_type ( $ data ) ; } } | Edit post type |
20,664 | public function save_post_type ( ) { global $ mf_domain ; check_admin_referer ( 'form_post_type_posttype' ) ; if ( isset ( $ _POST [ 'mf_posttype' ] ) ) { $ mf = $ _POST [ 'mf_posttype' ] ; if ( $ mf [ 'core' ] [ 'id' ] ) { $ this -> update_post_type ( $ mf ) ; } else { if ( $ this -> new_posttype ( $ mf ) ) { } else { } } $ name = trim ( $ mf [ 'option' ] [ 'capability_type' ] ) ; if ( ! in_array ( $ name , array ( 'post' , 'page' ) ) && ! empty ( $ name ) ) { $ this -> _add_cap ( $ name ) ; } } $ this -> mf_redirect ( "mf_posttype" , "update_rewrite" , array ( "noheader" => "true" ) ) ; } | Save a Post Type |
20,665 | public function _add_cap ( $ name ) { $ caps = array ( 'publish_posts' => sprintf ( 'publish_%ss' , $ name ) , 'edit_posts' => sprintf ( 'edit_%ss' , $ name ) , 'edit_others_posts' => sprintf ( 'edit_others_%ss' , $ name ) , 'read_private_posts' => sprintf ( 'read_private_%ss' , $ name ) , 'edit_post' => sprintf ( 'edit_%s' , $ name ) , 'delete_post' => sprintf ( 'delete_%s' , $ name ) , 'read_post' => sprintf ( 'read_%s' , $ name ) ) ; $ role = get_role ( 'administrator' ) ; if ( ! in_array ( $ caps [ 'edit_post' ] , array_keys ( $ role -> capabilities ) ) ) { foreach ( $ caps as $ cap ) { $ role -> add_cap ( $ cap ) ; } } } | Add a news Capabilities for Administrator |
20,666 | public function get_post_type ( $ post_type ) { global $ wpdb ; $ query = $ wpdb -> prepare ( "SELECT * FROM " . MF_TABLE_POSTTYPES . " WHERE type = %s" , array ( $ post_type ) ) ; $ post_type = $ wpdb -> get_row ( $ query , ARRAY_A ) ; if ( $ post_type ) { $ post_type_id = $ post_type [ 'id' ] ; $ post_type = unserialize ( $ post_type [ 'arguments' ] ) ; $ post_type [ 'core' ] [ 'id' ] = $ post_type_id ; return $ post_type ; } return false ; } | get a specific post type using the post_type_id or the post_type_name |
20,667 | public function delete_post_type ( ) { global $ wpdb ; check_admin_referer ( 'delete_post_type_mf_posttype' ) ; if ( isset ( $ _GET [ 'post_type' ] ) ) { $ post_type = $ _GET [ 'post_type' ] ; if ( $ post_type ) { $ sql = $ wpdb -> prepare ( "DELETE FROM " . MF_TABLE_POSTTYPES . " WHERE type = '%s'" , $ post_type ) ; $ wpdb -> query ( $ sql ) ; $ sql_fields = $ wpdb -> prepare ( "DELETE FROM " . MF_TABLE_CUSTOM_GROUPS . " WHERE post_type = '%s'" , $ post_type ) ; $ wpdb -> query ( $ sql_fields ) ; $ sql_fields = $ wpdb -> prepare ( "DELETE FROM " . MF_TABLE_CUSTOM_FIELDS . " WHERE post_type = '%s'" , $ post_type ) ; $ wpdb -> query ( $ sql_fields ) ; $ this -> mf_redirect ( null , null , array ( 'message' => 'success' ) ) ; } } } | delete a post type |
20,668 | protected function findInPaths ( array $ paths , $ group , $ mode = null , $ exists = false ) { $ items = [ ] ; foreach ( $ paths as $ path ) { if ( $ this -> fs -> exists ( $ file = "{$path}/{$group}.php" ) ) { if ( $ exists ) return true ; $ items = array_merge_recursive ( $ this -> fs -> getRequire ( $ file ) , $ items ) ; } if ( $ mode and $ this -> fs -> exists ( $ file = "{$path}/{$mode}/{$group}.php" ) ) { if ( $ exists ) return true ; $ items = array_merge_recursive ( $ this -> fs -> getRequire ( $ file ) , $ items ) ; } } return $ items ; } | Get the path for the specified namespace |
20,669 | function FindFirstSets ( ) { for ( $ i = 0 ; $ i < $ this -> nsymbol ; $ i ++ ) { $ this -> symbols [ $ i ] -> lambda = false ; } for ( $ i = $ this -> nterminal ; $ i < $ this -> nsymbol ; $ i ++ ) { $ this -> symbols [ $ i ] -> firstset = array ( ) ; } do { $ progress = 0 ; for ( $ rp = $ this -> rule ; $ rp ; $ rp = $ rp -> next ) { if ( $ rp -> lhs -> lambda ) { continue ; } for ( $ i = 0 ; $ i < $ rp -> nrhs ; $ i ++ ) { $ sp = $ rp -> rhs [ $ i ] ; if ( $ sp -> type != PHP_ParserGenerator_Symbol :: TERMINAL || $ sp -> lambda === false ) { break ; } } if ( $ i === $ rp -> nrhs ) { $ rp -> lhs -> lambda = true ; $ progress = 1 ; } } } while ( $ progress ) ; do { $ progress = 0 ; for ( $ rp = $ this -> rule ; $ rp ; $ rp = $ rp -> next ) { $ s1 = $ rp -> lhs ; for ( $ i = 0 ; $ i < $ rp -> nrhs ; $ i ++ ) { $ s2 = $ rp -> rhs [ $ i ] ; if ( $ s2 -> type == PHP_ParserGenerator_Symbol :: TERMINAL ) { $ progress += isset ( $ s1 -> firstset [ $ s2 -> index ] ) ? 0 : 1 ; $ s1 -> firstset [ $ s2 -> index ] = 1 ; break ; } elseif ( $ s2 -> type == PHP_ParserGenerator_Symbol :: MULTITERMINAL ) { for ( $ j = 0 ; $ j < $ s2 -> nsubsym ; $ j ++ ) { $ progress += isset ( $ s1 -> firstset [ $ s2 -> subsym [ $ j ] -> index ] ) ? 0 : 1 ; $ s1 -> firstset [ $ s2 -> subsym [ $ j ] -> index ] = 1 ; } break ; } elseif ( $ s1 === $ s2 ) { if ( $ s1 -> lambda === false ) { break ; } } else { $ test = array_diff_key ( $ s2 -> firstset , $ s1 -> firstset ) ; if ( count ( $ test ) ) { $ progress ++ ; $ s1 -> firstset += $ test ; } if ( $ s2 -> lambda === false ) { break ; } } } } } while ( $ progress ) ; } | Find all nonterminals which will generate the empty string . Then go back and compute the first sets of every nonterminal . The first set is the set of all terminal symbols which can begin a string generated by that nonterminal . |
20,670 | private function buildshifts ( PHP_ParserGenerator_State $ stp ) { $ cfp = $ stp -> cfp ; for ( $ cfp = $ stp -> cfp ; $ cfp ; $ cfp = $ cfp -> next ) { $ cfp -> status = PHP_ParserGenerator_Config :: INCOMPLETE ; } for ( $ cfp = $ stp -> cfp ; $ cfp ; $ cfp = $ cfp -> next ) { if ( $ cfp -> status == PHP_ParserGenerator_Config :: COMPLETE ) { continue ; } if ( $ cfp -> dot >= $ cfp -> rp -> nrhs ) { continue ; } PHP_ParserGenerator_Config :: Configlist_reset ( ) ; $ sp = $ cfp -> rp -> rhs [ $ cfp -> dot ] ; $ bcfp = $ cfp ; for ( $ bcfp = $ cfp ; $ bcfp ; $ bcfp = $ bcfp -> next ) { if ( $ bcfp -> status == PHP_ParserGenerator_Config :: COMPLETE ) { continue ; } if ( $ bcfp -> dot >= $ bcfp -> rp -> nrhs ) { continue ; } $ bsp = $ bcfp -> rp -> rhs [ $ bcfp -> dot ] ; if ( ! PHP_ParserGenerator_Symbol :: same_symbol ( $ bsp , $ sp ) ) { continue ; } $ bcfp -> status = PHP_ParserGenerator_Config :: COMPLETE ; $ new = PHP_ParserGenerator_Config :: Configlist_addbasis ( $ bcfp -> rp , $ bcfp -> dot + 1 ) ; PHP_ParserGenerator_PropagationLink :: Plink_add ( $ new -> bplp , $ bcfp ) ; } $ newstp = $ this -> getstate ( ) ; if ( is_array ( $ newstp ) ) { $ this -> buildshifts ( $ newstp [ 0 ] ) ; $ newstp = $ newstp [ 0 ] ; } if ( $ sp -> type == PHP_ParserGenerator_Symbol :: MULTITERMINAL ) { for ( $ i = 0 ; $ i < $ sp -> nsubsym ; $ i ++ ) { PHP_ParserGenerator_Action :: Action_add ( $ stp -> ap , PHP_ParserGenerator_Action :: SHIFT , $ sp -> subsym [ $ i ] , $ newstp ) ; } } else { PHP_ParserGenerator_Action :: Action_add ( $ stp -> ap , PHP_ParserGenerator_Action :: SHIFT , $ sp , $ newstp ) ; } } } | Construct all successor states to the given state . A successor state is any state which can be reached by a shift action . |
20,671 | function FindLinks ( ) { foreach ( $ this -> sorted as $ info ) { $ info -> key -> stp = $ info -> data ; } for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { $ stp = $ this -> sorted [ $ i ] ; for ( $ cfp = $ stp -> data -> cfp ; $ cfp ; $ cfp = $ cfp -> next ) { for ( $ plp = $ cfp -> bplp ; $ plp ; $ plp = $ plp -> next ) { $ other = $ plp -> cfp ; PHP_ParserGenerator_PropagationLink :: Plink_add ( $ other -> fplp , $ cfp ) ; } } } } | Construct the propagation links |
20,672 | function resolve_conflict ( $ apx , $ apy , $ errsym ) { $ errcnt = 0 ; if ( $ apx -> sp !== $ apy -> sp ) { throw new Exception ( 'no conflict but resolve_conflict called' ) ; } if ( $ apx -> type == PHP_ParserGenerator_Action :: SHIFT && $ apy -> type == PHP_ParserGenerator_Action :: REDUCE ) { $ spx = $ apx -> sp ; $ spy = $ apy -> x -> precsym ; if ( $ spy === 0 || $ spx -> prec < 0 || $ spy -> prec < 0 ) { $ apy -> type = PHP_ParserGenerator_Action :: CONFLICT ; $ errcnt ++ ; } elseif ( $ spx -> prec > $ spy -> prec ) { $ apy -> type = PHP_ParserGenerator_Action :: RD_RESOLVED ; } elseif ( $ spx -> prec < $ spy -> prec ) { $ apx -> type = PHP_ParserGenerator_Action :: SH_RESOLVED ; } elseif ( $ spx -> prec === $ spy -> prec && $ spx -> assoc == PHP_ParserGenerator_Symbol :: RIGHT ) { $ apy -> type = PHP_ParserGenerator_Action :: RD_RESOLVED ; } elseif ( $ spx -> prec === $ spy -> prec && $ spx -> assoc == PHP_ParserGenerator_Symbol :: LEFT ) { $ apx -> type = PHP_ParserGenerator_Action :: SH_RESOLVED ; } else { if ( $ spx -> prec !== $ spy -> prec || $ spx -> assoc !== PHP_ParserGenerator_Symbol :: NONE ) { throw new Exception ( '$spx->prec !== $spy->prec || $spx->assoc !== PHP_ParserGenerator_Symbol::NONE' ) ; } $ apy -> type = PHP_ParserGenerator_Action :: CONFLICT ; $ errcnt ++ ; } } elseif ( $ apx -> type == PHP_ParserGenerator_Action :: REDUCE && $ apy -> type == PHP_ParserGenerator_Action :: REDUCE ) { $ spx = $ apx -> x -> precsym ; $ spy = $ apy -> x -> precsym ; if ( $ spx === 0 || $ spy === 0 || $ spx -> prec < 0 || $ spy -> prec < 0 || $ spx -> prec === $ spy -> prec ) { $ apy -> type = PHP_ParserGenerator_Action :: CONFLICT ; $ errcnt ++ ; } elseif ( $ spx -> prec > $ spy -> prec ) { $ apy -> type = PHP_ParserGenerator_Action :: RD_RESOLVED ; } elseif ( $ spx -> prec < $ spy -> prec ) { $ apx -> type = PHP_ParserGenerator_Action :: RD_RESOLVED ; } } else { if ( $ apx -> type !== PHP_ParserGenerator_Action :: SH_RESOLVED && $ apx -> type !== PHP_ParserGenerator_Action :: RD_RESOLVED && $ apx -> type !== PHP_ParserGenerator_Action :: CONFLICT && $ apy -> type !== PHP_ParserGenerator_Action :: SH_RESOLVED && $ apy -> type !== PHP_ParserGenerator_Action :: RD_RESOLVED && $ apy -> type !== PHP_ParserGenerator_Action :: CONFLICT ) { throw new Exception ( '$apx->type!== PHP_ParserGenerator_Action::SH_RESOLVED && $apx->type!== PHP_ParserGenerator_Action::RD_RESOLVED && $apx->type!== PHP_ParserGenerator_Action::CONFLICT && $apy->type!== PHP_ParserGenerator_Action::SH_RESOLVED && $apy->type!== PHP_ParserGenerator_Action::RD_RESOLVED && $apy->type!== PHP_ParserGenerator_Action::CONFLICT' ) ; } } return $ errcnt ; } | Resolve a conflict between the two given actions . If the conflict can t be resolve return non - zero . |
20,673 | function CompressTables ( ) { for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { $ stp = $ this -> sorted [ $ i ] -> data ; $ nbest = 0 ; $ rbest = 0 ; for ( $ ap = $ stp -> ap ; $ ap ; $ ap = $ ap -> next ) { if ( $ ap -> type != PHP_ParserGenerator_Action :: REDUCE ) { continue ; } $ rp = $ ap -> x ; if ( $ rp === $ rbest ) { continue ; } $ n = 1 ; for ( $ ap2 = $ ap -> next ; $ ap2 ; $ ap2 = $ ap2 -> next ) { if ( $ ap2 -> type != PHP_ParserGenerator_Action :: REDUCE ) { continue ; } $ rp2 = $ ap2 -> x ; if ( $ rp2 === $ rbest ) { continue ; } if ( $ rp2 === $ rp ) { $ n ++ ; } } if ( $ n > $ nbest ) { $ nbest = $ n ; $ rbest = $ rp ; } } if ( $ nbest < 1 ) { continue ; } for ( $ ap = $ stp -> ap ; $ ap ; $ ap = $ ap -> next ) { if ( $ ap -> type == PHP_ParserGenerator_Action :: REDUCE && $ ap -> x === $ rbest ) { break ; } } if ( $ ap === 0 ) { throw new Exception ( '$ap is not an object' ) ; } $ ap -> sp = PHP_ParserGenerator_Symbol :: Symbol_new ( "{default}" ) ; for ( $ ap = $ ap -> next ; $ ap ; $ ap = $ ap -> next ) { if ( $ ap -> type == PHP_ParserGenerator_Action :: REDUCE && $ ap -> x === $ rbest ) { $ ap -> type = PHP_ParserGenerator_Action :: NOT_USED ; } } $ stp -> ap = PHP_ParserGenerator_Action :: Action_sort ( $ stp -> ap ) ; } } | Reduce the size of the action tables if possible by making use of defaults . |
20,674 | function ResortStates ( ) { for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { $ stp = $ this -> sorted [ $ i ] -> data ; $ stp -> nTknAct = $ stp -> nNtAct = 0 ; $ stp -> iDflt = $ this -> nstate + $ this -> nrule ; $ stp -> iTknOfst = PHP_ParserGenerator_Data :: NO_OFFSET ; $ stp -> iNtOfst = PHP_ParserGenerator_Data :: NO_OFFSET ; for ( $ ap = $ stp -> ap ; $ ap ; $ ap = $ ap -> next ) { if ( $ this -> compute_action ( $ ap ) >= 0 ) { if ( $ ap -> sp -> index < $ this -> nterminal ) { $ stp -> nTknAct ++ ; } elseif ( $ ap -> sp -> index < $ this -> nsymbol ) { $ stp -> nNtAct ++ ; } else { $ stp -> iDflt = $ this -> compute_action ( $ ap ) ; } } } $ this -> sorted [ $ i ] = $ stp ; } $ save = $ this -> sorted [ 0 ] ; unset ( $ this -> sorted [ 0 ] ) ; usort ( $ this -> sorted , array ( 'PHP_ParserGenerator_State' , 'stateResortCompare' ) ) ; array_unshift ( $ this -> sorted , $ save ) ; for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { $ this -> sorted [ $ i ] -> statenum = $ i ; } } | Renumber and resort states so that states with fewer choices occur at the end . Except keep state 0 as the first state . |
20,675 | function compute_action ( $ ap ) { switch ( $ ap -> type ) { case PHP_ParserGenerator_Action :: SHIFT : $ act = $ ap -> x -> statenum ; break ; case PHP_ParserGenerator_Action :: REDUCE : $ act = $ ap -> x -> index + $ this -> nstate ; break ; case PHP_ParserGenerator_Action :: ERROR : $ act = $ this -> nstate + $ this -> nrule ; break ; case PHP_ParserGenerator_Action :: ACCEPT : $ act = $ this -> nstate + $ this -> nrule + 1 ; break ; default : $ act = - 1 ; break ; } return $ act ; } | Given an action compute the integer value for that action which is to be put in the action table of the generated machine . Return negative if no action should be generated . |
20,676 | function ReportOutput ( ) { $ fp = fopen ( $ this -> filenosuffix . ".out" , "wb" ) ; if ( ! $ fp ) { return ; } for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { $ stp = $ this -> sorted [ $ i ] ; fprintf ( $ fp , "State %d:\n" , $ stp -> statenum ) ; if ( $ this -> basisflag ) { $ cfp = $ stp -> bp ; } else { $ cfp = $ stp -> cfp ; } while ( $ cfp ) { if ( $ cfp -> dot == $ cfp -> rp -> nrhs ) { $ buf = sprintf ( '(%d)' , $ cfp -> rp -> index ) ; fprintf ( $ fp , ' %5s ' , $ buf ) ; } else { fwrite ( $ fp , ' ' ) ; } $ cfp -> ConfigPrint ( $ fp ) ; fwrite ( $ fp , "\n" ) ; if ( 0 ) { } if ( $ this -> basisflag ) { $ cfp = $ cfp -> bp ; } else { $ cfp = $ cfp -> next ; } } fwrite ( $ fp , "\n" ) ; for ( $ ap = $ stp -> ap ; $ ap ; $ ap = $ ap -> next ) { if ( $ ap -> PrintAction ( $ fp , 30 ) ) { fprintf ( $ fp , "\n" ) ; } } fwrite ( $ fp , "\n" ) ; } fclose ( $ fp ) ; } | Generate the Parse . out log file |
20,677 | private function tplt_open ( ) { $ templatename = $ this -> parser_template ? $ this -> parser_template : dirname ( dirname ( __FILE__ ) ) . DIRECTORY_SEPARATOR . "Lempar.php" ; $ buf = $ this -> filenosuffix . '.lt' ; if ( file_exists ( $ buf ) && is_readable ( $ buf ) ) { $ tpltname = $ buf ; } elseif ( file_exists ( $ templatename ) && is_readable ( $ templatename ) ) { $ tpltname = $ templatename ; } elseif ( $ fp = @ fopen ( $ templatename , 'rb' , true ) ) { return $ fp ; } if ( ! isset ( $ tpltname ) ) { echo "Can't find the parser driver template file \"%s\".\n" , $ templatename ; $ this -> errorcnt ++ ; return 0 ; } $ in = @ fopen ( $ tpltname , "rb" ) ; if ( ! $ in ) { printf ( "Can't open the template file \"%s\".\n" , $ tpltname ) ; $ this -> errorcnt ++ ; return 0 ; } return $ in ; } | The next function finds the template file and opens it returning a pointer to the opened file . |
20,678 | private function tplt_xfer ( $ name , $ in , $ out , & $ lineno ) { while ( ( $ line = fgets ( $ in , 1024 ) ) && ( $ line [ 0 ] != '%' || $ line [ 1 ] != '%' ) ) { $ lineno ++ ; $ iStart = 0 ; if ( $ name ) { for ( $ i = 0 ; $ i < strlen ( $ line ) ; $ i ++ ) { if ( $ line [ $ i ] == 'P' && substr ( $ line , $ i , 5 ) == "Parse" && ( $ i === 0 || preg_match ( '/[^a-zA-Z]/' , $ line [ $ i - 1 ] ) ) ) { if ( $ i > $ iStart ) { fwrite ( $ out , substr ( $ line , $ iStart , $ i - $ iStart ) ) ; } fwrite ( $ out , $ name ) ; $ i += 4 ; $ iStart = $ i + 1 ; } } } fwrite ( $ out , substr ( $ line , $ iStart ) ) ; } } | The first function transfers data from in to out until a line is seen which begins with %% . The line number is tracked . |
20,679 | private function tplt_print ( $ out , $ str , $ strln , & $ lineno ) { if ( $ str == '' ) { return ; } $ this -> tplt_linedir ( $ out , $ strln , $ this -> filename ) ; $ lineno ++ ; fwrite ( $ out , $ str ) ; $ lineno += count ( explode ( "\n" , $ str ) ) - 1 ; $ this -> tplt_linedir ( $ out , $ lineno + 2 , $ this -> outname ) ; $ lineno += 2 ; } | Print a string to the file and keep the linenumber up to date |
20,680 | function FindFollowSets ( ) { for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { for ( $ cfp = $ this -> sorted [ $ i ] -> data -> cfp ; $ cfp ; $ cfp = $ cfp -> next ) { $ cfp -> status = PHP_ParserGenerator_Config :: INCOMPLETE ; } } do { $ progress = 0 ; for ( $ i = 0 ; $ i < $ this -> nstate ; $ i ++ ) { for ( $ cfp = $ this -> sorted [ $ i ] -> data -> cfp ; $ cfp ; $ cfp = $ cfp -> next ) { if ( $ cfp -> status == PHP_ParserGenerator_Config :: COMPLETE ) { continue ; } for ( $ plp = $ cfp -> fplp ; $ plp ; $ plp = $ plp -> next ) { $ a = array_diff_key ( $ cfp -> fws , $ plp -> cfp -> fws ) ; if ( count ( $ a ) ) { $ plp -> cfp -> fws += $ a ; $ plp -> cfp -> status = PHP_ParserGenerator_Config :: INCOMPLETE ; $ progress = 1 ; } } $ cfp -> status = PHP_ParserGenerator_Config :: COMPLETE ; } } } while ( $ progress ) ; } | Compute all followsets . |
20,681 | function emit_code ( $ out , PHP_ParserGenerator_Rule $ rp , & $ lineno ) { $ linecnt = 0 ; if ( $ rp -> code ) { $ this -> tplt_linedir ( $ out , $ rp -> line , $ this -> filename ) ; fwrite ( $ out , " function yy_r$rp->index(){" . $ rp -> code ) ; $ linecnt += count ( explode ( "\n" , $ rp -> code ) ) - 1 ; $ lineno += 3 + $ linecnt ; fwrite ( $ out , " }\n" ) ; $ this -> tplt_linedir ( $ out , $ lineno , $ this -> outname ) ; } } | Generate code which executes when the rule rp is reduced . Write the code to out . Make sure lineno stays up - to - date . |
20,682 | function emit_destructor_code ( $ out , PHP_ParserGenerator_Symbol $ sp , & $ lineno ) { $ cp = 0 ; $ linecnt = 0 ; if ( $ sp -> type == PHP_ParserGenerator_Symbol :: TERMINAL ) { $ cp = $ this -> tokendest ; if ( $ cp === 0 ) { return ; } $ this -> tplt_linedir ( $ out , $ this -> tokendestln , $ this -> filename ) ; fwrite ( $ out , "{" ) ; } elseif ( $ sp -> destructor ) { $ cp = $ sp -> destructor ; $ this -> tplt_linedir ( $ out , $ sp -> destructorln , $ this -> filename ) ; fwrite ( $ out , "{" ) ; } elseif ( $ this -> vardest ) { $ cp = $ this -> vardest ; if ( $ cp === 0 ) { return ; } $ this -> tplt_linedir ( $ out , $ this -> vardestln , $ this -> filename ) ; fwrite ( $ out , "{" ) ; } else { throw new Exception ( 'emit_destructor' ) ; } for ( $ i = 0 ; $ i < strlen ( $ cp ) ; $ i ++ ) { if ( $ cp [ $ i ] == '$' && $ cp [ $ i + 1 ] == '$' ) { fprintf ( $ out , "(yypminor->yy%d)" , $ sp -> dtnum ) ; $ i ++ ; continue ; } if ( $ cp [ $ i ] == "\n" ) { $ linecnt ++ ; } fwrite ( $ out , $ cp [ $ i ] ) ; } $ lineno += 3 + $ linecnt ; fwrite ( $ out , "}\n" ) ; $ this -> tplt_linedir ( $ out , $ lineno , $ this -> outname ) ; } | The following routine emits code for the destructor for the symbol sp |
20,683 | public function renderCharacteristics ( CharacteristicsInterface $ characteristics , array $ options = array ( ) ) { $ options = array_merge ( array ( 'table_class' => 'table table-striped table-bordered table-condensed ekyna-characteristics' , 'highlight_inherited' => false , 'display_group' => null , ) , $ options ) ; return $ this -> template -> render ( array ( 'view' => $ this -> manager -> createView ( $ characteristics , $ options [ 'display_group' ] ) , 'options' => $ options , ) ) ; } | Renders a characteristics view table . |
20,684 | public function Run ( $ data = null ) { $ this -> ProcessFrameworkData ( ) ; $ ApplicationList = \ Puzzlout \ Framework \ GeneratorEngine \ Constants \ ApplicationList :: Init ( ) -> GetList ( ) ; foreach ( $ ApplicationList as $ Appname ) { $ this -> ProcessApplicationData ( $ Appname ) ; } } | Retrieve the lists of controller filenames . Generate the Classes that list the Controller names available in the solution . |
20,685 | function ProcessApplicationData ( $ Appname ) { $ ApplicationControllers = DirectoryManager :: GetFileNames ( "APP_ROOT_DIR" . \ Puzzlout \ Framework \ Enums \ ApplicationFolderName :: AppsFolderName . $ Appname . \ Puzzlout \ Framework \ Enums \ ApplicationFolderName :: ControllersFolderName ) ; $ this -> params = array ( BaseClassGenerator :: NameSpaceKey => "Applications\\" . $ Appname . "\Generated" , BaseClassGenerator :: ClassNameKey => $ Appname . $ this -> GeneratedClassPrefix , BaseClassGenerator :: DestinationDirKey => \ Puzzlout \ Framework \ Enums \ ApplicationFolderName :: AppsFolderName . $ Appname . \ Puzzlout \ Framework \ Enums \ ApplicationFolderName :: Generated , BaseClassGenerator :: ClassDescriptionKey => "Lists the constants for application controller classes to autocompletion and easy coding." , ConstantsClassGeneratorBase :: DoGenerateConstantKeysKey => true , ConstantsClassGeneratorBase :: DoGenerateGetListMethodKey => true ) ; $ this -> GenerateApplicationFile ( $ ApplicationControllers ) ; } | Generate the files for an app . |
20,686 | public function add ( $ entity ) { $ class = $ this -> entityClass ; if ( ! $ entity instanceof $ class ) { throw new CollectionException ( 'class must an instance of ' . $ class ) ; } $ this -> entities [ ] = $ entity ; return $ this ; } | adds an entity to the collection |
20,687 | public function checkEntities ( $ entities ) { return array_filter ( $ entities , function ( $ val ) { $ entityClass = $ this -> entityClass ; return ( $ val instanceof $ entityClass ) ; } ) ; } | filter out all entities that don t belong to the entity class |
20,688 | public function offsetSet ( $ key , $ entity ) { $ class = $ this -> entityClass ; if ( $ entity instanceof $ class ) { if ( ! isset ( $ key ) ) { $ this -> entities [ ] = $ entity ; } else { $ this -> entities [ $ key ] = $ entity ; } return true ; } throw new CollectionException ( 'The specified entity is not allowed for this collection.' ) ; } | Add an entity to the collection |
20,689 | public function offsetUnset ( $ key ) { $ entityClass = $ this -> entityClass ; if ( $ key instanceof $ entityClass ) { $ this -> entities = array_filter ( $ this -> entities , function ( $ v ) use ( $ key ) { return $ v !== $ key ; } ) ; return true ; } if ( isset ( $ this -> entities [ $ key ] ) ) { unset ( $ this -> entities [ $ key ] ) ; return true ; } return false ; } | Remove an entity from the collection |
20,690 | public function offsetGet ( $ key ) { return isset ( $ this -> entities [ $ key ] ) ? $ this -> entities [ $ key ] : null ; } | Get the specified entity in the collection |
20,691 | public function seek ( $ index ) { $ this -> rewind ( ) ; $ position = 0 ; while ( $ position < $ index && $ this -> valid ( ) ) { $ this -> next ( ) ; $ position ++ ; } if ( ! $ this -> valid ( ) ) { throw new CollectionException ( 'Invalid seek position' ) ; } } | Seek to the given index . |
20,692 | public function Sort ( ) { $ this -> Permission ( 'Garden.Settings.Manage' ) ; $ Session = Gdn :: Session ( ) ; $ TransientKey = GetPostValue ( 'TransientKey' , '' ) ; $ Target = GetPostValue ( 'Target' , '' ) ; if ( $ Session -> ValidateTransientKey ( $ TransientKey ) ) { $ TableID = GetPostValue ( 'TableID' , FALSE ) ; if ( $ TableID ) { $ Rows = GetPostValue ( $ TableID , FALSE ) ; if ( is_array ( $ Rows ) ) { try { $ Table = str_replace ( 'Table' , '' , $ TableID ) ; $ TableModel = new Gdn_Model ( $ Table ) ; foreach ( $ Rows as $ Sort => $ ID ) { $ TableModel -> Update ( array ( 'Sort' => $ Sort ) , array ( $ Table . 'ID' => $ ID ) ) ; } } catch ( Exception $ ex ) { $ this -> Form -> AddError ( $ ex -> getMessage ( ) ) ; } } } } if ( $ this -> DeliveryType ( ) != DELIVERY_TYPE_BOOL ) Redirect ( $ Target ) ; $ this -> Render ( ) ; } | Set the sort order for data on an arbitrary database table . |
20,693 | public function Update ( ) { try { $ Now = time ( ) ; $ LastTime = Gdn :: Get ( 'Garden.Update.LastTimestamp' , 0 ) ; if ( $ LastTime + ( 60 * 60 * 24 ) > $ Now ) { $ Count = Gdn :: Get ( 'Garden.Update.Count' , 0 ) + 1 ; if ( $ Count > 5 ) { if ( ! Gdn :: Session ( ) -> CheckPermission ( 'Garden.Settings.Manage' ) ) { throw PermissionException ( ) ; } } } else { $ Count = 1 ; } Gdn :: Set ( 'Garden.Update.LastTimestamp' , $ Now ) ; Gdn :: Set ( 'Garden.Update.Count' , $ Count ) ; } catch ( PermissionException $ Ex ) { return ; } catch ( Exception $ Ex ) { } try { $ UpdateModel = new UpdateModel ( ) ; $ UpdateModel -> RunStructure ( ) ; $ this -> SetData ( 'Success' , TRUE ) ; } catch ( Exception $ Ex ) { $ this -> SetData ( 'Success' , FALSE ) ; } if ( Gdn :: Session ( ) -> CheckPermission ( 'Garden.Settings.Manage' ) ) { SaveToConfig ( 'Garden.Version' , APPLICATION_VERSION ) ; } if ( $ Target = $ this -> Request -> Get ( 'Target' ) ) { Redirect ( $ Target ) ; } $ this -> FireEvent ( 'AfterUpdate' ) ; $ this -> MasterView = 'empty' ; $ this -> CssClass = 'Home' ; $ this -> Render ( ) ; } | Run a structure update on the database . |
20,694 | public function Alive ( ) { $ this -> SetData ( 'Success' , TRUE ) ; $ this -> MasterView = 'empty' ; $ this -> CssClass = 'Home' ; $ this -> FireEvent ( 'Alive' ) ; $ this -> Render ( ) ; } | Signs of life . |
20,695 | public function GetFeed ( $ Type = 'news' , $ Length = 5 , $ FeedFormat = 'normal' ) { echo file_get_contents ( 'http://vanillaforums.org/vforg/home/getfeed/' . $ Type . '/' . $ Length . '/' . $ FeedFormat . '/?DeliveryType=VIEW' ) ; $ this -> DeliveryType ( DELIVERY_TYPE_NONE ) ; $ this -> Render ( ) ; } | Grab a feed from the mothership . |
20,696 | public function FetchPageInfo ( $ Url = '' ) { $ PageInfo = FetchPageInfo ( $ Url ) ; $ this -> SetData ( 'PageInfo' , $ PageInfo ) ; $ this -> MasterView = 'default' ; $ this -> RemoveCssFile ( 'admin.css' ) ; $ this -> AddCssFile ( 'style.css' ) ; $ this -> SetData ( '_NoPanel' , TRUE ) ; $ this -> Render ( ) ; } | Return some meta information about any page on the internet in JSON format . |
20,697 | final public static function getInstance ( ... $ params ) { $ called = static :: class ; if ( self :: $ instance instanceof $ called ) { return self :: $ instance ; } else { return self :: $ instance = new $ called ( ... $ params ) ; } } | Dynamic singleton can call a class with parameters . |
20,698 | protected function numberOfLineFeedsBetweenDocBlockAndDeclaration ( File $ sniffedFile , $ indexOfFunctionToken ) { $ indexOfClosingDocBlock = $ sniffedFile -> findPrevious ( [ T_DOC_COMMENT_CLOSE_TAG ] , $ indexOfFunctionToken ) ; if ( $ indexOfClosingDocBlock === false ) { return false ; } $ numberOfLineFeeds = 0 ; for ( $ i = $ indexOfClosingDocBlock ; $ i < $ indexOfFunctionToken ; $ i ++ ) { if ( $ this -> isLinefeedToken ( $ sniffedFile , $ i ) ) { $ numberOfLineFeeds ++ ; } } return $ numberOfLineFeeds ; } | Counts the linefeeds between a method declaration and its docblock . |
20,699 | private static function pluralize ( $ string ) { $ plural = array ( array ( '/(quiz)$/i' , "$1zes" ) , array ( '/^(ox)$/i' , "$1en" ) , array ( '/([m|l])ouse$/i' , "$1ice" ) , array ( '/(matr|vert|ind)ix|ex$/i' , "$1ices" ) , array ( '/(x|ch|ss|sh)$/i' , "$1es" ) , array ( '/([^aeiouy]|qu)y$/i' , "$1ies" ) , array ( '/([^aeiouy]|qu)ies$/i' , "$1y" ) , array ( '/(hive)$/i' , "$1s" ) , array ( '/(?:([^f])fe|([lr])f)$/i' , "$1$2ves" ) , array ( '/sis$/i' , "ses" ) , array ( '/([ti])um$/i' , "$1a" ) , array ( '/(buffal|tomat)o$/i' , "$1oes" ) , array ( '/(bu)s$/i' , "$1ses" ) , array ( '/(alias|status)$/i' , "$1es" ) , array ( '/(octop|vir)us$/i' , "$1i" ) , array ( '/(ax|test)is$/i' , "$1es" ) , array ( '/s$/i' , "s" ) , array ( '/$/' , "s" ) , ) ; $ irregular = array ( array ( 'move' , 'moves' ) , array ( 'sex' , 'sexes' ) , array ( 'child' , 'children' ) , array ( 'man' , 'men' ) , array ( 'person' , 'people' ) , ) ; $ uncountable = array ( 'sheep' , 'fish' , 'series' , 'species' , 'money' , 'rice' , 'information' , 'equipment' , ) ; if ( in_array ( strtolower ( $ string ) , $ uncountable ) ) { return $ string ; } foreach ( $ irregular as $ noun ) { if ( strtolower ( $ string ) == $ noun [ 0 ] ) { return $ noun [ 1 ] ; } } foreach ( $ plural as $ pattern ) { if ( preg_match ( $ pattern [ 0 ] , $ string ) ) { return preg_replace ( $ pattern [ 0 ] , $ pattern [ 1 ] , $ string ) ; } } return $ string ; } | who translated it from Ruby from the Rails Inflector class |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.