idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
23,400 | public function get ( $ name , $ default = null ) { $ row = $ this -> current ( ) ; if ( $ this -> _as_object ) { if ( isset ( $ row -> $ name ) ) { return $ row -> $ name ; } } else { if ( isset ( $ row [ $ name ] ) ) { return $ row [ $ name ] ; } } return \ Fuel :: value ( $ default ) ; } | Return the named column from the current row . |
23,401 | public function getItemProviders ( ) { foreach ( $ this -> modules -> enabled ( ) as $ module ) { $ name = studly_case ( $ module -> getName ( ) ) ; $ class = 'Modules\\' . $ name . '\\MenuExtenders\\MenuExtender' ; if ( class_exists ( $ class ) ) { $ extender = $ this -> container -> make ( $ class ) ; $ this -> extenders -> put ( $ module -> getName ( ) , [ 'content' => $ extender -> getContentItems ( ) , 'static' => $ extender -> getStaticItems ( ) , ] ) ; } } return $ this -> extenders ; } | Build the menu structure . |
23,402 | public function buildMenus ( ) { $ menu = Menu :: whereIsRoot ( ) -> get ( ) ; foreach ( $ menu as $ item ) { LavaryMenu :: make ( Str :: slug ( $ item -> name ) , function ( $ menu ) use ( $ item ) { $ this -> buildMenuItems ( $ menu , $ item ) ; } ) ; } } | Build all Menus . |
23,403 | public function init ( ) { if ( ! Config :: config ( ) [ 'user' ] [ 'debug' ] [ 'maintenance' ] ) { date_default_timezone_set ( Config :: config ( ) [ 'user' ] [ 'output' ] [ 'timezone' ] ) ; $ this -> _setEnvironment ( ) ; $ this -> _route ( ) ; if ( $ this -> _route == true ) { $ this -> _setDatabase ( ) ; $ this -> _setSecure ( ) ; $ this -> _setLibrary ( ) ; $ this -> _setEvent ( ) ; $ this -> _setCron ( ) ; $ this -> _setFunction ( ) ; $ this -> _setFunction ( $ this -> request -> src ) ; $ this -> _setEvent ( $ this -> request -> src ) ; } } } | initialization of the engine |
23,404 | public function initCron ( $ src , $ controller , $ action ) { if ( ! Config :: config ( ) [ 'user' ] [ 'debug' ] [ 'maintenance' ] ) { $ this -> _routeCron ( $ src , $ controller , $ action ) ; if ( $ this -> _route == true ) { $ this -> _setFunction ( $ this -> request -> src ) ; $ this -> _setEvent ( $ this -> request -> src ) ; } } } | initialization of the engine for cron |
23,405 | private function _routeCron ( $ src , $ controller , $ action ) { $ this -> request -> name = '-' . $ src . '_' . $ controller . '_' . $ action ; $ this -> request -> src = $ src ; $ this -> request -> controller = $ controller ; $ this -> request -> action = $ action ; $ this -> request -> auth = new Auth ( $ this -> request -> src ) ; $ this -> _route = true ; } | routing with cron |
23,406 | public function _action ( & $ class ) { ob_start ( ) ; $ annotation = Annotation :: getClass ( $ class ) ; $ this -> _callAnnotation ( $ class , $ annotation , 'class' , 'Before' ) ; if ( method_exists ( $ class , 'action' . ucfirst ( $ this -> request -> action ) ) ) { $ this -> _callAnnotation ( $ class , $ annotation , 'methods' , 'Before' ) ; $ action = 'action' . ucfirst ( $ this -> request -> action ) ; $ params = Injector :: instance ( ) -> getArgsMethod ( $ class , $ action ) ; $ reflectionMethod = new \ ReflectionMethod ( $ class , $ action ) ; $ output = $ reflectionMethod -> invokeArgs ( $ class , $ params ) ; $ this -> _callAnnotation ( $ class , $ annotation , 'methods' , 'After' ) ; $ this -> addError ( 'Action "' . $ this -> request -> src . '/' . ucfirst ( $ this -> request -> controller ) . '/action' . ucfirst ( $ this -> request -> action ) . '" called successfully' , __FILE__ , __LINE__ , ERROR_INFORMATION ) ; } else { throw new Exception ( 'The requested "' . $ this -> request -> src . '/' . ucfirst ( $ this -> request -> controller ) . '/action' . ucfirst ( $ this -> request -> action ) . '" doesn\'t exist' ) ; } $ this -> _callAnnotation ( $ class , $ annotation , 'class' , 'After' ) ; $ output = ob_get_contents ( ) . $ output ; ob_get_clean ( ) ; return $ output ; } | call action from controller |
23,407 | protected function _callAnnotation ( Controller & $ class , $ annotation = [ ] , $ type = 'class' , $ annotationType = 'Before' ) { foreach ( $ annotation [ $ type ] as $ action => $ annotationClasses ) { foreach ( $ annotationClasses as $ annotationClass ) { if ( $ annotationClass [ 'annotation' ] == $ annotationType ) { $ instance = $ annotationClass [ 'instance' ] ; $ className = $ instance -> class ; $ methodName = $ instance -> method ; if ( method_exists ( $ className , $ methodName ) ) { if ( $ className == get_class ( $ class ) ) { $ class -> $ methodName ( ) ; } else { $ reflectionMethod = new \ ReflectionMethod ( $ className , $ methodName ) ; echo $ reflectionMethod -> invoke ( new $ className ( ) ) ; } } else { throw new MissingMethodException ( 'The method "' . $ methodName . '" from the class "' . $ className . '" does not exist' ) ; } } } } } | call all annotation methods required |
23,408 | protected function _setControllerFile ( $ src , $ controller ) { $ controllerPath = SRC_PATH . $ src . '/' . SRC_CONTROLLER_PATH . ucfirst ( $ controller ) . '.php' ; if ( file_exists ( $ controllerPath ) ) { require_once ( $ controllerPath ) ; return true ; } return false ; } | include the module |
23,409 | public function run ( ) { if ( ! Config :: config ( ) [ 'user' ] [ 'debug' ] [ 'maintenance' ] ) { if ( $ this -> _route == false ) { $ this -> response -> status ( 404 ) ; $ this -> addError ( 'routing failed : http://' . $ this -> request -> env ( 'HTTP_HOST' ) . $ this -> request -> env ( 'REQUEST_URI' ) , __FILE__ , __LINE__ , ERROR_WARNING ) ; } else { $ this -> _controller ( ) ; } $ this -> response -> run ( ) ; $ this -> addErrorHr ( LOG_ERROR ) ; $ this -> addErrorHr ( LOG_SYSTEM ) ; $ this -> _setHistory ( '' ) ; if ( Config :: config ( ) [ 'user' ] [ 'output' ] [ 'minify' ] && preg_match ( '#text/html#isU' , $ this -> response -> contentType ( ) ) ) { $ this -> response -> page ( $ this -> _minifyHtml ( $ this -> response -> page ( ) ) ) ; } if ( Config :: config ( ) [ 'user' ] [ 'debug' ] [ 'environment' ] == 'development' && Config :: config ( ) [ 'user' ] [ 'debug' ] [ 'profiler' ] ) { $ this -> profiler -> profiler ( $ this -> request , $ this -> response ) ; } } else { $ this -> response -> page ( $ this -> maintenance ( ) ) ; } echo $ this -> response -> page ( ) ; } | display the page |
23,410 | public function runCron ( ) { if ( ! Config :: config ( ) [ 'user' ] [ 'debug' ] [ 'maintenance' ] ) { $ this -> _controller ( ) ; $ this -> _setHistory ( 'CRON' ) ; } echo $ this -> response -> page ( ) ; } | display the page for a cron |
23,411 | private function _setHistory ( $ message ) { $ this -> addError ( 'URL : http://' . $ this -> request -> env ( 'HTTP_HOST' ) . $ this -> request -> env ( 'REQUEST_URI' ) . ' (' . $ this -> response -> status ( ) . ') / SRC "' . $ this -> request -> src . '" / CONTROLLER "' . $ this -> request -> controller . '" / ACTION "' . $ this -> request -> action . '" / CACHE "' . $ this -> request -> cache . '" / ORIGIN : ' . $ this -> request -> env ( 'HTTP_REFERER' ) . ' / IP : ' . $ this -> request -> env ( 'REMOTE_ADDR' ) . ' / ' . $ message , 0 , 0 , 0 , LOG_HISTORY ) ; } | log request in history |
23,412 | public function addCredential ( $ type ) { $ this -> data_type = $ type ; $ this -> setTitleEditCredential ( ) ; $ this -> setBreadcrumbEditCredential ( ) ; $ this -> credential -> callHandler ( $ type , 'edit' ) ; } | Route page callback Displays the add credential page |
23,413 | public function editCredential ( $ credential_id ) { $ this -> setCredential ( $ credential_id ) ; $ this -> setTitleEditCredential ( ) ; $ this -> setBreadcrumbEditCredential ( ) ; $ this -> setData ( 'credential' , $ this -> data_credential ) ; $ this -> submitDeleteCredential ( ) ; $ this -> credential -> callHandler ( $ this -> data_credential [ 'type' ] , 'edit' ) ; } | Route page callback Displays the edit credential page |
23,414 | protected function setCredential ( $ credential_id ) { if ( is_numeric ( $ credential_id ) ) { $ this -> data_credential = $ this -> credential -> get ( $ credential_id ) ; if ( empty ( $ this -> data_credential ) ) { $ this -> outputHttpStatus ( 404 ) ; } } } | Sets the credential data |
23,415 | protected function setTitleEditCredential ( ) { if ( isset ( $ this -> data_credential [ 'name' ] ) ) { $ text = $ this -> text ( 'Edit %name' , array ( '%name' => $ this -> data_credential [ 'name' ] ) ) ; } else { $ text = $ this -> text ( 'Add credential' ) ; } $ this -> setTitle ( $ text ) ; } | Set titles on the edit credential page |
23,416 | protected function setBreadcrumbEditCredential ( ) { $ breadcrumbs = array ( ) ; $ breadcrumbs [ ] = array ( 'url' => $ this -> url ( 'admin' ) , 'text' => $ this -> text ( 'Dashboard' ) ) ; $ breadcrumbs [ ] = array ( 'text' => $ this -> text ( 'Google API credentials' ) , 'url' => $ this -> url ( 'admin/report/gapi' ) ) ; $ this -> setBreadcrumbs ( $ breadcrumbs ) ; } | Set breadcrumbs on the edit credential page |
23,417 | protected function validateKeyCredential ( ) { if ( ! $ this -> isPosted ( 'save' ) ) { return false ; } $ this -> setSubmitted ( 'credential' ) ; $ this -> validateElement ( array ( 'name' => $ this -> text ( 'Name' ) ) , 'length' , array ( 1 , 255 ) ) ; $ this -> validateElement ( array ( 'data.key' => $ this -> text ( 'Key' ) ) , 'length' , array ( 1 , 255 ) ) ; return ! $ this -> hasErrors ( ) ; } | Validates API key credential data |
23,418 | protected function validateOauthCredential ( ) { if ( ! $ this -> isPosted ( 'save' ) ) { return false ; } $ this -> setSubmitted ( 'credential' ) ; $ this -> validateElement ( array ( 'name' => $ this -> text ( 'Name' ) ) , 'length' , array ( 1 , 255 ) ) ; $ this -> validateElement ( array ( 'data.id' => $ this -> text ( 'Client ID' ) ) , 'length' , array ( 1 , 255 ) ) ; $ this -> validateElement ( array ( 'data.secret' => $ this -> text ( 'Client secret' ) ) , 'length' , array ( 1 , 255 ) ) ; return ! $ this -> hasErrors ( ) ; } | Validates OAuth credential data |
23,419 | protected function validateServiceCredential ( ) { if ( ! $ this -> isPosted ( 'save' ) ) { return false ; } $ this -> setSubmitted ( 'credential' ) ; $ this -> validateElement ( array ( 'name' => $ this -> text ( 'Name' ) ) , 'length' , array ( 1 , 255 ) ) ; $ this -> validateFileUploadCredential ( ) ; return ! $ this -> hasErrors ( ) ; } | Validates Service credential data |
23,420 | protected function validateFileUploadCredential ( ) { $ upload = $ this -> request -> file ( 'file' ) ; if ( empty ( $ upload ) ) { if ( ! isset ( $ this -> data_credential [ 'credential_id' ] ) ) { $ this -> setError ( 'data.file' , $ this -> text ( 'File is required' ) ) ; return false ; } return null ; } if ( $ this -> isError ( ) ) { return null ; } $ result = $ this -> file_transfer -> upload ( $ upload , false , gplcart_file_private_module ( 'gapi' ) ) ; if ( $ result !== true ) { $ this -> setError ( 'data.file' , $ result ) ; return false ; } $ file = $ this -> file_transfer -> getTransferred ( ) ; $ decoded = json_decode ( file_get_contents ( $ file ) , true ) ; if ( empty ( $ decoded [ 'private_key' ] ) ) { unlink ( $ file ) ; $ this -> setError ( 'data.file' , $ this -> text ( 'Failed to read JSON file' ) ) ; return false ; } if ( isset ( $ this -> data_credential [ 'data' ] [ 'file' ] ) ) { $ existing = gplcart_file_absolute ( $ this -> data_credential [ 'data' ] [ 'file' ] ) ; if ( file_exists ( $ existing ) ) { unlink ( $ existing ) ; } } $ this -> setSubmitted ( 'data.file' , gplcart_file_relative ( $ file ) ) ; return true ; } | Validates JSON file upload |
23,421 | protected function updateSubmittedCredential ( ) { $ this -> controlAccess ( 'module_gapi_credential_edit' ) ; if ( $ this -> credential -> update ( $ this -> data_credential [ 'credential_id' ] , $ this -> getSubmitted ( ) ) ) { $ this -> redirect ( 'admin/report/gapi' , $ this -> text ( 'Credential has been updated' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Credential has not been updated' ) , 'warning' ) ; } | Updates a submitted credential |
23,422 | protected function addSubmittedCredential ( ) { $ this -> controlAccess ( 'module_gapi_credential_add' ) ; $ submitted = $ this -> getSubmitted ( ) ; $ submitted [ 'type' ] = $ this -> data_type ; if ( $ this -> credential -> add ( $ submitted ) ) { $ this -> redirect ( 'admin/report/gapi' , $ this -> text ( 'Credential has been added' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Credential has not been added' ) , 'warning' ) ; } | Adds a submitted credential |
23,423 | protected function submitDeleteCredential ( ) { if ( $ this -> isPosted ( 'delete' ) && isset ( $ this -> data_credential [ 'credential_id' ] ) ) { $ this -> controlAccess ( 'module_gapi_credential_delete' ) ; if ( $ this -> credential -> callHandler ( $ this -> data_credential [ 'type' ] , 'delete' , array ( $ this -> data_credential [ 'credential_id' ] ) ) ) { $ this -> redirect ( 'admin/report/gapi' , $ this -> text ( 'Credential has been deleted' ) , 'success' ) ; } $ this -> redirect ( '' , $ this -> text ( 'Credential has not been deleted' ) , 'warning' ) ; } } | Delete a submitted credential |
23,424 | public function listCredential ( ) { $ this -> actionListCredential ( ) ; $ this -> setTitleListCredential ( ) ; $ this -> setBreadcrumbListCredential ( ) ; $ this -> setFilterListCredential ( ) ; $ this -> setPagerListCredential ( ) ; $ this -> setData ( 'credentials' , $ this -> getListCredential ( ) ) ; $ this -> setData ( 'handlers' , $ this -> credential -> getHandlers ( ) ) ; $ this -> outputListCredential ( ) ; } | Route callback Displays the credential overview page |
23,425 | protected function actionListCredential ( ) { list ( $ selected , $ action ) = $ this -> getPostedAction ( ) ; $ deleted = 0 ; foreach ( $ selected as $ id ) { if ( $ action === 'delete' && $ this -> access ( 'module_gapi_credential_delete' ) ) { $ credential = $ this -> credential -> get ( $ id ) ; $ deleted += ( int ) $ this -> credential -> callHandler ( $ credential [ 'type' ] , 'delete' , array ( $ credential [ 'credential_id' ] ) ) ; } } if ( $ deleted > 0 ) { $ message = $ this -> text ( 'Deleted %num item(s)' , array ( '%num' => $ deleted ) ) ; $ this -> setMessage ( $ message , 'success' ) ; } } | Applies an action to the selected credentials |
23,426 | protected function getListCredential ( ) { $ options = $ this -> query_filter ; $ options [ 'limit' ] = $ this -> data_limit ; return $ this -> credential -> getList ( $ options ) ; } | Returns an array of credentials |
23,427 | public function saveRememberedCustomName ( ) { if ( null === $ this -> rememberName || ! $ this -> hasLoadedLinks ( ) ) { return ; } foreach ( $ this -> collAttachmentLinks as $ attachmentLink ) { $ attachmentLink -> setCustomName ( $ this -> rememberName ) -> save ( ) ; } return $ this ; } | Save custom name to all loaded AttachmentLinks if it has been set from the outside . |
23,428 | public function getLinkForObject ( AttachableObjectInterface $ object , $ fieldName = null ) { return AttachmentLinkQuery :: create ( ) -> filterByAttachment ( $ this ) -> filterByAttachableObject ( $ object ) -> filterByModelField ( $ fieldName ) -> findOne ( ) ; } | Get the AttachmentLink for a specific attachable object and field name . |
23,429 | public static function getExcelColumnName ( $ num ) { $ num -- ; for ( $ name = '' ; $ num >= 0 ; $ num = intval ( $ num / 26 ) - 1 ) { $ name = chr ( $ num % 26 + 0x41 ) . $ name ; } return $ name ; } | Converts numbers to Excel - like column names A = 1 |
23,430 | public static function getExcelColumnNumber ( $ letters ) { $ num = 0 ; $ arr = array_reverse ( str_split ( $ letters ) ) ; $ arrSize = count ( $ arr ) ; for ( $ i = 0 ; $ i < $ arrSize ; $ i ++ ) { $ num += ( ord ( strtolower ( $ arr [ $ i ] ) ) - 96 ) * ( pow ( 26 , $ i ) ) ; } return $ num ; } | Converts Excel - like column names to numbers |
23,431 | private function initMethodDefinitionList ( ) { $ class = new \ ReflectionClass ( $ this -> className ) ; $ methods = $ class -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) ; foreach ( $ methods as $ reflect ) { if ( $ reflect -> class != $ this -> className ) { continue ; } $ docComment = $ reflect -> getDocComment ( ) ; $ phpDoc = array ( 'name' => $ reflect -> getName ( ) , 'definition' => implode ( "\n" , array_map ( 'trim' , explode ( "\n" , $ docComment ) ) ) ) ; $ this -> methodDefinitionList [ ] = $ phpDoc ; } } | Sets the array of the definitions of the methods . |
23,432 | public function getApiRequestUrl ( Event $ event ) { $ params = $ event -> getCustomParams ( ) ; $ country = $ params [ count ( $ params ) - 1 ] ; unset ( $ params [ count ( $ params ) - 1 ] ) ; $ place = trim ( implode ( "_" , preg_replace ( '/[^\da-z\ ]/i' , '' , $ params ) ) ) ; return sprintf ( "%s/%s/conditions/q/%s/%s.json" , $ this -> apiUrl , $ this -> appId , $ country , $ place ) ; } | Return the url for the API request |
23,433 | public static function instance ( ) { if ( empty ( static :: $ _modmgr ) ) { $ module = Yii :: $ app -> getModule ( static :: $ modulesManagerModuleUid ) ; if ( ! empty ( $ module ) && $ module instanceof UniModule ) { static :: $ _modmgr = $ module -> getDataModel ( static :: $ modulesManagerModelAlias ) ; } else { static :: $ _modmgr = new static ; } } return static :: $ _modmgr ; } | Get modules manager instance |
23,434 | public static function setAlreadyAddSubmodulesFor ( $ module , $ app = null ) { if ( empty ( $ app ) ) { $ app = Yii :: $ app ; } $ appKey = UniApplication :: appKey ( $ app ) ; if ( $ module instanceof YiiBaseModule ) { static :: $ _modulesWithInstalledSubmodules [ $ appKey ] [ $ module :: className ( ) ] = $ module -> uniqueId ; } } | Add new module to list modules with already installed submodules . |
23,435 | public static function modulesNamesList ( $ module = null , $ onlyActivated = true , $ forModmgr = false , $ onlyUniModule = false , $ onlyLoaded = false , $ indent = '. ' ) { $ list = [ ] ; if ( empty ( $ module ) ) { $ module = Yii :: $ app ; } $ modmgr = static :: instance ( ) ; if ( method_exists ( $ modmgr , 'registeredModuleName' ) ) { $ label = $ modmgr :: registeredModuleName ( $ module -> uniqueId ) ; } if ( empty ( $ label ) && $ module instanceof UniModule ) { $ label = $ module -> inform ( 'label' ) ; } if ( empty ( $ label ) ) { $ label = Yii :: t ( self :: $ tc , 'Module' ) . ' ' . $ module -> uniqueId ; } if ( $ module != Yii :: $ app ) { if ( ! $ onlyUniModule || $ module instanceof UniModule ) { $ prefix = str_repeat ( $ indent , count ( explode ( '/' , $ module -> uniqueId ) ) ) ; $ muid = $ module -> uniqueId ; if ( $ forModmgr ) { $ muid = $ modmgr :: tonumberModuleUniqueId ( $ muid ) ; } $ list [ $ muid ] = $ prefix . $ label ; } } $ staticSubmodules = $ module -> modules ; $ dynSubmodules = $ modmgr -> getSubmodules ( $ module , $ onlyActivated ) ; $ module -> modules = ArrayHelper :: merge ( $ dynSubmodules , $ staticSubmodules ) ; if ( empty ( $ module -> modules ) ) { return $ list ; } foreach ( $ module -> modules as $ childId => $ childModule ) { if ( ! $ onlyLoaded && is_array ( $ childModule ) ) { $ childModule = $ module -> getModule ( $ childId ) ; } if ( $ childModule instanceof YiiBaseModule ) { $ list += static :: modulesNamesList ( $ childModule , $ onlyActivated , $ forModmgr , $ onlyUniModule , $ onlyLoaded , $ indent ) ; } } return $ list ; } | Get modules list in format uniqueId = > label . Use for modules dropdown list . |
23,436 | public static function initSubmodules ( $ module ) { $ submodules = ArrayHelper :: merge ( $ module -> modules , static :: submodules ( $ module ) ) ; foreach ( $ submodules as $ submoduleId => $ submodule ) { if ( is_array ( $ submodule ) ) $ submodule = $ module -> getModule ( $ submoduleId ) ; if ( empty ( $ submodule ) ) continue ; static :: initSubmodules ( $ submodule ) ; } } | Recursively init all submodules of module . |
23,437 | public function modelAction ( ) { $ name = ucfirst ( Inflector :: camelize ( $ this -> getFirstParamOrAsk ( 'Enter model name' ) ) ) ; $ path = DC :: getEnvironment ( ) -> getUserClassesRoot ( ) . 'db/' ; $ mo = ModelOperator :: getInstance ( $ path ) ; if ( $ mo -> getModelStructure ( $ name ) ) { $ this -> warning ( 'model ' . $ name . ' is already exists' , '~ model exists, skipping:' ) ; return true ; } $ mo -> generateBasicStructure ( $ name ) ; $ mo -> saveModelStructure ( $ name ) ; $ this -> notify ( $ path . 'structure/' . $ name . '.yml' , '+ model created' ) ; } | Generates default database model structure |
23,438 | public function cvAction ( ) { $ params = array ( ) ; $ params [ 'name' ] = ucfirst ( $ this -> getFirstParamOrAsk ( 'Enter controller\'s name' ) ) ; $ params [ 'app' ] = ucfirst ( $ this -> ask ( 'App to generate controller' , 'Frontend' ) ) ; $ this -> createCV ( $ params ) ; } | Generates controller and view structure for it |
23,439 | public function appAction ( ) { $ name = ucfirst ( $ this -> getFirstParamOrAsk ( 'Enter application\'s name' ) ) ; ; FSService :: makeWritable ( DC :: getEnvironment ( ) -> getApplicationRoot ( ) . $ name ) ; $ this -> createCV ( array ( 'name' => 'Index' , 'app' => $ name , ) ) ; $ appPath = DC :: getEnvironment ( ) -> getApplicationRoot ( ) . $ name . '/' ; $ this -> safeCreateFromTemplate ( $ appPath . 'Views/_layout.slot' , '_view_layout' , array ( 'app' => $ name ) ) ; $ this -> safeCreateFromTemplate ( $ appPath . 'config.yml' , '_app_config' , array ( 'app' => $ name ) ) ; $ config = DC :: getProjectConfig ( ) ; if ( ! $ config -> has ( 'applications/' . strtolower ( $ name ) ) ) { $ config -> set ( 'applications/' . strtolower ( $ name ) , strtolower ( $ name ) ) ; $ this -> notify ( 'added information to project.yml' , '+ config' ) ; $ config -> save ( ) ; } } | Generates new application |
23,440 | public function fetchResults ( ) { if ( count ( $ this -> results ) == 0 ) { while ( $ result = $ this -> fetchResult ( ) ) { $ this -> results [ ] = $ result ; } } return $ this -> results ; } | Fetches all rows from current result set |
23,441 | public function fetchResult ( ) { if ( $ this -> checkValid ( ) ) { try { return $ this -> getAdapter ( ) -> fetchAssoc ( $ this -> resultSQL ) ; } catch ( Exception $ e ) { $ e -> log ( ) ; } } return false ; } | Fetches row from current result set |
23,442 | public static function linkify ( $ tweet , $ target = '_blank' ) { if ( $ target == null ) { $ target = '_blank' ; } $ tweet = preg_replace_callback ( "#(^|[\n ])@([a-z0-9_-]*)#is" , function ( $ matches ) use ( $ target ) { return sprintf ( '%s<a href="https://twitter.com/%s" target="%s" class="user"><span>@</span>%s</a>' , $ matches [ 1 ] , $ matches [ 2 ] , $ target , $ matches [ 2 ] ) ; } , $ tweet ) ; $ tweet = preg_replace_callback ( "#(^|[\n ])\#([a-z0-9_-]*)#is" , function ( $ matches ) use ( $ target ) { return sprintf ( '%s<a href="https://twitter.com/search?q=%%23%s" target="%s" class="hashtag"><span>#</span>%s</a>' , $ matches [ 1 ] , $ matches [ 2 ] , $ target , $ matches [ 2 ] ) ; } , $ tweet ) ; $ tweet = preg_replace_callback ( "#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#is" , function ( $ matches ) use ( $ target ) { return sprintf ( '%s<a href="%s" target="%s" class="link">%s</a>' , $ matches [ 1 ] , $ matches [ 2 ] , $ target , $ matches [ 2 ] ) ; } , $ tweet ) ; $ tweet = preg_replace_callback ( "#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#is" , function ( $ matches ) use ( $ target ) { return sprintf ( '%s<a href="http://%s" target="%s" class="link">%s</a>' , $ matches [ 1 ] , $ matches [ 2 ] , $ target , $ matches [ 2 ] ) ; } , $ tweet ) ; return $ tweet ; } | Linkifies all users hashtags and urls in a tweet . |
23,443 | protected function addFeed ( ) { if ( $ this -> params -> get ( 'show_feed_link' , 1 ) == 1 ) { $ link = '&format=feed&limitstart=' ; $ attribs = array ( 'type' => 'application/rss+xml' , 'title' => 'RSS 2.0' ) ; $ this -> document -> addHeadLink ( JRoute :: _ ( $ link . '&type=rss' ) , 'alternate' , 'rel' , $ attribs ) ; $ attribs = array ( 'type' => 'application/atom+xml' , 'title' => 'Atom 1.0' ) ; $ this -> document -> addHeadLink ( JRoute :: _ ( $ link . '&type=atom' ) , 'alternate' , 'rel' , $ attribs ) ; } } | Method to add an alternative feed link to a category layout . |
23,444 | static function fromDate ( $ date = false ) { $ format = count ( explode ( " " , $ date ) ) > 1 ? Settings \ DefaultDateSettings :: $ defaultDateTimeFromat : Settings \ DefaultDateSettings :: $ defaultDateFromat ; return ( $ date ) ? static :: createFromFormat ( $ format , $ date ) : new self ( ) ; } | Create an instance from a short date or short date time formatted string |
23,445 | static function formatTimestamp ( $ timestamp = 'now' , $ format = false ) { $ dateObj = static :: createFromTimestamp ( $ timestamp ) ; return $ dateObj -> format ( $ format ? : Settings \ DefaultDateSettings :: $ defaultDateTimeFromat ) ; } | Format a timestamp |
23,446 | static function mysqlToDateTime ( $ mysqlDate = false ) { return static :: createFromFormat ( static :: $ mysqlFormat , $ mysqlDate ) -> format ( Settings \ DefaultDateSettings :: $ defaultDateTimeFromat ) ; } | Converts a MySql formatted date to a default date time string |
23,447 | static function getDaysDiff ( $ startDate , $ endDate , Settings \ DateSettings $ settings = null ) { $ format = $ settings ? $ settings -> dateFromat : Settings \ DefaultDateSettings :: $ defaultDateFromat ; $ start = self :: createFromFormat ( $ format , $ startDate ) ; $ end = self :: createFromFormat ( $ format , $ endDate ) ; return $ start && $ end ? $ start -> diff ( $ end ) -> format ( '%r%d' ) : false ; } | Compare the difference in days between to dates . Dates are formatted as dateTime strings |
23,448 | static function createFromTimestamp ( $ timestamp , $ settings = null ) { $ settings = is_null ( $ settings ) ? new Settings \ DateSettings ( ) : $ settings ; $ dateObj = new Date ( 'now' , $ settings ) ; if ( is_long ( $ timestamp ) ) { $ dateObj = new Date ( '@' . $ timestamp ) ; } return $ dateObj ; } | Create an instance from a timestamp |
23,449 | static function isTimezoneInDST ( $ timeZone ) { $ tz = is_string ( $ timeZone ) ? new \ DateTimeZone ( $ timeZone ) : $ timeZone ; $ trans = $ tz -> getTransitions ( ) ; return ( ( count ( $ trans ) && $ trans [ count ( $ trans ) - 1 ] [ 'ts' ] > time ( ) ) ) ; } | Determin if a timezone is in daylight savings |
23,450 | static function daysOfTheWeek ( $ startFrom = 'Monday' , $ format = 'l' ) { $ result = [ ] ; $ start = new self ( $ startFrom ) ; $ interval = \ DateInterval :: createFromDateString ( '1 day' ) ; $ recurrences = 6 ; foreach ( new \ DatePeriod ( $ start , $ interval , $ recurrences ) as $ date ) { $ result [ ] = $ date -> format ( $ format ) ; } return $ result ; } | Returns and array of all the days in a week |
23,451 | static function monthsOfTheYear ( $ format = "F" ) { $ result = [ ] ; $ start = new self ( 'January this year' ) ; $ interval = new \ DateInterval ( 'P1M' ) ; $ recurrences = 11 ; foreach ( new \ DatePeriod ( $ start , $ interval , $ recurrences ) as $ date ) { $ result [ ] = $ date -> format ( $ format ) ; } return $ result ; } | Returns and array of all the months in a year |
23,452 | public function getName ( $ os = null ) { if ( $ os === null ) { if ( strstr ( strtoupper ( php_uname ( ) ) , "WIN" ) ) $ os = self :: OS_WINDOWS ; elseif ( strstr ( strtoupper ( php_uname ( ) ) , "MACOS" ) ) $ os = self :: OS_MAC ; else $ os = self :: OS_UNIX ; } $ host = $ this -> getHost ( ) ; $ filename = $ this -> getPath ( ) ; if ( $ filename { 0 } === '/' && $ os == self :: OS_WINDOWS ) { $ filename = substr ( $ filename , 1 ) ; } if ( $ os == self :: OS_WINDOWS ) { $ filename = str_replace ( '/' , '\\' , $ filename ) ; } if ( $ os == self :: OS_WINDOWS ) { if ( $ host && $ host !== 'localhost' ) return sprintf ( '\\\\%s\%s' , $ host , $ filename ) ; else return $ filename ; } else { return $ this -> buildStr ( ) ; } } | Get legacy file string name |
23,453 | public function getDirectory ( ) { $ dir = clone $ this ; $ dir -> path = str_replace ( DIRECTORY_SEPARATOR , '/' , dirname ( $ this -> path ) ) ; if ( ! $ dir -> path ) $ dir -> path = '/' ; return $ dir ; } | Get directory file uri |
23,454 | public function toString ( array $ types , array $ translations = array ( ) , array $ plugins = array ( ) ) { $ query = new Zend_Search_Lucene_Search_Query_Boolean ( ) ; foreach ( $ this -> _expressions as $ expr ) { if ( ( $ itemstr = $ expr -> toString ( $ types , $ translations , $ plugins ) ) !== '' ) { $ query -> addSubquery ( $ itemstr , self :: $ _operators [ $ this -> _operator ] ) ; } } return $ query ; } | Generates a Lucene object from the expression objects . |
23,455 | public function token ( ) { $ key = 'WeChatToken' . $ this -> get ( 'appid' ) ; if ( Factory :: cache ( ) -> has ( $ key ) ) { return Factory :: cache ( ) -> get ( $ key ) ; } $ args = $ this -> getToken ( ) -> json ( ) ; if ( ! is_array ( $ args ) ) { throw new Exception ( 'HTTP ERROR!' ) ; } if ( ! array_key_exists ( 'access_token' , $ args ) ) { throw new Exception ( isset ( $ args [ 'errmsg' ] ) ? $ args [ 'errmsg' ] : 'GET ACCESS TOKEN ERROR!' ) ; } Factory :: cache ( ) -> set ( $ key , $ args [ 'access_token' ] , $ args [ 'expires_in' ] ) ; return $ args [ 'access_token' ] ; } | GET ACCESS TOKEN AND SAVE CACHE |
23,456 | public function read ( $ splash , $ session , $ sessionId ) { $ database = $ this -> database ; $ statement = $ database -> where ( "session_agent" , $ database -> quote ( $ splash [ 'agent' ] ) ) -> where ( "session_ip" , $ database -> quote ( $ splash [ 'ip' ] ) ) -> where ( "session_host" , $ database -> quote ( $ splash [ 'domain' ] ) ) -> where ( "session_key" , $ database -> quote ( $ sessionId ) ) -> select ( "*" ) -> from ( $ session -> table ) -> prepare ( ) ; $ result = $ statement -> execute ( ) ; if ( ( int ) $ result -> rowCount ( ) < 1 ) { $ session -> destroy ( $ sessionId ) ; return false ; } $ object = $ result -> fetchObject ( ) ; return $ object ; } | Read the session from the database |
23,457 | public function update ( $ update , $ session , $ sessionId ) { $ database = $ this -> database ; if ( isset ( $ update [ "session_registry" ] ) ) { $ update [ "session_registry" ] = $ database -> quote ( $ update [ "session_registry" ] ) ; } $ database -> update ( $ session -> table , $ update , array ( "session_key" => $ database -> quote ( $ sessionId ) ) ) ; return true ; } | Updates session data in the database ; |
23,458 | public function delete ( $ where , $ session ) { $ database = $ this -> database ; if ( isset ( $ where [ "session_key" ] ) ) { $ where [ "session_key" ] = $ database -> quote ( $ where [ "session_key" ] ) ; } $ database -> delete ( $ session -> table , $ where ) ; return true ; } | Deletes session data from the database |
23,459 | public function write ( $ userdata , $ splash , $ session , $ sessionId , $ expiry ) { $ database = $ this -> database ; $ database -> insert ( $ session -> table , array ( "session_key" => $ database -> quote ( $ sessionId ) , "session_ip" => $ database -> quote ( $ splash [ 'ip' ] ) , "session_host" => $ database -> quote ( $ splash [ 'domain' ] ) , "session_agent" => $ database -> quote ( $ splash [ 'agent' ] ) , "session_token" => $ database -> quote ( $ splash [ 'token' ] ) , "session_expires" => $ expiry , "session_lastactive" => time ( ) , "session_registry" => $ database -> quote ( $ userdata ) ) ) ; } | Writes session data to the database store |
23,460 | private function parseRequestUri ( ) : void { $ requestUri = $ this -> baseClass -> getRequestUri ( ) ; $ path = \ explode ( '/' , $ requestUri ) ; $ pathCnt = \ count ( $ path ) ; if ( $ pathCnt > 0 ) { $ file = \ array_pop ( $ path ) ; $ path = \ sprintf ( '%%DOCUMENT_ROOT%%%s%s' , \ implode ( DIRECTORY_SEPARATOR , $ path ) , DIRECTORY_SEPARATOR ) ; $ path = $ this -> baseClass -> parsePath ( $ path ) ; $ file = \ explode ( '.' , $ file ) ; $ ext = '' ; if ( \ count ( $ file ) > 1 ) { $ ext = \ array_pop ( $ file ) ; } $ file = \ explode ( '__' , \ implode ( '.' , $ file ) ) ; $ resizeParams = [ ] ; if ( \ count ( $ file ) > 1 ) { $ resizeParams = $ this -> parseResizeParams ( \ explode ( '_' , $ file [ 1 ] ) ) ; } $ file = $ file [ 0 ] ; $ this -> uriParams [ 'path' ] = $ path ; $ this -> uriParams [ 'file' ] = $ file ; $ this -> uriParams [ 'extension' ] = $ ext ; $ this -> uriParams [ 'resize-params' ] = $ resizeParams ; } } | Parses request uri |
23,461 | private function parseResizeParams ( array $ params = [ ] ) : array { $ resizeParams = [ ] ; foreach ( $ params as $ param ) { \ preg_match ( '/^(' . \ implode ( '|' , $ this -> allowedResizeParams ) . ')([0-9]+)$/' , $ param , $ matches ) ; if ( isset ( $ matches [ 1 ] ) && isset ( $ matches [ 2 ] ) ) { $ resizeParams [ $ matches [ 1 ] ] = ( int ) $ matches [ 2 ] ; if ( $ matches [ 1 ] == 'gs' ) { $ resizeParams [ $ matches [ 1 ] ] = ( ( int ) $ matches [ 2 ] === 1 ) ; } } } return $ resizeParams ; } | Parses resize params |
23,462 | private function getResizeParamsString ( ) : string { $ ret = '' ; foreach ( $ this -> uriParams [ 'resize-params' ] as $ param => $ value ) { $ ret .= \ sprintf ( '_%s%s' , $ param , $ value ) ; } return $ ret !== '' ? \ sprintf ( '_%s' , $ ret ) : '' ; } | Returns resize params string |
23,463 | private function sendCachingHeaders ( string $ imagePath = '' ) : void { $ ifModifiedSince = '' ; if ( isset ( $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ) { $ ifModifiedSince = \ preg_replace ( '/;.*$/' , '' , $ _SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] ) ; } $ mdate = \ gmdate ( 'D, d M Y H:i:s' , \ filemtime ( $ imagePath ) ) . ' GMT' ; if ( $ ifModifiedSince == $ mdate ) { \ header ( $ this -> serverProtocol . ' 304 Not Modified' , true , 304 ) ; die ( ) ; } \ header ( $ this -> serverProtocol . ' 200 OK' , true , 200 ) ; \ header ( 'Last-Modified: ' . $ mdate ) ; $ maxAge = $ this -> baseClass -> Image -> Server -> cacheTime ; $ maxAgeHeader = 'Cache-Control: no-transform,public,max-age=' . $ maxAge ; if ( $ maxAge == 0 ) { $ maxAgeHeader = 'Cache-Control: max-age=0, no-cache, no-store' ; } \ header ( $ maxAgeHeader ) ; \ header ( 'Expires: ' . \ gmdate ( 'D, d M Y H:i:s' , \ time ( ) + $ maxAge ) . ' GMT' ) ; } | Sends caching headers |
23,464 | private function outputImage ( string $ imagePath = '' ) : void { $ fPointer = \ fopen ( $ imagePath , 'rb' ) ; $ this -> sendCachingHeaders ( $ imagePath ) ; \ header ( 'Content-Type: ' . $ this -> getImageContentType ( ) ) ; \ header ( 'Content-Length: ' . \ filesize ( $ imagePath ) ) ; \ fpassthru ( $ fPointer ) ; \ fclose ( $ fPointer ) ; die ( ) ; } | Reads image from disk and outputs it |
23,465 | private function serveImage ( ) : void { if ( empty ( $ this -> uriParams ) ) { \ header ( $ this -> serverProtocol . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } $ requestFilePath = \ sprintf ( '%s%s%s.%s' , $ this -> uriParams [ 'path' ] , $ this -> uriParams [ 'file' ] , $ this -> getResizeParamsString ( ) , $ this -> uriParams [ 'extension' ] ) ; $ originalFilePath = \ sprintf ( '%s%s.%s' , $ this -> uriParams [ 'path' ] , $ this -> uriParams [ 'file' ] , $ this -> uriParams [ 'extension' ] ) ; if ( File :: exists ( $ requestFilePath ) ) { $ this -> outputImage ( $ requestFilePath ) ; } if ( File :: exists ( $ originalFilePath ) ) { if ( $ this -> baseClass -> Image -> Server -> checkRefererBeforeResize === true ) { if ( ! \ preg_match ( '|^' . $ this -> baseClass -> getServerName ( ) . '|i' , $ this -> baseClass -> getReferer ( ) ) ) { \ header ( $ this -> serverProtocol . ' 403 Forbidden' , true , 403 ) ; die ( ) ; } } $ options = $ this -> uriParams [ 'resize-params' ] ; $ options [ 'quality' ] = $ this -> baseClass -> Image -> Resizer -> defaultQuality ; try { Resizer :: resize ( $ originalFilePath , $ requestFilePath , $ options ) ; } catch ( \ Exception $ e ) { \ header ( $ this -> serverProtocol . ' 500 Internal Server Error' , true , 500 ) ; die ( ) ; } $ this -> outputImage ( $ requestFilePath ) ; } \ header ( $ this -> serverProtocol . ' 404 Not Found' , true , 404 ) ; die ( ) ; } | Serves image . If no REQUEST_URI found sends 500 Internal Server Error header . If no image is found sends 404 Not found header . If image needs resizing or grayscale converting - it applies transformations and returns it otherwise returns original one . |
23,466 | protected function runNextJobForDaemon ( $ connectionName , $ queue , $ delay , $ sleep , $ maxTries ) { try { $ this -> pop ( $ connectionName , $ queue , $ delay , $ sleep , $ maxTries ) ; } catch ( Exception $ e ) { if ( $ this -> exceptions ) $ this -> exceptions -> report ( $ e ) ; } } | Run the next job for the daemon worker . |
23,467 | public static function media ( $ path , $ size ) { global $ _wp_additional_image_sizes ; $ image_size = $ _wp_additional_image_sizes [ $ size ] ; $ pathinfo = pathinfo ( $ path ) ; $ fname = $ pathinfo [ 'basename' ] ; $ fext = $ pathinfo [ 'extension' ] ; $ dir = $ pathinfo [ 'dirname' ] ; $ fdir = realpath ( str_replace ( '//' , '/' , ABSPATH . $ dir ) ) . '/' ; $ fname_prefix = preg_replace ( '/(?:-\d+x\d+)?\.' . $ fext . '$/i' , '' , $ fname ) ; $ out_fname = sprintf ( '%s-%sx%s.%s' , $ fname_prefix , $ image_size [ 'width' ] , $ image_size [ 'height' ] , $ fext ) ; $ fpath = $ fdir . $ out_fname ; if ( file_exists ( $ fpath ) ) { return sprintf ( '%s/%s' , $ pathinfo [ 'dirname' ] , $ out_fname ) ; } global $ wpdb ; $ guid = site_url ( ) . $ dir . '/' . $ fname_prefix . '.' . $ fext ; $ prepared = $ wpdb -> prepare ( "SELECT pm.meta_value FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE p.guid = %s AND pm.meta_key = '_wp_attachment_metadata' LIMIT 1" , $ guid ) ; $ row = $ wpdb -> get_row ( $ prepared ) ; if ( is_object ( $ row ) ) { $ meta = unserialize ( $ row -> meta_value ) ; if ( isset ( $ meta [ 'sizes' ] [ $ size ] [ 'file' ] ) ) { $ meta_fname = $ meta [ 'sizes' ] [ $ size ] [ 'file' ] ; return sprintf ( '%s/%s' , $ pathinfo [ 'dirname' ] , $ meta_fname ) ; } } return $ path ; } | Get URL for an image in the media library |
23,468 | public static function asset ( $ relative_path , $ include_version = true ) { $ clean_relative_path = preg_replace ( '/^[\/_]+/' , '' , $ relative_path ) ; return sprintf ( '%s/_/%s%s' , THEME_URL , $ clean_relative_path , ( $ include_version ) ? THEME_SUFFIX : null ) ; } | Get the asset path |
23,469 | public static function optionsLink ( $ description = null , $ display_inline = false ) { if ( ! ( is_user_logged_in ( ) && current_user_can ( 'manage_options' ) ) ) return null ; if ( is_null ( $ description ) ) { $ description = 'this' ; } $ options = AppOption :: getInstance ( ) ; return self :: editLink ( $ options -> ID , 'app-option' , $ description . ' in options' , $ display_inline ) ; } | Get App Options link when admin is logged in |
23,470 | public static function pageTitle ( ) { $ short_site_name = Config :: get ( ) -> site_name ; $ separator = self :: pageTitleSeparator ( ) ; $ title = wp_title ( null , false ) ; $ title_has_site_name = ( strpos ( $ title , $ short_site_name ) !== false ) ; if ( ! empty ( $ title ) && $ title_has_site_name ) { return $ title ; } $ site_name = get_bloginfo ( 'name' ) ; if ( ! empty ( $ title ) ) { return $ title . $ separator . $ site_name ; } global $ post ; $ this_post = $ post ; if ( ! is_subclass_of ( $ post , 'Taco\Base' ) ) { $ this_post = \ Taco \ Post \ Factory :: create ( $ post ) ; } $ page_title_taxonomy = $ this_post -> pageTitleTaxonomy ( ) ; if ( Config :: get ( ) -> use_yoast ) { $ yoast_title = $ this_post -> getSafe ( '_yoast_wpseo_title' ) ; $ yoast_title_has_site_name = preg_match ( '/' . $ site_name . '$/' , $ yoast_title ) ; if ( ! empty ( $ yoast_title ) && $ yoast_title_has_site_name ) { return $ yoast_title ; } if ( ! empty ( $ yoast_title ) ) { return $ yoast_title . $ separator . $ site_name ; } } if ( empty ( $ page_title_taxonomy ) ) { return $ this_post -> getTheTitle ( ) . $ separator . $ site_name ; } $ term_name = null ; $ terms = $ this_post -> getTerms ( $ page_title_taxonomy ) ; if ( ! empty ( $ terms ) ) { $ primary_term_id = $ this_post -> { '_yoast_wpseo_primary_' . $ page_title_taxonomy } ; $ term = ( ! empty ( $ primary_term_id ) ) ? $ terms [ $ primary_term_id ] : reset ( $ terms ) ; $ term_name = $ separator . $ term -> name ; } return $ this_post -> getTheTitle ( ) . $ term_name . $ separator . $ site_name ; } | Get the page title |
23,471 | public static function pageMeta ( ) { $ title = wp_title ( null , false ) ; if ( ! empty ( $ title ) ) return null ; global $ post ; $ this_post = $ post ; if ( ! is_subclass_of ( $ post , 'Taco\Base' ) ) { $ this_post = \ Taco \ Post \ Factory :: create ( $ post , false ) ; } if ( ! Obj :: iterable ( $ this_post ) ) return null ; $ description = null ; if ( Config :: get ( ) -> use_yoast ) { $ description = $ this_post -> getSafe ( '_yoast_wpseo_metadesc' ) ; } if ( empty ( $ description ) ) { $ description = strip_tags ( $ this_post -> getTheExcerpt ( ) ) ; } $ image = ( Config :: get ( ) -> use_yoast ) ? $ this_post -> { '_yoast_wpseo_opengraph-image' } : null ; return View :: make ( 'meta-tags' , [ 'title' => self :: pageTitle ( ) , 'description' => trim ( $ description ) , 'image' => $ image , 'full_url' => URL_REQUEST , 'site_name' => get_bloginfo ( 'name' ) , 'separator' => self :: pageTitleSeparator ( ) , ] ) ; } | Get the page meta tags |
23,472 | public static function appIcons ( ) { $ config = Config :: instance ( ) ; $ icons_directory = THEME_DIRECTORY . '/' . $ config -> app_icons_directory ; $ icons_url = THEME_URL . '/' . $ config -> app_icons_directory ; if ( ! file_exists ( $ icons_directory ) ) return null ; $ files = scandir ( $ icons_directory ) ; if ( ! Arr :: iterable ( $ files ) ) return null ; $ icon_types = [ 'apple' , 'android' , 'favicon' ] ; $ paths = [ ] ; foreach ( $ files as $ file ) { if ( ! preg_match ( '/\.png$/' , $ file ) ) continue ; preg_match ( '/(\d+x\d+)/' , $ file , $ sizes ) ; if ( ! Arr :: iterable ( $ sizes ) ) continue ; $ size = reset ( $ sizes ) ; $ icon_type = reset ( explode ( '-' , $ file ) ) ; if ( ! in_array ( $ icon_type , $ icon_types ) ) continue ; $ file_path = $ icons_url . '/' . $ file ; $ paths [ ] = View :: make ( 'meta/icon-' . $ icon_type , [ 'file' => $ file_path , 'size' => $ size , ] ) ; } $ paths [ ] = View :: make ( 'meta/icon-favicon-ico' , [ 'file' => $ icons_url . '/favicon.ico' , ] ) ; return join ( '' , $ paths ) ; } | Get HTML for all icons |
23,473 | public function create ( $ interface ) { if ( ! Util :: existsDirWritable ( $ this -> config -> getProxyRootDir ( ) ) ) { throw new InitiallyRpcException ( "Proxy builder error: proxy class root dir not to be write" ) ; } $ this -> interface = $ interface ; $ this -> reflectionInterfaceAndCheck ( ) ; $ this -> service = $ this -> config -> getServiceByKey ( $ this -> interface ) ; $ info = $ this -> parseProxyClassInfo ( ) ; $ dir = $ this -> getProxyClassDirAndCreate ( $ info -> getNamespace ( ) ) ; $ file = sprintf ( "%s/%s.php" , $ dir , $ info -> getClassName ( ) ) ; $ methodString = "" ; foreach ( $ this -> refectionClass -> getMethods ( ReflectionMethod :: IS_PUBLIC ) as $ method ) { $ methodString .= $ this -> buildMethod ( $ method ) ; } $ useString = "" ; $ this -> useList = array_unique ( $ this -> useList ) ; foreach ( $ this -> useList as $ value ) { $ useString .= "use {$value};" . PHP_EOL ; } $ replaces = array ( $ info -> getNamespace ( ) , $ useString , $ this -> refectionClass -> getDocComment ( ) , $ info -> getClassName ( ) , sprintf ( "\\%s" , $ this -> refectionClass -> getName ( ) ) , str_replace ( "\\" , "\\\\" , $ this -> refectionClass -> getName ( ) ) , $ methodString ) ; $ content = str_replace ( self :: CLASS_TPL_SEARCHES , $ replaces , $ this -> template -> getClassTemplate ( ) ) ; if ( ! @ file_put_contents ( $ file , $ content ) ) { throw new InitiallyRpcException ( "Proxy builder error: proxy class code write failed" ) ; } $ this -> clear ( ) ; } | Create proxy class |
23,474 | protected function parseProxyClassInfo ( ) { $ arr = explode ( "\\" , $ this -> interface ) ; $ name = array_pop ( $ arr ) ; $ matches = array ( ) ; if ( ! preg_match ( $ this -> getClassNameRule ( ) , $ name , $ matches ) ) { throw new InitiallyRpcException ( "Proxy builder error: interface name must ending of '{$this->interfaceEndOf}' like 'DemoService{$this->interfaceEndOf}'" ) ; } $ replace = $ this -> config -> getReplace ( ) ; $ replaceKey = $ this -> service -> getReplaceKey ( ) ; if ( ! empty ( $ arr ) && ! empty ( $ replace ) && isset ( $ replace [ $ replaceKey ] ) ) { foreach ( $ arr as $ key => $ value ) { if ( isset ( $ replace [ $ replaceKey ] [ $ value ] ) ) { $ arr [ $ key ] = $ replace [ $ replaceKey ] [ $ value ] ; } } } $ namespace = implode ( "\\" , $ arr ) ; $ info = new ProxyClassInfo ( ) ; $ info -> setNamespace ( $ namespace ) ; $ info -> setClassName ( $ matches [ 1 ] ) ; return $ info ; } | Parse interface info |
23,475 | protected function getProxyClassDirAndCreate ( $ namespace ) { $ path = str_replace ( "\\" , DIRECTORY_SEPARATOR , $ namespace ) ; $ dir = $ this -> config -> getProxyRootDir ( ) . DIRECTORY_SEPARATOR . $ path ; if ( ! Util :: createDirIfNotExists ( $ dir ) ) { throw new InitiallyRpcException ( "Proxy builder error: get proxy class dir and create it" ) ; } return $ dir ; } | Get proxy class dir and create it |
23,476 | public function getResult ( ) { $ arrayData = $ this -> decode ( $ this -> getResponse ( ) -> getBody ( ) -> getContents ( ) ) ; if ( is_array ( $ arrayData ) && count ( $ arrayData ) ) { $ singleItem = reset ( $ arrayData ) ; } else { throw new ResponseDecodeException ( 'Response has bad format.' ) ; } return new Contact ( $ singleItem ) ; } | Returns useful result of operation . |
23,477 | private function decode ( $ json ) { $ decodedResult = json_decode ( $ json , true ) ; if ( JSON_ERROR_NONE != json_last_error ( ) ) { throw new ResponseDecodeException ( 'JSON error: ' . json_last_error_msg ( ) ) ; } return $ decodedResult ; } | Parses and validates request parameters . |
23,478 | protected function flushIfNeeded ( ) { if ( ! $ this -> _enabled ) { return ; } $ now = $ this -> _util -> nowMicros ( ) ; $ delta = $ now - $ this -> _lastFlushMicros ; if ( $ delta < $ this -> _minFlushPeriodMicros ) { return ; } if ( $ delta > $ this -> _maxFlushPeriodMicros ) { $ this -> flush ( ) ; return ; } if ( count ( $ this -> _logRecords ) >= $ this -> _options [ "max_log_records" ] ) { $ this -> flush ( ) ; return ; } if ( count ( $ this -> _spanRecords ) >= $ this -> _options [ "max_span_records" ] ) { $ this -> flush ( ) ; return ; } } | new data comes in by calling this method . |
23,479 | public function _log ( $ level , $ fmt , $ allArgs ) { array_shift ( $ allArgs ) ; $ text = vsprintf ( $ fmt , $ allArgs ) ; $ this -> _rawLogRecord ( array ( 'level' => $ level , 'message' => $ text , ) , $ allArgs ) ; $ this -> flushIfNeeded ( ) ; return $ text ; } | For internal use only . |
23,480 | protected function setFilename ( $ filename ) { $ parts = explode ( '.' , $ filename ) ; $ extension = array_pop ( $ parts ) ; $ name = time ( ) . '-' . str_slug ( str_random ( 35 ) ) ; return "{$name}.{$extension}" ; } | Change filename . |
23,481 | public function getPopup ( CustomerMigrateEvent $ event ) { $ route = $ this -> routeProvider -> customer_migrate_popup ; $ route -> setParameters ( array ( 'uuid' => $ event -> getUuid ( ) ) ) ; $ response = $ route -> process ( function ( $ request ) use ( $ event ) { $ request -> addHeader ( $ event -> getBasicHeader ( ) ) ; } ) ; $ event -> setResponse ( $ response ) ; } | Initial request of migrate customer request flow Response filled with HTML to display to the user ; requires user action to continue |
23,482 | public function onSuccess ( CustomerMigrateEvent $ event ) { $ route = $ this -> routeProvider -> customer_migrate_success ; $ route -> setParameters ( array ( 'uuid' => $ event -> getUuid ( ) ) ) ; $ response = $ route -> process ( function ( $ request ) use ( $ event ) { $ request -> addHeader ( $ event -> getBasicHeader ( ) ) ; $ request -> setContent ( array ( 'status' => $ event -> getStatus ( ) ) ) ; } ) ; $ event -> setResponse ( $ response ) ; } | Additional third request to notify the application that we ve added the user successfully |
23,483 | private function getFormattedValue ( ) : string { return ( string ) is_numeric ( $ this -> value ) ? $ this -> value : sprintf ( '"%s"' , $ this -> value ) ; } | Devuelve el atributo value con formato |
23,484 | public function loadActions ( ) { $ actions = new ActionCollection ( ) ; foreach ( $ this -> loaders as $ loader ) { $ childActions = $ loader -> loadActions ( ) ; $ actions -> addActions ( $ childActions ) ; } return $ actions ; } | Get all actions |
23,485 | public function map ( $ methods , $ match , $ callback ) { return $ this -> routeService -> attach ( $ methods , $ match , $ callback ) ; } | Regist a HEAD http route . |
23,486 | public function group ( $ match , $ callback ) { $ group = new RouteGroup ( $ this -> container , $ match ) ; $ callback ( $ group ) ; return $ group ; } | Route group . |
23,487 | public function start ( ) { $ routeMethodSep = '>' ; $ storage = $ this -> routeService -> getStorage ( ) ; foreach ( $ storage as $ match => $ route ) { if ( ( $ matched = $ this -> matchHttpRequest ( $ match ) ) !== false ) { if ( ! in_array ( $ this -> request -> getMethod ( ) , $ route -> methods ) ) { throw new MethodNotAllowedException ( ) ; } $ this -> request -> withAttributes ( $ matched ) ; $ middleWares = new MiddleWares ( $ this -> getMiddleWareFromRoute ( $ route ) ) ; $ decorators = $ route -> decorators ; if ( \ is_string ( $ route -> callback ) ) { if ( strpos ( $ route -> callback , $ routeMethodSep ) !== false ) { list ( $ controller , $ method ) = explode ( $ routeMethodSep , $ route -> callback ) ; return $ this -> connectMiddlewares ( $ controller , $ method , $ middleWares , $ decorators ) ; } } return $ this -> connectMiddlewares ( $ route -> callback , '__invoke' , $ middleWares , $ decorators ) ; } } throw new NotFoundException ( ) ; } | Match routers and call the callback . |
23,488 | public function connectMiddlewares ( $ controller , $ method , MiddleWares $ middleWares , $ decorators = [ ] ) { $ isClosure = is_callable ( $ controller ) ; if ( $ middleWares -> valid ( ) ) { if ( $ isClosure ) { $ next = $ this -> getInvokeMiddlewareNext ( $ controller , $ middleWares , $ decorators ) ; } else { $ next = $ this -> getControllerMiddlewareNext ( $ controller , $ method , $ middleWares , $ decorators ) ; } $ middleWares -> withNextArgs ( $ next ) ; $ response = $ this -> injectionClass ( $ middleWares -> current ( ) , 'handle' , $ middleWares -> getNextArgs ( ) ) ; } else { if ( $ isClosure ) { $ controller = $ this -> closureBinder ( $ controller ) ; $ response = $ this -> injectionClosure ( $ controller , $ decorators ) ; } else { $ response = $ this -> injectionClass ( $ controller , $ method , [ ] , $ decorators ) ; } } if ( $ response instanceof Response ) { $ this -> sendByResponse ( $ response ) ; } } | Call middlewares and controller . |
23,489 | public function injectionClosure ( $ controller , $ decorators , $ args = [ ] ) { foreach ( $ decorators as $ decorator ) { $ controller = $ decorator ( $ this -> closureWrapper ( $ controller ) ) ; } return $ this -> container -> dependentService -> call ( $ controller , $ args ) ; } | Injection Types for Closure . |
23,490 | private function getMiddleWareFromRoute ( Route $ route ) { if ( ! $ route -> group ) { return $ route -> middleWare ; } $ groupMiddleWare = $ this -> getMiddleWareFromGroup ( $ route -> group ) ; return \ array_merge ( $ groupMiddleWare , $ route -> middleWare ) ; } | Get middle ware from Route |
23,491 | private function getMiddleWareFromGroup ( RouteGroup $ group , array $ middleWareList = [ ] ) { if ( $ group -> middleWare ) { $ middleWareList = \ array_merge ( $ group -> middleWare , $ middleWareList ) ; } if ( \ is_null ( $ group -> parentGroup ) ) { return $ middleWareList ; } return $ this -> getMiddleWareFromGroup ( $ group -> parentGroup , $ middleWareList ) ; } | Merge all middlewares from group and parent - group . |
23,492 | private function matchHttpRequest ( $ pattern ) { $ pattern = $ this -> replaceKeyWorlds ( $ pattern ) ; \ preg_match_all ( '/\<(.*?)\>/iu' , $ pattern , $ attrKeys ) ; \ array_shift ( $ attrKeys ) ; $ attrKeys = $ attrKeys [ 0 ] ; $ pathInfo = $ this -> request -> server -> get ( 'path-info' , '/' ) ; $ pattern = $ this -> replacePatternKeyword ( $ pattern ) ; $ regexp = '/^' . $ pattern . '\/?$/' ; if ( \ preg_match ( $ regexp , $ pathInfo , $ matched ) ) { \ array_shift ( $ matched ) ; $ result = [ ] ; foreach ( $ attrKeys as $ num => $ key ) { $ result [ $ key ] = $ matched [ $ num ] ; } return $ result ; } return false ; } | Match route storage by request url and return params . |
23,493 | public function sendBody ( Response $ response ) { $ body = $ response -> getBody ( ) ; $ body -> rewind ( ) ; echo $ body -> getContents ( ) ; return $ response ; } | Sends body for the current web response . |
23,494 | public function strpos ( $ needle , $ offset = 0 ) { $ function = static :: $ functions [ ( int ) static :: $ useMbstring ] [ 'strpos' ] ; return $ function ( $ this -> string , $ needle , $ offset ) ; } | Strpos function . Use mbstring extension if loaded . |
23,495 | public function substr ( $ start = 0 , $ length = null ) { $ function = static :: $ functions [ ( int ) static :: $ useMbstring ] [ 'substr' ] ; return new self ( $ function ( $ this -> string , $ start , $ length ) ) ; } | Substring function . Use mbstring extension if loaded . |
23,496 | public function strip ( ) { $ this -> noAccent ( ) -> trim ( ) -> toLower ( ) -> replace ( array_keys ( static :: $ charStrip ) , array_values ( static :: $ charStrip ) ) -> pregReplace ( array ( '#[^a-z0-9-]#S' , '#-+#S' ) , array ( '' , '-' ) ) ; return $ this ; } | Strip string and remove accent and non basic characters . |
23,497 | public function concat ( $ string , $ prepend = false ) { $ this -> string = $ prepend ? ( string ) $ string . $ this -> string : $ this -> string . ( string ) $ string ; return $ this ; } | Concat string with current string . |
23,498 | public function pregReplace ( $ pattern , $ replace , $ limit = - 1 , & $ count = null ) { $ this -> string = preg_replace ( $ pattern , $ replace , $ this -> string , $ limit , $ count ) ; return $ this ; } | Preg replace text in string . |
23,499 | public function replace ( $ search , $ replace , & $ count = null ) { $ this -> string = str_replace ( $ search , $ replace , $ this -> string , $ count ) ; return $ this ; } | Replace text in string . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.