idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
26,300 | protected function documentFragmentCreate ( $ source , $ charset = null ) { $ fake = new DOMDocumentWrapper ( ) ; $ fake -> contentType = $ this -> contentType ; $ fake -> isXML = $ this -> isXML ; $ fake -> isHTML = $ this -> isHTML ; $ fake -> isXHTML = $ this -> isXHTML ; $ fake -> root = $ fake -> document ; if ( ! $ charset ) { $ charset = $ this -> charset ; } if ( $ source instanceof DOMNODE && ! ( $ source instanceof DOMNODELIST ) ) { $ source = array ( $ source ) ; } if ( is_array ( $ source ) || $ source instanceof DOMNODELIST ) { if ( ! $ this -> documentFragmentLoadMarkup ( $ fake , $ charset ) ) { return false ; } $ nodes = $ fake -> import ( $ source ) ; foreach ( $ nodes as $ node ) $ fake -> root -> appendChild ( $ node ) ; } else { $ this -> documentFragmentLoadMarkup ( $ fake , $ charset , $ source ) ; } return $ fake ; } | Creates new document fragment . |
26,301 | public function reload ( string $ language ) : bool { $ language = trim ( $ language ) ; if ( ! self :: valid ( $ language ) ) { return false ; } if ( $ this -> language === $ language && $ this -> lang_init ) { return true ; } $ packages = is_null ( $ this -> lang ) ? [ ] : $ this -> lang -> packages ( ) ; $ this -> language = $ language ; $ this -> lang = null ; $ this -> lang_init = true ; $ this -> proxy = [ ] ; $ event = new LanguageLoadEvent ( $ this ) ; EventManager :: dispatch ( $ event , function ( $ result ) use ( $ event ) { if ( $ result instanceof Language ) { $ this -> lang = $ result ; $ event -> stopPropagation ( ) ; } } ) ; if ( is_null ( $ this -> lang ) ) { $ this -> lang = new LanguageFiles ( $ language ) ; } $ this -> lang_i18 = $ this -> lang instanceof I18Interface ; $ this -> lang_transliteration = $ this -> lang instanceof TransliterationInterface ; $ this -> lang_text = $ this -> lang instanceof TextInterface ; $ this -> lang_is_default = $ this -> lang === $ this -> lang_default ; foreach ( $ packages as $ package ) { $ this -> lang -> load ( $ package ) ; } return true ; } | Set new language key and reload all packages |
26,302 | public function getProxy ( string $ context ) : ThenProxy { if ( isset ( $ this -> proxy [ $ context ] ) ) { return $ this -> proxy [ $ context ] ; } if ( ! $ this -> lang -> load ( $ context ) ) { throw new \ InvalidArgumentException ( "Cannot load the '{$context}' language package" ) ; } $ this -> proxy [ $ context ] = new ThenProxy ( $ this , $ context ) ; return $ this -> proxy [ $ context ] ; } | Get the language package proxy |
26,303 | public function replace ( string $ text , ... $ replace ) : string { $ then = $ this -> package_context ; return $ this -> format ( $ this -> line ( $ text ) , $ then , count ( $ replace ) === 1 && is_array ( $ replace [ 0 ] ) ? $ replace [ 0 ] : $ replace ) ; } | Get line and replace values |
26,304 | public function text ( string $ text ) : string { $ then = $ this -> getThen ( ) ; if ( $ this -> lang_text ) { return $ this -> lang -> text ( $ text , $ then ) ; } else { return $ text ; } } | Get text block |
26,305 | public static function canonical ( $ path ) { $ path = self :: split ( $ path ) ; $ canon = [ ] ; foreach ( $ path as $ segment ) { if ( $ segment === '..' ) { array_pop ( $ canon ) ; } elseif ( $ segment !== '.' ) { $ canon [ ] = $ segment ; } } if ( $ canon [ count ( $ canon ) - 1 ] === '' ) { array_pop ( $ canon ) ; } return self :: join ( $ canon ) ; } | Canonicalizes the file system path . Always remove slash from the end . |
26,306 | public static function trimFileName ( $ path ) { $ name = static :: nameFromPath ( $ path ) ; return substr ( $ path , 0 , strlen ( $ path ) - strlen ( $ name ) ) ; } | Trim file name from provided path |
26,307 | public static function splitNameFromPath ( $ path ) { $ name = static :: nameFromPath ( $ path ) ; $ path = static :: trimFileName ( $ path ) ; return [ $ path , $ name ] ; } | Get the path separate from name |
26,308 | public static function deleteDirectory ( $ path ) { if ( ! is_dir ( $ path ) ) { return false ; } $ files = array_diff ( scandir ( $ path ) , [ '.' , '..' ] ) ; foreach ( $ files as $ file ) { $ inner_file = static :: join ( $ path , $ file ) ; if ( is_dir ( $ inner_file ) ) { static :: deleteDirectory ( $ inner_file ) ; } else { unlink ( $ inner_file ) ; } } return rmdir ( $ path ) ; } | Delete directory recursive |
26,309 | public static function dirSize ( $ path , array $ exclude = [ ] ) { if ( ! is_dir ( $ path ) ) { return 0 ; } $ size = 0 ; $ exclude = array_merge ( [ '.' , '..' ] , $ exclude ) ; $ items = array_diff ( scandir ( $ path ) , $ exclude ) ; foreach ( $ items as $ item ) { $ inner_item = static :: join ( $ path , $ item ) ; $ size += is_file ( $ inner_item ) ? filesize ( $ inner_item ) : static :: dirSize ( $ inner_item , $ exclude ) ; } return $ size ; } | Calculate directory size including sub - folders |
26,310 | public function setCharList ( $ charList ) { if ( ! strlen ( $ charList ) ) { $ charList = null ; } $ this -> options [ 'charlist' ] = $ charList ; return $ this ; } | Sets the charList option |
26,311 | public final function execute ( ehough_shortstop_api_HttpRequest $ request ) { $ requestEvent = new ehough_tickertape_GenericEvent ( $ request ) ; $ this -> _eventDispatcher -> dispatch ( ehough_shortstop_api_Events :: REQUEST , $ requestEvent ) ; $ chainContext = new ehough_chaingang_impl_StandardContext ( ) ; $ chainContext -> put ( 'request' , $ request ) ; $ result = $ this -> _executionChain -> execute ( $ chainContext ) ; if ( ! $ result || ! $ chainContext -> containsKey ( 'response' ) || ( ! ( $ chainContext -> get ( 'response' ) instanceof ehough_shortstop_api_HttpResponse ) ) ) { throw new ehough_shortstop_api_exception_RuntimeException ( sprintf ( 'No HTTP transports could execute %s' , $ request ) ) ; } $ response = $ chainContext -> get ( 'response' ) ; $ responseEvent = new ehough_tickertape_GenericEvent ( $ response , array ( 'request' => $ requestEvent -> getSubject ( ) ) ) ; $ this -> _eventDispatcher -> dispatch ( ehough_shortstop_api_Events :: RESPONSE , $ responseEvent ) ; return $ response ; } | Execute a given HTTP request . |
26,312 | public function splitDate ( $ value ) { $ parts = Match :: on ( $ this -> laxTime ) -> test ( true , function ( ) use ( $ value ) { $ parts = explode ( ' ' , $ value ) ; if ( count ( $ parts ) == 3 ) { $ parts [ 1 ] .= ' ' . $ parts [ 2 ] ; unset ( $ parts [ 2 ] ) ; } return $ parts ; } ) -> test ( false , function ( ) use ( $ value ) { return explode ( 't' , $ value ) ; } ) -> value ( ) ; if ( count ( $ parts ) == 0 || count ( $ parts ) > 2 || ( count ( $ parts ) == 1 && empty ( $ parts [ 0 ] ) ) ) { return array ( null , null , null , $ this -> timepartFound , $ this -> zonepartFound ) ; } if ( count ( $ parts ) == 1 ) { return array ( $ parts [ 0 ] , null , null , $ this -> timepartFound , $ this -> zonepartFound ) ; } if ( count ( $ parts ) == 2 ) { $ this -> timepartFound = true ; list ( $ time , $ zone ) = $ this -> splitTime ( $ parts [ 1 ] ) ; if ( ! is_null ( $ zone ) ) { return array ( $ parts [ 0 ] , $ time , $ zone , $ this -> timepartFound , $ this -> zonepartFound ) ; } elseif ( ! is_null ( $ time ) ) { return array ( $ parts [ 0 ] , $ time , null , $ this -> timepartFound , $ this -> zonepartFound ) ; } return array ( $ parts [ 0 ] , null , null , $ this -> timepartFound , $ this -> zonepartFound ) ; } return array ( $ parts [ 0 ] , null , null , $ this -> timepartFound , $ this -> zonepartFound ) ; } | Split date by its parts |
26,313 | protected function splitTime ( $ value ) { if ( empty ( $ value ) ) { return array ( null , null ) ; } $ partsZ = explode ( 'z' , $ value ) ; $ partsM = explode ( '-' , $ value ) ; $ partsP = explode ( '+' , $ value ) ; if ( $ this -> laxZone ) { $ partsZ [ 0 ] = rtrim ( $ partsZ [ 0 ] ) ; $ partsM [ 0 ] = rtrim ( $ partsM [ 0 ] ) ; $ partsP [ 0 ] = rtrim ( $ partsP [ 0 ] ) ; } if ( count ( $ partsZ ) == 0 && count ( $ partsM ) == 0 && count ( $ partsP ) == 0 ) { return array ( null , null ) ; } if ( count ( $ partsZ ) == 2 && empty ( $ partsZ [ 1 ] ) ) { $ this -> zonepartFound = true ; return array ( $ partsZ [ 0 ] , $ this -> getUTCTimezone ( ) ) ; } if ( count ( $ partsM ) == 2 ) { $ this -> zonepartFound = true ; return array ( $ partsM [ 0 ] , "-{$partsM[1]}" ) ; } if ( count ( $ partsP ) == 2 ) { $ this -> zonepartFound = true ; return array ( $ partsP [ 0 ] , "+{$partsP[1]}" ) ; } return array ( ( empty ( $ value ) ? null : $ value ) , null ) ; } | Split timezone by its parts |
26,314 | protected function getUTCTimezone ( ) { if ( \ date_default_timezone_get ( ) == 'UTC' ) { return 'UTC' ; } $ timezone = new \ DateTimeZone ( \ date_default_timezone_get ( ) ) ; $ offset = $ timezone -> getOffset ( new \ DateTime ( ) ) ; $ offsetHours = round ( abs ( $ offset ) / 3600 ) ; $ offsetMinutes = round ( ( abs ( $ offset ) - $ offsetHours * 3600 ) / 60 ) ; $ offsetString = ( $ offset < 0 ? '-' : '+' ) . ( $ offsetHours < 10 ? '0' : '' ) . $ offsetHours . ( $ this -> format == C :: FORMAT_EXTENDED || $ this -> format == C :: FORMAT_EXTENDED_SIGNED ? ':' : '' ) . ( $ offsetMinutes < 10 ? '0' : '' ) . $ offsetMinutes ; return $ offsetString ; } | Get current UTC timezone offset |
26,315 | public function authenticate ( ) { Logger :: get ( ) -> debug ( 'Authenticating OpenID user...' ) ; if ( ! $ this -> isAuthenticated ) { if ( ! static :: getConsumer ( ) -> validate ( ) ) { Logger :: get ( ) -> debug ( ' Failed!' ) ; throw new NotAuthenticatedException ( 'OpenID authentication failed.' ) ; } else { $ this -> isAuthenticated = true ; } } Logger :: get ( ) -> debug ( ' OK!' ) ; } | Makes sure the user is authenticated . If not an exception is thrown . |
26,316 | public function setMail ( string $ mailPath , bool $ mailPanel ) : void { $ this -> mailPath = $ mailPath ; $ this -> mailPanel = $ mailPanel ; } | Nastavi mail panel |
26,317 | public function enable ( ) : void { $ this -> response -> setCookie ( Configurator :: COOKIE_SECRET , $ this -> cookie , strtotime ( '1 years' ) , '/' , '' , '' , true ) ; $ this -> enable = true ; } | Zapnuti debug modu pomoci cookie |
26,318 | public function disable ( ) : void { $ this -> response -> deleteCookie ( Configurator :: COOKIE_SECRET ) ; $ this -> enable = false ; } | Vypnuti debug modu pomoci cookie |
26,319 | public function stripes ( $ classes , $ column = false ) { $ count = count ( $ classes ) ; $ index = - 1 ; $ prev = null ; foreach ( $ this -> children as $ i => $ row ) { if ( $ column === false ) { $ index = ++ $ index % $ count ; } else { foreach ( $ row -> children as $ k => $ cell ) { if ( $ k > $ column ) break ; if ( $ i == 0 || $ cell -> content != $ prev -> children [ $ k ] -> content ) { $ index = ++ $ index % $ count ; break ; } } $ prev = $ row ; } $ this -> children [ $ i ] -> setClass ( $ classes [ $ index ] ) ; } return $ this ; } | Adds alternating classes to child elements . |
26,320 | public function getSubject ( $ name ) { if ( empty ( $ this -> subjects [ $ name ] ) ) { $ this -> initSubject ( $ name ) ; } return $ this -> subjects [ $ name ] ; } | Provides an event subject identified by the given name . |
26,321 | public function initSubject ( $ name ) { $ this -> fetchSubjectsFromRegistry ( $ name ) ; try { if ( empty ( $ this -> subjects [ $ name ] ) ) { $ this -> subjects [ $ name ] = new EventSubject ( $ name ) ; if ( $ this -> registry -> isRegistered ( $ name ) ) { $ this -> registry -> replace ( $ name , $ this -> subjects [ $ name ] ) ; } else { $ this -> registry -> register ( $ name , $ this -> subjects [ $ name ] ) ; } } } catch ( RegistryException $ re ) { $ this -> getDrupalConnectorFactory ( ) -> getCommonConnector ( ) -> watchdog ( 'Liip Drupal Event Manager' , $ re -> getMessage ( ) , array ( ) , WATCHDOG_ERROR ) ; } } | Initiates and caches an event subject for later use . |
26,322 | protected function fetchSubjectsFromRegistry ( $ name ) { try { $ this -> subjects = $ this -> registry -> getContent ( ) ; if ( ! empty ( $ this -> subjects [ $ name ] ) ) { $ this -> assertions -> isInstanceOf ( $ this -> subjects [ $ name ] , '\\Liip\\Drupal\\Modules\\EventManager\\EventSubjectInterface' , 'Someone sneaked wrong value in there.. neat!! Will be reset now ;)' ) ; } } catch ( InvalidArgumentException $ e ) { $ this -> getDrupalConnectorFactory ( ) -> getCommonConnector ( ) -> watchdog ( 'Liip Drupal Event Manager' , $ e -> getMessage ( ) , array ( ) , WATCHDOG_ERROR ) ; $ this -> subjects [ $ name ] = null ; } } | Retrieves the set of subjects from the registry currently attached . |
26,323 | public function create ( $ index , $ type , $ document ) { $ request = $ this -> createRequestInstance ( self :: CREATE_DOCUMENT , $ index , $ type ) ; $ request -> setBody ( $ document ) ; return $ this -> client -> send ( $ request ) ; } | creates a document |
26,324 | public function delete ( $ index , $ type , $ id ) { $ request = $ this -> createRequestInstance ( self :: DELETE_DOCUMENT , $ index , $ type ) ; $ request -> setId ( $ id ) ; return $ this -> client -> send ( $ request ) ; } | Deletes a document by id |
26,325 | public function get ( $ index , $ type , $ id ) { $ request = $ this -> createRequestInstance ( self :: GET_DOCUMENT , $ index , $ type ) ; $ request -> setId ( $ id ) ; return $ this -> client -> send ( $ request ) ; } | gets a document by id |
26,326 | public function setString ( $ string = '' ) { try { Assert :: string ( $ string ) ; } catch ( InvalidArgumentException $ e ) { $ this -> string = '' ; } $ this -> string = $ string ; return $ this ; } | Sets an empty string if the parameter has the wrong type . |
26,327 | public function isValidAbsolutePath ( ) { if ( ! Path :: isAbsolute ( $ this -> string ) ) { return false ; } if ( ! is_dir ( $ this -> string ) ) { return false ; } return true ; } | Confirms if a string is an existing absolute path . |
26,328 | public function isValidRegex ( ) { set_error_handler ( function ( $ errno , $ errstr ) { throw new InvalidArgumentException ( $ errstr , $ errno ) ; } , E_WARNING ) ; $ valid = true ; try { preg_match ( $ this -> string , 'tester' ) ; } catch ( InvalidArgumentException $ e ) { $ valid = false ; } restore_error_handler ( ) ; return $ valid ; } | Confirms if a string is a valid regular expression . |
26,329 | public function hasKeyAndValueSubPattern ( ) { if ( ! $ this -> isValidRegex ( ) ) { return false ; } if ( false === strpos ( $ this -> string , '(?<key>' ) || false === strpos ( $ this -> string , '(?<value>' ) ) { return false ; } return true ; } | Confirms if a valid regex string contains a key and a value named suppattern . |
26,330 | public function validateUrl ( $ attribute , $ params ) { $ parentParentId = ( null === $ this -> structure ) ? 0 : ( int ) $ this -> structure -> parent_id ; $ parentContextId = ( null === $ this -> structure ) ? 0 : ( int ) $ this -> structure -> context_id ; if ( $ this -> slug != $ this -> oldSlug || $ this -> parentParentId !== $ parentParentId || $ this -> parentContextId !== $ parentContextId ) { $ url = $ this -> compileUrl ( ) ; $ query = self :: find ( ) -> select ( 'url' ) -> innerJoin ( BaseStructure :: tableName ( ) , 'model_id = ' . BaseStructure :: tableName ( ) . '.id' ) -> where ( [ 'language_id' => $ this -> language_id , 'context_id' => $ this -> parentContextId , 'url' => $ url ] ) ; if ( false === $ this -> isNewRecord ) { $ query -> andWhere ( [ 'not' , [ 'model_id' => $ this -> model_id ] ] ) ; } $ isset = $ query -> scalar ( ) ; if ( false !== $ isset ) { $ this -> addError ( 'slug' , Yii :: t ( 'dotplant.entity.structure' , 'Value \'{value}\' already in use, please, choose another!' , [ 'value' => $ this -> slug ] ) ) ; } $ this -> url = $ url ; } } | Validates url to be unique among other in one context and in one language range |
26,331 | public function write ( $ message , $ params = [ ] ) { $ options = $ this -> getMergedWriteParams ( $ params ) ; echo $ this -> getMessagePrefix ( $ options ) , $ this -> getDecoratedMessage ( $ message , $ options ) , $ this -> getReset ( ) ; return $ this ; } | writes a messge to the output |
26,332 | protected function getMergedWriteParams ( $ params = [ ] ) { $ defaults = [ 'background' => false , 'color' => false , 'bold' => false , 'underline' => false , ] ; return array_merge ( $ defaults , $ params ) ; } | Gets merged params with defaults |
26,333 | protected function getDecoratedMessage ( $ message , $ params = [ ] ) { $ result = '' ; $ prefix = '' ; foreach ( $ params as $ option => $ value ) { if ( $ value ) { $ result .= $ prefix . $ this -> decorations [ $ option ] [ $ value ] ; $ prefix = ';' ; } } if ( $ prefix ) { $ message = 'm' . $ message ; } return $ result . $ message ; } | Gets a decorated version of the message . |
26,334 | public function import ( $ file ) { $ data = $ this -> yaml -> load ( $ file ) ; parent :: import ( $ data ) ; } | import config file . |
26,335 | public static function fromXml ( \ DOMNodeList $ xml ) { $ items = array ( ) ; foreach ( $ xml as $ xmlTag ) { $ items [ ] = Hold :: fromXml ( $ xmlTag ) ; } return new static ( $ items ) ; } | Builds a HoldCollection object from XML . |
26,336 | public function subscribeform ( $ listID ) { if ( ! $ this -> subscribeToList -> getListByID ( $ listID ) ) { return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.list_invalid' , [ 'title' => 'Invalid List' , ] ) ; } return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_form' , [ 'title' => 'List Sign-up' , 'email_field_only' => Config :: get ( 'lasallecrmlistmanagement.listmgmt_subscribe_form_email_field_only' ) , 'list' => $ this -> subscribeToList -> getListnameByListId ( $ listID ) , 'listID' => $ listID , ] ) ; } | Display the subscribe form for a given list ID |
26,337 | public function postSubscribe ( Request $ request ) { if ( $ this -> subscribeToList -> getEmailIDByTitle ( $ request -> input ( 'email' ) ) ) { if ( $ this -> subscribeToList -> getList_emailByEmailIdAndListId ( $ this -> subscribeToList -> getEmailIDByTitle ( $ request -> input ( 'email' ) ) , $ request -> input ( 'listID' ) ) ) { return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_email_already_in_list' , [ 'title' => $ this -> subscribeToList -> getListnameByListId ( $ request -> input ( 'listID' ) ) , 'email' => $ request -> input ( 'email' ) ] ) ; } } $ emailID = $ this -> subscribeToList -> getEmailIDByTitle ( $ request -> input ( 'email' ) ) ; if ( ! $ emailID ) { $ data = $ this -> subscribeToList -> prepareEmailDataForInsert ( $ request ) ; $ emailID = $ this -> subscribeToList -> createNewEmailRecord ( $ data ) ; } if ( ! $ emailID ) { $ message = "Something did not quite go right in the processing. Please try again." ; Session :: flash ( 'message' , $ message ) ; return redirect ( 'list/subscribe/' . $ request -> input ( 'listID' ) ) -> withInput ( ) ; } $ input = array_merge ( $ request -> all ( ) , [ 'emailID' => $ emailID ] ) ; $ data = $ this -> subscribeToList -> prepareList_emailDataForInsert ( $ input ) ; $ list_emailID = $ this -> subscribeToList -> createNewList_emailRecord ( $ data ) ; if ( ! $ list_emailID ) { $ message = "Something did not go quite right in the processing. Please try again." ; Session :: flash ( 'message' , $ message ) ; return redirect ( 'list/subscribe/' . $ request -> input ( 'listID' ) ) -> withInput ( ) ; } if ( $ request -> has ( 'surname' ) ) { $ peopleID = $ this -> subscribeToList -> isFirstnameSurname ( $ request -> input ( 'first_name' ) , $ request -> input ( 'surname' ) ) ; if ( ! $ peopleID ) { $ data = $ this -> subscribeToList -> preparePeoplesDataForInsert ( $ input ) ; $ peopleID = $ this -> subscribeToList -> createNewPeoplesRecord ( $ data ) ; } if ( $ peopleID ) { $ people_emailID = $ this -> subscribeToList -> createNewPeople_emailRecord ( [ 'people_id' => $ peopleID , 'email_id' => $ emailID ] ) ; } if ( ! $ people_emailID ) { $ people_emailID = $ this -> subscribeToList -> createNewPeople_emailRecord ( [ 'people_id' => $ peopleID , 'email_id' => $ emailID ] ) ; } } return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_success' , [ 'title' => $ this -> subscribeToList -> getListnameByListId ( $ request -> input ( 'listID' ) ) , 'email' => $ request -> input ( 'email' ) ] ) ; } | Subscribe someone to a LaSalleCRM email list from the filled in subscribe form |
26,338 | public function setRightMenu ( $ container ) { if ( null === $ container ) { throw Exception \ InvalidArgumentException ( 'Container must be a string alias or an instance of ' . 'Zend\Navigation\AbstractContainer' ) ; } $ this -> parseContainer ( $ container ) ; $ this -> rightMenu = $ container ; return $ this ; } | Set right menu |
26,339 | protected function renderNavigation ( AbstractContainer $ container , array $ options ) { $ html = $ this -> renderNavbarContainerHeader ( $ options ) . $ this -> renderNavbarMenu ( $ container , $ options ) ; if ( $ options [ 'useForm' ] ) { $ html .= $ this -> renderNavbarForm ( $ options ) ; } if ( $ options [ 'rightMenu' ] ) { $ html .= $ this -> renderNavbarRightMenu ( $ options ) ; } $ html .= $ this -> renderNavbarContainerFooter ( ) ; return $ html ; } | Render navbar container |
26,340 | protected function renderNavbarMenu ( AbstractContainer $ container , array $ options ) { $ iterator = new \ RecursiveIteratorIterator ( $ container , \ RecursiveIteratorIterator :: SELF_FIRST ) ; $ iterator -> setMaxDepth ( self :: MAX_RENDER_DEPTH ) ; $ html = '' ; $ prevDepth = - 1 ; foreach ( $ iterator as $ page ) { if ( ! $ this -> accept ( $ page ) ) { continue ; } $ depth = $ iterator -> getDepth ( ) ; $ html .= $ this -> renderNavbarMenuPage ( $ page , $ options , $ depth , $ prevDepth ) ; $ prevDepth = $ depth ; } if ( $ html ) { for ( $ i = $ prevDepth + 1 ; $ i > 0 ; $ i -- ) { $ html .= '</li></ul>' ; } } return $ html ; } | Render navbar menu |
26,341 | protected function renderNavbarMenuPage ( AbstractPage $ page , array $ options , $ depth , $ prevDepth ) { $ html = '' ; if ( $ depth > $ prevDepth ) { $ ulClass = $ this -> createNavbarMenuClass ( $ page , $ options [ 'ulClass' ] , $ depth ) ; $ html .= '<ul' . $ ulClass . '>' ; } elseif ( $ depth < $ prevDepth ) { for ( $ i = $ prevDepth ; $ i > $ depth ; $ i -- ) { $ html .= '</li></ul>' ; } $ html .= '</li>' ; } elseif ( $ depth == $ prevDepth ) { $ html .= '</li>' ; } if ( $ page -> get ( 'divider' ) ) { $ html .= '<li class="divider"></li>' ; } if ( $ this -> isPageEmpty ( $ page ) ) { return $ html ; } $ liClass = $ this -> createNavbarMenuItemClass ( $ page , $ options [ 'addClassToLi' ] , $ depth ) ; $ html .= '<li' . $ liClass . '>' . $ this -> htmlify ( $ page , $ options [ 'addClassToLi' ] , $ options [ 'iconPosition' ] , $ depth >= self :: MAX_RENDER_DEPTH ) ; return $ html ; } | Render navbar menu page |
26,342 | protected function isPageEmpty ( AbstractPage $ page ) { if ( $ page -> get ( 'route' ) ) { return false ; } if ( ! $ page -> hasPages ( true ) ) { return true ; } $ isGranted = $ this -> getView ( ) -> plugin ( 'isGranted' ) ; foreach ( $ page -> getPages ( ) as $ childPage ) { if ( ! $ childPage -> isVisible ( ) ) { continue ; } if ( $ isGranted ( $ childPage -> get ( 'permission' ) ) ) { return false ; } } return true ; } | Is the page empty? |
26,343 | protected function renderNavbarRightMenu ( array $ options ) { $ container = $ options [ 'rightMenu' ] ; $ this -> parseContainer ( $ container ) ; if ( null === $ container ) { $ container = new Navigation ; } $ options [ 'ulClass' ] .= ' navbar-right' ; return $ this -> renderNavbarMenu ( $ container , $ options ) ; } | Render navbar right aligned menu |
26,344 | protected function createNavbarContainerClass ( array $ options ) { $ containerClass = 'navbar' ; if ( $ options [ 'inverse' ] ) { $ containerClass .= ' navbar-inverse' ; } if ( $ options [ 'fixed' ] ) { $ containerClass .= ' navbar-fixed-' ; switch ( $ options [ 'fixed' ] ) { case 'top' : case 'bottom' : $ containerClass .= $ options [ 'fixed' ] ; break ; default : throw new Exception \ InvalidArgumentException ( 'Only top and bottom are acceptable navbarFixed options' ) ; } } return $ containerClass ; } | Create navbar container class |
26,345 | protected function createNavbarMenuClass ( AbstractPage $ page , $ ulClass , $ depth ) { if ( $ depth === 0 && $ ulClass ) { return ' class="' . $ this -> escapeHtmlAttribute ( $ ulClass ) . '"' ; } elseif ( $ page -> getParent ( ) && $ depth <= self :: MAX_RENDER_DEPTH ) { return ' class="dropdown-menu"' ; } return '' ; } | Create navbar menu class |
26,346 | protected function createNavbarMenuItemClass ( AbstractPage $ page , $ addClassToLi , $ depth ) { $ liClasses = [ ] ; if ( $ page -> isActive ( ) ) { $ liClasses [ ] = 'active' ; } if ( $ page -> hasPages ( ) && $ depth < self :: MAX_RENDER_DEPTH ) { $ liClasses [ ] = 'dropdown' ; } if ( $ addClassToLi && $ page -> getClass ( ) ) { $ liClasses [ ] = $ page -> getClass ( ) ; } if ( $ liClasses ) { return ' class="' . implode ( ' ' , $ liClasses ) . '"' ; } return '' ; } | Create navbar menu item class |
26,347 | public function getConditionString ( array $ types , array $ translations = array ( ) , array $ plugins = array ( ) ) { if ( $ this -> _conditions !== null ) { return $ string = $ this -> _conditions -> toString ( $ types , $ translations , $ plugins ) ; } return new Zend_Search_Lucene_Search_Query_Insignificant ( ) ; } | Returns the expression string . |
26,348 | public function getSortationString ( array $ types , array $ translations = array ( ) ) { $ sortation = '' ; foreach ( $ this -> _sortations as $ sortitem ) { if ( ( $ string = $ sortitem -> toString ( $ types , $ translations ) ) !== '' ) { $ sortation .= $ string ; } } return $ sortation ; } | Returns the string for sorting the result |
26,349 | protected function checkSettings ( ) { $ io = $ this -> event -> getIO ( ) ; if ( $ this -> disabled ) { $ io -> write ( '<info>[C33sConstructionKitBundle] C33sConstructionKit is disabled</info>' ) ; return false ; } if ( ! is_dir ( $ this -> appDir ) ) { $ currentDir = getcwd ( ) ; $ io -> write ( "<warning>[C33sConstructionKitBundle] The symfony-app-dir {$this->appDir} specified in composer.json was not found in {$currentDir}. Cannot generate building blocks file.</warning>" ) ; return false ; } return true ; } | Check various settings before performing any updates . |
26,350 | protected function listChanges ( $ existingConfig , array $ blocks ) { $ existingBlocks = array ( ) ; if ( isset ( $ existingConfig [ 'c33s_construction_kit' ] [ 'composer_building_blocks' ] ) && is_array ( $ existingConfig [ 'c33s_construction_kit' ] [ 'composer_building_blocks' ] ) ) { foreach ( $ existingConfig [ 'c33s_construction_kit' ] [ 'composer_building_blocks' ] as $ packageBlocks ) { if ( is_array ( $ packageBlocks ) ) { $ existingBlocks = array_merge ( $ existingBlocks , $ packageBlocks ) ; } } } $ added = array_diff ( $ blocks , $ existingBlocks ) ; $ removed = array_diff ( $ existingBlocks , $ blocks ) ; if ( count ( $ added ) ) { $ this -> event -> getIO ( ) -> write ( '<info>[C33sConstructionKitBundle] Found new building blocks:</info>' ) ; $ added = array_map ( function ( $ block ) { return ' - ' . $ block ; } , $ added ) ; $ this -> event -> getIO ( ) -> write ( $ added ) ; } if ( count ( $ removed ) ) { $ this -> event -> getIO ( ) -> write ( '<info>[C33sConstructionKitBundle] The following building blocks have been removed:</info>' ) ; $ removed = array_map ( function ( $ block ) { return ' - ' . $ block ; } , $ removed ) ; $ this -> event -> getIO ( ) -> write ( $ removed ) ; } } | Display information regarding changed building blocks . |
26,351 | protected function getPackagesData ( ) { $ composer = $ this -> event -> getComposer ( ) ; $ locker = $ composer -> getLocker ( ) ; if ( isset ( $ locker ) ) { $ lockData = $ locker -> getLockData ( ) ; $ allPackages = isset ( $ lockData [ 'packages' ] ) ? $ lockData [ 'packages' ] : array ( ) ; } $ packages = array ( ) ; foreach ( $ allPackages as $ package ) { if ( isset ( $ package [ 'extra' ] [ 'c33s-building-blocks' ] ) && is_array ( $ package [ 'extra' ] [ 'c33s-building-blocks' ] ) ) { $ packages [ ] = $ package ; } } $ root = $ composer -> getPackage ( ) ; if ( $ root ) { $ dumper = new ArrayDumper ( ) ; $ package = $ dumper -> dump ( $ root ) ; if ( isset ( $ package [ 'extra' ] [ 'c33s-building-blocks' ] ) && is_array ( $ package [ 'extra' ] [ 'c33s-building-blocks' ] ) ) { $ packages [ ] = $ package ; } } return $ packages ; } | Get active non - dev packages from composer s locker that include an c33s - building - blocks extra array . |
26,352 | protected function storeConfig ( array $ blocksByPackage ) { $ content = "# This file is auto-generated by c33s/composer-construction-kit-installer\n# upon each composer dump-autoload event\n" ; $ content .= Yaml :: dump ( array ( 'c33s_construction_kit' => array ( 'composer_building_blocks' => $ blocksByPackage , ) , ) , 4 ) ; $ fs = new Filesystem ( ) ; $ fs -> dumpFile ( $ this -> getFilename ( ) , $ content ) ; } | Save new blocks config to file . |
26,353 | public function isCached ( $ type , $ hash , $ version ) { if ( ! isset ( $ this -> cachedFiles [ $ hash ] ) ) { return false ; } $ searchedFile = $ this -> buildFilePath ( $ type , $ hash , $ version ) ; foreach ( $ this -> cachedFiles as $ baseFileHash => $ cachedFile ) { if ( $ cachedFile [ 'file' ] === $ searchedFile ) { return true ; } } return false ; } | Returns true if the given file is cached otherwise return false . |
26,354 | public function getAssetContent ( $ type , $ hash , $ version ) { if ( ! $ this -> isCached ( $ type , $ hash , $ version ) ) { return '' ; } $ targetFile = $ this -> buildFilePath ( $ type , $ hash , $ version ) ; return $ this -> fileBackend -> loadFromFile ( $ targetFile ) ; } | Returns the content of the given type and file . |
26,355 | public function getCachedAssetTimestamp ( $ type , $ hash , $ version ) { if ( ! $ this -> isCached ( $ type , $ hash , $ version ) ) { return 0 ; } return $ this -> cachedFiles [ $ hash ] [ 'timestamp' ] ; } | Returns the timestamp of the cached asset |
26,356 | public function displayAssetType ( $ type ) { $ files = $ this -> assetManager -> getAssetFiles ( $ type ) ; if ( $ files === false ) { return ; } if ( $ this -> combineAssets ) { $ this -> displayCombinedAssets ( $ type , $ files ) ; } else { foreach ( $ files as $ file ) { $ cachedFile = $ this -> generateCachedFile ( $ type , $ file -> getFileName ( ) ) ; if ( $ cachedFile !== false ) { echo $ this -> generateHtmlCode ( $ type , $ cachedFile [ 'file' ] ) ; } } } } | Make the cache for an asset type and display the html code to include the asset type . |
26,357 | protected function displayCombinedAssets ( $ type , $ files ) { $ isValid = $ this -> validateTypeCache ( $ type , $ files ) ; $ result = $ isValid ; if ( ! $ isValid ) { $ result = $ this -> buildTypeCache ( $ type , $ files ) ; } if ( $ result ) { $ hash = $ this -> getTypeHash ( $ type ) ; $ cachedFile = $ this -> cachedFiles [ $ hash ] [ 'file' ] ; echo $ this -> generateHtmlCode ( $ type , $ cachedFile ) ; } } | Displays the combined assets for the given asset type |
26,358 | public function getAssetUrl ( $ type , $ assetName ) { $ file = $ this -> assetManager -> getAssetFile ( $ type , $ assetName ) ; if ( $ file === false ) { return ; } $ cachedFile = $ this -> generateCachedFile ( $ type , $ file -> getFileName ( ) ) ; return $ this -> getUrlToTheAssetLoader ( $ cachedFile [ 'file' ] ) ; } | Returns the url for one asset . |
26,359 | public function generateCachedFile ( $ type , $ fileName ) { $ isValid = $ this -> validateCache ( $ fileName ) ; $ result = $ isValid ; if ( ! $ isValid ) { $ result = $ this -> buildFileCache ( $ type , $ fileName ) ; } if ( $ result ) { $ hash = $ this -> getHash ( $ fileName ) ; return $ this -> cachedFiles [ $ hash ] ; } return false ; } | Generates a cached file for the given type and base file . |
26,360 | public function clearAssetCache ( ) { foreach ( $ this -> cachedFiles as $ hash => $ fileData ) { if ( ! $ this -> fileBackend -> isWritable ( $ fileData [ 'file' ] ) ) { continue ; } $ this -> fileBackend -> deleteFile ( $ fileData [ 'file' ] ) ; } $ this -> cachedFiles = array ( ) ; $ this -> saveAssetsCache ( ) ; } | Clears the asset cache . |
26,361 | protected function buildTypeCache ( $ type , $ files ) { $ typeContent = '' ; $ fileHashs = array ( ) ; foreach ( $ files as $ file ) { $ fileName = $ file -> getFileName ( ) ; if ( ! file_exists ( $ fileName ) ) { continue ; } $ content = $ this -> fileBackend -> loadFromFile ( $ fileName ) ; $ content = $ this -> optimizeContent ( $ type , $ fileName , $ content ) ; $ typeContent .= $ content ; $ fileHashs [ $ this -> getHash ( $ fileName ) ] = md5_file ( $ fileName ) ; } if ( ( $ type === AssetManager :: CSS || $ type === AssetManager :: JS ) && $ this -> minifyAssets ) { $ typeContent = $ this -> minifyContent ( $ type , $ typeContent ) ; } $ hash = $ this -> getTypeHash ( $ type ) ; $ version = $ type . '-' . uniqid ( ) . '.' . $ this -> getExtensionForType ( $ type ) ; $ targetFile = $ this -> buildFilePath ( $ type , $ hash , $ version ) ; $ this -> removeOldTypeCacheFile ( $ type ) ; $ this -> fileBackend -> saveToFile ( $ typeContent , $ targetFile ) ; $ this -> cachedFiles [ $ hash ] = array ( 'file' => $ targetFile , 'checksums' => $ fileHashs , 'timestamp' => time ( ) ) ; $ this -> saveAssetsCache ( ) ; return $ targetFile ; } | Builds the cache for an asset type |
26,362 | protected function buildFileCache ( $ type , $ fileName ) { if ( ! file_exists ( $ fileName ) ) { return false ; } $ content = $ this -> fileBackend -> loadFromFile ( $ fileName ) ; $ content = $ this -> optimizeContent ( $ type , $ fileName , $ content ) ; if ( ( $ type === AssetManager :: CSS || $ type === AssetManager :: JS ) && $ this -> minifyAssets ) { $ content = $ this -> minifyContent ( $ type , $ content ) ; } $ fileInfo = pathinfo ( $ fileName ) ; $ hash = $ this -> getHash ( $ fileName ) ; $ version = $ fileInfo [ 'filename' ] . '-' . uniqid ( ) . '.' . $ fileInfo [ 'extension' ] ; $ targetFile = $ this -> buildFilePath ( $ type , $ hash , $ version ) ; $ this -> removeOldCacheFile ( $ fileName ) ; $ this -> fileBackend -> saveToFile ( $ content , $ targetFile ) ; $ this -> cachedFiles [ $ hash ] = array ( 'file' => $ targetFile , 'checksum' => md5_file ( $ fileName ) , 'timestamp' => time ( ) ) ; $ this -> saveAssetsCache ( ) ; return $ targetFile ; } | Generates the cache for the given files . |
26,363 | protected function removeCacheFile ( $ hash ) { if ( ! $ this -> hasCachedFile ( $ hash ) ) { return false ; } $ fileData = $ this -> cachedFiles [ $ hash ] ; $ this -> fileBackend -> deleteFile ( $ fileData [ 'file' ] ) ; } | Deletes the cache file for the given hash |
26,364 | protected function validateCache ( $ fileName ) { $ hash = $ this -> getHash ( $ fileName ) ; if ( ! file_exists ( $ fileName ) || ! isset ( $ this -> cachedFiles [ $ hash ] ) ) { return false ; } $ fileChecksum = md5_file ( $ fileName ) ; $ cachedChecksum = $ this -> cachedFiles [ $ hash ] [ 'checksum' ] ; if ( $ fileChecksum != $ cachedChecksum ) { return false ; } return true ; } | Returns false if the cached version of the given file isn t up to date . |
26,365 | protected function validateTypeCache ( $ type , $ files ) { $ hash = $ this -> getTypeHash ( $ type ) ; if ( ! isset ( $ this -> cachedFiles [ $ hash ] ) ) { return false ; } $ data = $ this -> cachedFiles [ $ hash ] ; $ checksums = $ data [ 'checksums' ] ; foreach ( $ files as $ file ) { if ( ! file_exists ( $ file -> getFileName ( ) ) ) { return false ; } $ fileHash = $ this -> getHash ( $ file -> getFileName ( ) ) ; $ contentHash = md5_file ( $ file -> getFileName ( ) ) ; if ( ! isset ( $ checksums [ $ fileHash ] ) || $ contentHash !== $ checksums [ $ fileHash ] ) { return false ; } } return true ; } | Validates the cache for an asset type . Return false if the cache isn t valid . |
26,366 | protected function generateHtmlCode ( $ type , $ file ) { $ url = $ this -> getUrlToTheAssetLoader ( $ file ) ; if ( $ type === AssetManager :: CSS ) { return '<link rel="stylesheet" type="text/css" href="' . $ url . '">' . PHP_EOL ; } else if ( $ type === AssetManager :: JS ) { return '<script type="text/javascript" src="' . $ url . '"></script>' . PHP_EOL ; } } | Generates the html code for the given asset |
26,367 | public function setDiscriminatorField ( $ discriminatorField ) { if ( $ discriminatorField === null ) { $ this -> discriminatorField = null ; return ; } if ( is_array ( $ discriminatorField ) ) { if ( isset ( $ discriminatorField [ 'name' ] ) ) { $ discriminatorField = $ discriminatorField [ 'name' ] ; } elseif ( isset ( $ discriminatorField [ 'fieldName' ] ) ) { $ discriminatorField = $ discriminatorField [ 'fieldName' ] ; } } foreach ( $ this -> fieldMappings as $ fieldMapping ) { if ( $ discriminatorField == $ fieldMapping [ 'name' ] ) { throw MappingException :: discriminatorFieldConflict ( $ this -> name , $ discriminatorField ) ; } } $ this -> discriminatorField = $ discriminatorField ; } | Sets the discriminator field . |
26,368 | public static function deleteRecursive ( $ pDir ) { $ files = glob ( $ pDir . '*' , GLOB_MARK ) ; foreach ( $ files as $ file ) { if ( substr ( $ file , - 1 ) == '/' ) { self :: deleteRecursive ( $ file ) ; } else { unlink ( $ file ) ; } } if ( is_dir ( $ pDir ) ) { rmdir ( $ pDir ) ; } return true ; } | Recursive deletion of a directory . |
26,369 | public static function chmod ( $ pDir , $ pMode ) { if ( strpos ( $ pMode , '0' ) !== 0 ) { $ mode = octdec ( '0' . $ pMode ) ; } else { $ mode = octdec ( $ pMode ) ; } return chmod ( $ pDir , $ mode ) ; } | CHMOD a directory . |
26,370 | public static function word_substr ( $ text , $ from , $ minlength , $ maxlength ) { $ text = mb_substr ( $ text , $ from , $ maxlength ) ; $ p1 = strrpos ( $ text , ' ' ) ; if ( $ p1 >= $ minlength ) { return mb_substr ( $ text , 0 , $ p1 ) ; } return $ text ; } | This function does the substr function but does not end the string in the middle of the word if the end is between min and max length . |
26,371 | public function generate ( ReflectionClass $ class , array $ methods , array $ uncovered ) : void { $ this -> objectUnderTest = $ class ; $ this -> features = [ ] ; foreach ( $ methods as $ method ) { if ( isset ( $ uncovered [ $ method -> name ] ) && $ uncovered [ $ method -> name ] ) { $ this -> addFeature ( $ class , $ method , $ uncovered [ $ method -> name ] ) ; } } $ this -> write ( ) ; } | Generates stub test methods for all found features . |
26,372 | private function addFeature ( ReflectionClass $ class , ReflectionMethod $ method , array $ calls ) : void { Formatter :: out ( "<gray> Adding tests for feature <magenta>{$class->name}::{$method->name}\n" ) ; $ tested = $ method -> name ; $ this -> features [ $ method -> name ] = ( object ) [ 'calls' => [ ] ] ; foreach ( $ calls as $ call ) { $ arglist = [ ] ; foreach ( $ call as $ idx => $ p ) { if ( $ p == 'NULL' ) { $ arglist [ ] = 'null' ; } elseif ( isset ( $ arguments [ $ idx + 1 ] ) ) { preg_match ( '@\$\w+@' , "{$arguments[$idx + 1]}" , $ matches ) ; $ arglist [ ] = $ matches [ 0 ] ; } else { $ arglist [ ] = $ this -> getDefaultForType ( $ p , self :: AS_INSTANCE ) ; } } $ mt = $ method -> isStatic ( ) ? '::' : '->' ; $ expectedResult = 'true' ; if ( $ method -> hasReturnType ( ) ) { $ type = $ method -> getReturnType ( ) -> __toString ( ) ; $ expectedResult = $ this -> getDefaultForType ( $ type , self :: AS_RETURNCHECK ) ; } $ this -> features [ $ method -> name ] -> calls [ ] = ( object ) [ 'name' => $ method -> name , 'parameters' => implode ( ', ' , $ arglist ) , 'expectedResult' => $ expectedResult , ] ; } } | Internal method to add a testable feature . |
26,373 | public function write ( ) : void { if ( ! $ this -> features ) { return ; } $ i = 0 ; while ( true ) { $ file = sprintf ( '%s/%s%s.php' , $ this -> config -> output , $ this -> normalize ( $ this -> objectUnderTest -> getName ( ) ) , $ i ? ".$i" : '' ) ; if ( ! file_exists ( $ file ) ) { break ; } ++ $ i ; } file_put_contents ( $ file , $ this -> render ( ) ) ; } | Actually write the generated stubs to file . If a file by the name of the feature already exists a number is appended . |
26,374 | private function render ( ) : string { return $ this -> twig -> render ( 'template.html.twig' , [ 'namespace' => $ this -> config -> namespace ?? null , 'objectUnderTest' => $ this -> objectUnderTest -> name , 'features' => $ this -> features , ] ) ; } | Renders the testing code according to the supplied template . |
26,375 | private function getDefaultForType ( string $ type , int $ mode = 0 ) : string { $ isClass = false ; switch ( $ type ) { case 'string' : $ value = "'blarps'" ; break ; case 'int' : $ value = '1' ; break ; case 'float' : $ value = '1.1' ; break ; case 'mixed' : $ value = "'MIXED'" ; break ; case 'callable' : $ value = 'function () {}' ; break ; case 'bool' : $ value = 'true' ; break ; case 'array' : $ value = '[]' ; break ; default : if ( class_exists ( $ type ) ) { $ isClass = true ; } $ value = $ type ; } switch ( $ mode ) { case self :: AS_INSTANCE : if ( $ isClass ) { return "new $value" ; } else { return $ value ; } case self :: AS_RETURNCHECK : if ( $ isClass ) { return "\$result instanceof $value" ; } elseif ( $ value === 'array' ) { return "is_array(\$result)" ; } elseif ( $ value == 'callable' ) { return "is_callable(\$result)" ; } else { return "\$result === $value" ; } default : return $ type ; } } | Get a string representation of a default value for a given type . |
26,376 | public function remove ( Interfaces \ IElement $ element ) { if ( $ this -> elements -> contains ( $ element ) ) { $ this -> elements -> detach ( $ element ) ; } return $ this ; } | Remove a JSONLD element |
26,377 | public function replaceTokens ( $ tokens ) { $ keys = array_keys ( $ tokens ) ; $ values = array_values ( $ tokens ) ; return str_replace ( $ keys , $ values , $ this -> getExpression ( ) ) ; } | replace tokens and return new string |
26,378 | protected static function _getEngine ( ) { if ( ! self :: $ _Engine ) { self :: $ _Engine = ClassRegistry :: init ( 'DBConfigure.' . self :: $ _EngineName ) ; } return self :: $ _Engine ; } | Return engine instance |
26,379 | protected static function _buildWriteParams ( $ params = array ( ) ) { $ writeParams [ 'equalKeysOnly' ] = ( isset ( $ params [ 'equalKeysOnly' ] ) && empty ( $ params [ 'equalKeysOnly' ] ) ? false : true ) ; return $ writeParams ; } | Build write params |
26,380 | public function createAuthorizationHeader ( $ includePrefix = false ) { $ headerParams = array ( 'oauth_signature' => $ this -> signature -> sign ( ) , 'oauth_nonce' => $ this -> signature -> getNonce ( ) , 'oauth_signature_method' => $ this -> signature -> getSignatureMethod ( ) , 'oauth_timestamp' => $ this -> signature -> getTimestamp ( ) , 'oauth_consumer_key' => $ this -> signature -> getConsumer ( ) -> getIdentifier ( ) , 'oauth_token' => $ this -> signature -> getUser ( ) -> getIdentifier ( ) , 'oauth_version' => $ this -> signature -> getVersion ( ) ) ; if ( ( $ callback = $ this -> signature -> getCallback ( ) ) !== '' ) { $ headerParams [ 'oauth_callback' ] = $ callback ; } if ( ( $ verifier = $ this -> signature -> getVerifier ( ) ) !== '' ) { $ headerParams [ 'oauth_verifier' ] = $ verifier ; } $ tempArray = array ( ) ; ksort ( $ headerParams ) ; foreach ( $ headerParams as $ key => $ value ) { $ tempArray [ ] = $ key . '="' . rawurlencode ( $ value ) . '"' ; } $ prefix = "Authorization: " ; $ headerString = 'OAuth ' . implode ( ', ' , $ tempArray ) ; return ( $ includePrefix ) ? $ prefix . $ headerString : $ headerString ; } | Build the authorization header |
26,381 | public static function getDateTime ( $ datetime = null ) { if ( $ datetime instanceof \ DateTime ) { return clone $ datetime ; } if ( $ datetime instanceof \ DateTimeImmutable ) { return new \ DateTime ( $ datetime -> format ( \ DateTime :: ATOM ) ) ; } if ( \ is_string ( $ datetime ) ) { if ( \ is_numeric ( $ datetime ) ) { $ isTs = ! preg_match ( '/^(19|20)\d{2}(0[1-9]|1[0-2])[0-3][0-9](([01]\d|2[0-3])\d[0-5]\d[0-5]\d)?$/' , $ datetime ) ; if ( $ isTs ) { $ datetime = '@' . $ datetime ; } } Debug :: _log ( 'datetime' , $ datetime ) ; return new \ DateTime ( $ datetime ) ; } if ( \ is_int ( $ datetime ) || \ is_float ( $ datetime ) ) { $ dateTime = new \ DateTime ( ) ; $ dateTime -> setTimestamp ( $ datetime ) ; return $ dateTime ; } return new \ DateTime ( ) ; } | Return a datetime obj |
26,382 | public static function getNextBusinessDay ( $ datetime , $ holidays = array ( ) ) { $ dateParts = self :: getdate ( $ datetime ) ; $ ts = \ mktime ( 0 , 0 , 0 , $ dateParts [ 'mon' ] , $ dateParts [ 'mday' ] + 1 , $ dateParts [ 'year' ] ) ; $ goodDate = false ; while ( ! $ goodDate ) { $ dateParts = \ getdate ( $ ts ) ; if ( $ dateParts [ 'weekday' ] == 'Saturday' ) { $ ts = \ mktime ( 0 , 0 , 0 , $ dateParts [ 'mon' ] , $ dateParts [ 'mday' ] + 2 , $ dateParts [ 'year' ] ) ; } elseif ( $ dateParts [ 'weekday' ] == 'Sunday' ) { $ ts = \ mktime ( 0 , 0 , 0 , $ dateParts [ 'mon' ] , $ dateParts [ 'mday' ] + 1 , $ dateParts [ 'year' ] ) ; } elseif ( \ in_array ( \ date ( 'Ymd' , $ ts ) , $ holidays ) ) { $ ts = \ mktime ( 0 , 0 , 0 , $ dateParts [ 'mon' ] , $ dateParts [ 'mday' ] + 1 , $ dateParts [ 'year' ] ) ; } else { $ goodDate = true ; } } return self :: getDateTime ( $ ts ) ; } | Given passed datetime return DateTime of next business day |
26,383 | public static function getRelTime ( $ datetime , $ datetimeFrom = null ) { $ ret = '' ; $ dateTime = self :: getDateTime ( $ datetime ) ; $ dateTimeFrom = self :: getDateTime ( $ datetimeFrom ) ; $ dateTimeSameDay = clone $ dateTimeFrom ; $ dateTimeSameDay -> setTime ( 0 , 0 , 0 ) ; $ diffSec = $ dateTimeFrom -> getTimestamp ( ) - $ dateTime -> getTimestamp ( ) ; if ( $ dateTime > $ dateTimeFrom ) { $ dateTimeTest = clone $ dateTimeSameDay ; if ( $ dateTime < $ dateTimeTest -> modify ( 'tomorrow' ) ) { $ ret = 'Today at ' . $ dateTime -> format ( 'g:ia' ) ; } elseif ( $ dateTime < $ dateTimeTest -> modify ( '+2 days' ) ) { $ ret = 'Tomorrow at ' . $ dateTime -> format ( 'g:ia' ) ; } else { $ ret = $ dateTime -> format ( 'F jS' ) ; } } elseif ( $ diffSec < 60 ) { $ ret = 'Just now' ; } elseif ( $ diffSec < 3600 ) { $ ret = \ round ( ( $ diffSec ) / 60 ) . ' min ago' ; } elseif ( $ diffSec < 3600 * 6 ) { $ hrs = \ round ( ( $ diffSec ) / 3600 ) ; $ ret = $ hrs . ' ' . Str :: plural ( $ hrs , 'hour' ) . ' ago' ; } elseif ( $ dateTime > $ dateTimeSameDay ) { $ ret = 'Today at ' . $ dateTime -> format ( 'g:ia' ) ; } elseif ( $ dateTime -> getTimestamp ( ) >= $ dateTimeSameDay -> getTimestamp ( ) - 86400 ) { $ ret = 'Yesterday at ' . $ dateTime -> format ( 'g:ia' ) ; } elseif ( $ dateTime -> getTimestamp ( ) >= $ dateTimeSameDay -> getTimestamp ( ) - 86400 * 7 ) { $ ret = $ dateTime -> format ( 'l \a\t g:ia' ) ; } elseif ( $ dateTime -> getTimestamp ( ) > \ mktime ( 0 , 0 , 0 , 1 , 1 ) ) { $ ret = $ dateTime -> format ( 'F jS' ) ; } else { $ ret = $ dateTime -> format ( 'F jS, Y' ) ; } $ ret = \ str_replace ( ' at 12:00am' , '' , $ ret ) ; return $ ret ; } | Return a 3 hours ago type string for passed timestamp |
26,384 | public function get_handler ( ) { $ handler = new PrettyPageHandler ( ) ; $ handler -> addDataTableCallback ( '$wp_query' , [ $ this , 'add_query' ] ) ; $ handler -> addDataTableCallback ( '$post' , [ $ this , 'add_post' ] ) ; $ handler -> addDataTableCallback ( '$wp' , [ $ this , 'add_wp' ] ) ; return $ handler ; } | Return the Whoops PrettyPageHandler . |
26,385 | public function add_query ( ) { global $ wp_query ; if ( ! $ wp_query instanceof WP_Query ) { return [ ] ; } $ output = \ get_object_vars ( $ wp_query ) ; $ output [ 'query_vars' ] = \ array_filter ( $ output [ 'query_vars' ] ) ; unset ( $ output [ 'posts' ] , $ output [ 'post' ] ) ; return \ array_filter ( $ output ) ; } | Add the WP_Query global to Whoops data list . |
26,386 | public function add_wp ( ) { global $ wp ; if ( ! $ wp instanceof WP ) { return array ( ) ; } $ output = \ get_object_vars ( $ wp ) ; unset ( $ output [ 'private_query_vars' ] , $ output [ 'public_query_vars' ] ) ; return \ array_filter ( $ output ) ; } | Add the WP global to Whoops data list . |
26,387 | public static function dispatcher ( $ name ) { static $ all = [ ] ; if ( ! isset ( $ all [ $ name ] ) ) { if ( Helper :: isSystemInstall ( ) ) { $ cache = new Cache ( $ name , 'events' ) ; if ( $ cache -> ready ( ) ) { $ data = $ cache -> import ( ) ; } else { $ event = new EventFactory ( $ name ) ; if ( $ event -> load ( ) === false ) { throw new NotFoundException ( "Event '{$name}' is not registered in system" ) ; } $ data = $ event -> getContentData ( ) ; if ( ! $ cache -> export ( $ data ) ) { throw new WriteException ( "Can't write cache data for the '{$name}' event" ) ; } } } else { $ data = ( new EventFactory ( $ name ) ) -> getContentData ( ) ; } $ manager = new Dispatcher ( $ data [ "name" ] , $ data [ "completable" ] , function ( Dispatcher $ manager ) use ( $ data ) { foreach ( $ data [ "classes" ] as $ class_name ) { $ class = new $ class_name ( $ data [ "name" ] ) ; $ class -> prepare ( $ manager ) ; } } ) ; $ all [ $ name ] = $ manager ; } return $ all [ $ name ] ; } | Get event manager element from cache |
26,388 | protected function error ( $ msg , array $ bind = [ ] ) { foreach ( $ bind as $ key => $ value ) { if ( is_null ( $ value ) ) { $ value = 'NULL' ; } elseif ( is_bool ( $ value ) ) { $ value = $ value ? 'true' : 'false' ; } $ msg .= "$key => $value\n" ; } return $ msg ; } | Internal helper to correctly format error messages . |
26,389 | private function parseCapturingGroup ( $ group , $ charBefore , $ charAfter ) { $ split = explode ( ':' , $ group ) ; $ key = trim ( $ split [ 0 ] ) ; if ( $ key === '' || $ key == '.' ) { throw new \ InvalidArgumentException ( 'Invalid capturing group' ) ; } $ this -> keys [ ] = $ key ; if ( ! isset ( $ split [ 1 ] ) ) { if ( $ charAfter !== '' || $ charBefore !== '' ) { return sprintf ( '([^%s]+)' , preg_quote ( $ charAfter !== '' ? $ charAfter : $ charBefore , '/' ) ) ; } return '(.+)' ; } $ specifier = trim ( $ split [ 1 ] ) ; if ( $ specifier === '0' ) { throw new \ InvalidArgumentException ( 'Invalid length specifier: 0' ) ; } $ type = substr ( $ specifier , - 1 ) ; switch ( $ type ) { case 'd' : case 's' : $ len = trim ( substr ( $ specifier , 0 , - 1 ) ) ; if ( $ len === '' ) { $ len = '1,' ; } else { if ( ! $ this -> canCastToInteger ( $ len ) || intval ( $ len ) === 0 ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid length specifier: %s' , $ len ) ) ; } } break ; case 'f' : $ len = trim ( substr ( $ specifier , 0 , - 1 ) ) ; if ( $ len === '' ) { $ lenBeforeDec = $ lenAfterDec = '1,' ; } else { if ( $ len [ 0 ] == '.' ) { $ lenBeforeDec = '0,' ; $ lenAfterDec = substr ( $ len , 1 ) ; } else if ( substr ( $ len , - 1 ) == '.' ) { $ lenBeforeDec = substr ( $ len , 0 , - 1 ) ; $ lenAfterDec = '0,' ; } else { if ( $ len === '0.0' || $ len === '0' ) { throw new \ InvalidArgumentException ( 'Invalid length specifier: 0.0' ) ; } $ split = explode ( '.' , $ len ) ; $ lenBeforeDec = trim ( $ split [ 0 ] ) ; $ lenAfterDec = trim ( $ split [ 1 ] ) ; } } break ; default : $ len = $ specifier ; if ( ! $ this -> canCastToInteger ( $ len ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid length specifier: %s' , $ specifier ) ) ; } } switch ( $ type ) { case 'd' : return sprintf ( '(\d{%s})' , $ len ) ; case 'f' : return sprintf ( '([-+]?\d{%s}\.\d{%s})' , $ lenBeforeDec , $ lenAfterDec ) ; default : return sprintf ( '(.{%s})' , $ len ) ; } } | Parses a raw capturing group into a RegEx capturing group |
26,390 | public static function getMonthEnd ( $ month = - 1 , $ year = - 1 ) { if ( $ month == - 1 ) { $ month = date ( "n" ) ; } if ( $ year == - 1 ) { $ year = date ( "Y" ) ; } $ tempTime = mktime ( 0 , 0 , 0 , $ month , 1 , $ year ) ; $ tempTime = date ( "t" , $ tempTime ) ; return mktime ( 23 , 59 , 59 , $ month , $ tempTime , $ year ) ; } | returns a timestamp of the end of a month |
26,391 | public static function getFormatedDate ( $ timestamp ) { return MTimestampHelper :: getDay ( $ timestamp ) . "." . MTimestampHelper :: getMonth ( $ timestamp ) . "." . MTimestampHelper :: getYear ( $ timestamp ) ; } | returns the given timestamp in a manner like |
26,392 | public function inTransaction ( callable $ function ) { if ( ! is_callable ( $ function ) ) { throw new InvalidArgumentException ( '$function must be callable.' ) ; } $ this -> beginTransaction ( ) ; try { if ( func_num_args ( ) === 1 ) { $ returnValue = $ function ( $ this ) ; } else { $ args = func_get_args ( ) ; $ args [ 0 ] = $ this ; $ returnValue = call_user_func_array ( $ function , $ args ) ; } $ this -> commit ( ) ; return $ returnValue ; } catch ( \ PDOException $ e ) { $ this -> rollBack ( ) ; throw $ e ; } } | Call a function guarded by a transaction . |
26,393 | public function render ( Page $ page ) { return $ this -> doRender ( $ this -> getRawContent ( ) , $ this -> getAttributes ( ) + [ 'content' => $ page -> getRenderedContent ( ) ] ) ; } | Render the layout with a given Page . |
26,394 | public function parameterTypeCheck ( $ param , string $ type = 'string' ) : bool { $ type = 'is_' . $ type ; return ( bool ) ( $ type ( $ param ) && ! empty ( $ param ) ) ; } | Parameter type check . |
26,395 | public function arrayKeyExistsRecursive ( string $ needle , array $ haystack ) : bool { $ result = array_key_exists ( $ needle , $ haystack ) ; if ( true === $ result ) { return $ result ; } $ this -> arrayKeyExistsRecursiveExtended ( $ needle , $ haystack ) ; return $ result ; } | Recursive version of array_key_exists . |
26,396 | public function arrayKeyExistsRecursiveExtended ( string $ needle , array $ haystack ) : bool { $ result = false ; foreach ( $ haystack as $ value ) { if ( true === is_array ( $ value ) ) { $ result = $ this -> arrayKeyExistsRecursive ( $ needle , $ value ) ; } if ( true === $ result ) { return $ result ; } } return $ result ; } | Recursive version extended sub - function . |
26,397 | public function getTitledItem ( string $ str , string $ item = null , string $ delimiter = ';' ) : string { return ( null === $ item ) ? trim ( substr ( trim ( substr ( $ str , 0 ) ) , 0 , $ this -> getStringPositionX ( trim ( substr ( $ str , 0 ) ) , $ delimiter , 1 ) ) ) : trim ( substr ( trim ( substr ( $ str , $ this -> getStringPositionX ( $ str , $ item , 1 ) + strlen ( $ item ) ) ) , 0 , $ this -> getStringPositionX ( trim ( substr ( $ str , $ this -> getStringPositionX ( $ str , $ item , 1 ) + strlen ( $ item ) ) ) , $ delimiter , 1 ) ) ) ; } | A parser for title delimited data . |
26,398 | protected function sftpCreateDirectory ( ) : FunctionsInterface { if ( true === $ this -> get ( '_createRemoteDirectory' ) ) { ( file_exists ( $ this -> get ( '_localCacheFilePath' ) ) && $ this -> get ( '_localFileSize' ) > 0 ) ? $ this -> get ( '_sftp' ) -> deleteDirectory ( $ this -> get ( '_remoteDirectoryPath' ) , true ) -> createDirectory ( $ this -> get ( '_remoteDirectoryPath' ) ) : $ this -> get ( '_sftp' ) -> deleteDirectory ( $ this -> get ( '_remoteDirectoryPath' ) , true ) ; } return $ this ; } | Handling new directory creation . |
26,399 | protected function sftpTransport ( ServiceRequestContainer $ service , string $ account ) : FunctionsInterface { $ this -> set ( '_account' , $ account ) -> set ( '_sftp' , $ service -> Sftp ) -> set ( '_persist' , $ service -> Persistence ) -> set ( '_localCacheFilePath' , $ this -> get ( 'localCacheFilePath' ) ) -> set ( '_remoteFilePath' , $ service -> Database -> viewData [ 'remoteFilePath' ] ) -> set ( '_remoteDirectoryPath' , $ service -> Database -> viewData [ 'remoteDirectoryPath' ] ) -> set ( '_createRemoteDirectory' , $ service -> Database -> viewData [ 'sftpCreateRemoteDirectory' ] ) -> set ( '_accountSettings' , $ service -> ConfigurationVault -> openVaultFile ( 'account' , $ account ) -> all ( ) ) -> set ( '_localFileSize' , ( file_exists ( $ this -> get ( '_localCacheFilePath' ) ) ? filesize ( $ this -> get ( '_localCacheFilePath' ) ) : 0 ) ) ; $ this -> get ( '_sftp' ) -> connect ( $ this -> get ( '_accountSettings' ) ) ; return $ this -> sftpCreateDirectory ( ) -> sftpUploadFile ( ) -> sftpRecordFileSizes ( ) -> sftpCompareFileSizes ( ) ; } | Upload file to remote server . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.