idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
1,700 | public function showPage ( Request $ request , $ path = '' ) { $ uri = $ request -> getRequestUri ( ) ; if ( strlen ( $ uri ) > 1 && substr ( $ uri , - 1 ) === '/' ) { return redirect ( rtrim ( $ request -> path ( ) , '/' ) , 301 ) ; } $ pathInfo = LocaleService :: parsePath ( $ path ) ; $ pagePath = $ pathInfo -> pagePath ; LocaleService :: setLang ( $ pathInfo -> lang ) ; if ( $ pagePath === '/index' ) { error_log ( "index is a reserved name." ) ; abort ( 404 ) ; } $ viewsPath = base_path ( ) . '/resources/views/' ; if ( ! is_dir ( $ viewsPath ) ) { error_log ( "The directory /resources/views/ doesn't exists." ) ; throw new PathNotFoundException ( ) ; } $ showView = '' ; if ( $ pagePath === '/' ) { $ showView = 'index' ; } else { $ showView = ltrim ( str_replace ( '/' , '.' , $ pagePath ) , '.' ) ; } if ( ! view ( ) -> exists ( $ showView ) ) { abort ( 404 , "View not found: $showView" ) ; } LocaleLinkService :: setLang ( $ pathInfo -> lang ) ; LocaleLinkService :: setLangDir ( $ pathInfo -> langDir ) ; LocaleLinkService :: setPagePath ( $ pathInfo -> pagePath ) ; return view ( $ showView , [ 'benjamin' => 'benjamin::html' , 'activeLang' => LocaleService :: getActiveLang ( ) , ] ) ; } | Show the selected page |
1,701 | public static function setDefaultSeparator ( $ cSeparator , $ bMerge = true ) { self :: $ cDefaultSeparator = $ cSeparator ; self :: setSeparator ( $ cSeparator , $ bMerge ) ; } | Set default separator |
1,702 | public function addRoute ( array $ verbs , $ pattern , $ action , $ name = null ) { $ pattern = $ this -> resolvePatternValue ( $ pattern ) ; $ action = $ this -> resolveActionValue ( $ action ) ; $ name = $ this -> resolveNameValue ( $ name ) ; $ route = new Route ( $ pattern , $ action , $ verbs , $ name ) ; if ( $ filters = $ this -> getDefaultFilters ( ) ) { $ route -> setFilters ( $ filters ) ; } $ this -> routes -> add ( $ route ) ; return $ route ; } | Create a new route instance and attach to Collection |
1,703 | private function prepareCondition ( $ q ) { $ condition = [ ] ; foreach ( $ this -> searchFields as $ field ) { $ condition [ ] = [ 'like' , $ field , $ q ] ; } if ( count ( $ this -> searchFields ) > 1 ) { array_unshift ( $ condition , 'or' ) ; } return $ condition ; } | Prepares query condition |
1,704 | public function push ( $ value ) : StackInterface { $ this -> resolver -> value ( function ( $ value ) : void { $ this -> items -> push ( $ value ) ; } , $ value ) ; return $ this ; } | Pushes one value onto the top of the stack . |
1,705 | public function pushAll ( iterable $ input ) : StackInterface { foreach ( $ input as $ value ) { $ this -> push ( $ value ) ; } return $ this ; } | Pushes zero or more values onto the top of the stack . |
1,706 | function checkPhpVersion ( int $ pMajor , int $ pMinor = NULL , int $ pRelease = NULL ) { $ requirementsMet = TRUE ; $ phpVersion = \ phpversion ( ) ; $ version = \ explode ( '.' , \ phpversion ( ) ) ; $ version [ 2 ] = \ str_replace ( '-dev' , '' , $ version [ 2 ] ) ; if ( $ version [ 0 ] < $ pMajor ) { $ requirementsMet = FALSE ; } else if ( $ version [ 0 ] == $ pMajor ) { if ( \ is_int ( $ pMinor ) && $ version [ 1 ] < $ pMinor ) { $ requirementsMet = FALSE ; } else if ( $ requirementsMet && \ is_int ( $ pMinor ) && $ version [ 1 ] == $ pMinor ) { if ( \ is_int ( $ pRelease ) && $ version [ 2 ] < $ pRelease ) { $ requirementsMet = FALSE ; } } } if ( ! $ requirementsMet ) { $ versionString = "{$pMajor}.{$pMinor}.{$pRelease}" ; $ msg = "Your PHP version is '{$phpVersion}'. The minimum required" . "PHP version is '{$versionString}'. You'll need to upgrade in " . "order to use this application." ; throw new \ Exception ( $ msg ) ; } return $ requirementsMet ; } | Check the PHP version and throws an error if it does not meet the minimum version . |
1,707 | function convertToClassName ( $ pString ) { $ className = \ basename ( $ pString , '.php' ) ; $ className = $ this -> camelCase ( $ className , TRUE ) ; return $ className ; } | Turn a string into camel - cased word . |
1,708 | public function getAuthorReviews ( $ author , $ size = SPIGET4PHP_DEFAULT , $ page = SPIGET4PHP_DEFAULT , $ sort = SPIGET4PHP_DEFAULT , $ fields = SPIGET4PHP_DEFAULT ) { $ function = 'authors/' . $ author . '/reviews' ; $ args = [ ] ; if ( ! is_null ( $ size ) ) $ args [ 'size' ] = $ size ; if ( ! is_null ( $ page ) ) $ args [ 'page' ] = $ page ; if ( ! is_null ( $ sort ) ) $ args [ 'sort' ] = $ sort ; if ( ! is_null ( $ fields ) ) $ args [ 'fields' ] = implode ( ',' , $ fields ) ; return $ this -> getResult ( $ function , $ args ) ; } | Get the reviews of an specific author . |
1,709 | public function getCategoryList ( $ size = SPIGET4PHP_DEFAULT , $ page = SPIGET4PHP_DEFAULT , $ sort = SPIGET4PHP_DEFAULT , $ fields = SPIGET4PHP_DEFAULT ) { $ function = 'categories' ; $ args = [ ] ; if ( ! is_null ( $ size ) ) $ args [ 'size' ] = $ size ; if ( ! is_null ( $ page ) ) $ args [ 'page' ] = $ page ; if ( ! is_null ( $ sort ) ) $ args [ 'sort' ] = $ sort ; if ( ! is_null ( $ fields ) ) $ args [ 'fields' ] = implode ( ',' , $ fields ) ; return $ this -> getResult ( $ function , $ args ) ; } | Get a list of categories . |
1,710 | public function getCategoryResources ( $ category , $ size = SPIGET4PHP_DEFAULT , $ page = SPIGET4PHP_DEFAULT , $ sort = SPIGET4PHP_DEFAULT , $ fields = SPIGET4PHP_DEFAULT ) { $ function = 'categories/' . $ category . '/resources' ; $ args = [ ] ; if ( ! is_null ( $ size ) ) $ args [ 'size' ] = $ size ; if ( ! is_null ( $ page ) ) $ args [ 'page' ] = $ page ; if ( ! is_null ( $ sort ) ) $ args [ 'sort' ] = $ sort ; if ( ! is_null ( $ fields ) ) $ args [ 'fields' ] = implode ( ',' , $ fields ) ; return $ this -> getResult ( $ function , $ args ) ; } | Get a list of resources of an specific category . |
1,711 | public function getSearchResource ( $ resource , $ size = SPIGET4PHP_DEFAULT , $ page = SPIGET4PHP_DEFAULT , $ sort = SPIGET4PHP_DEFAULT , $ fields = SPIGET4PHP_DEFAULT ) { $ function = 'search/resources/' . $ resource ; $ args = [ ] ; if ( ! is_null ( $ size ) ) $ args [ 'size' ] = $ size ; if ( ! is_null ( $ page ) ) $ args [ 'page' ] = $ page ; if ( ! is_null ( $ sort ) ) $ args [ 'sort' ] = $ sort ; if ( ! is_null ( $ fields ) ) $ args [ 'fields' ] = implode ( ',' , $ fields ) ; return $ this -> getResult ( $ function , $ args ) ; } | Get a resource - search results .. |
1,712 | public function getSearchAuthors ( $ author , $ field = SPIGET4PHP_DEFAULT , $ size = SPIGET4PHP_DEFAULT , $ page = SPIGET4PHP_DEFAULT , $ sort = SPIGET4PHP_DEFAULT , $ fields = SPIGET4PHP_DEFAULT ) { $ function = 'search/authors/' . $ author ; $ args = [ ] ; if ( ! is_null ( $ field ) ) $ args [ 'field' ] = $ field ; if ( ! is_null ( $ size ) ) $ args [ 'size' ] = $ size ; if ( ! is_null ( $ page ) ) $ args [ 'page' ] = $ page ; if ( ! is_null ( $ sort ) ) $ args [ 'sort' ] = $ sort ; if ( ! is_null ( $ fields ) ) $ args [ 'fields' ] = implode ( ',' , $ fields ) ; return $ this -> getResult ( $ function , $ args ) ; } | Get the search - result for an specific username . |
1,713 | private function getResult ( $ function , $ args = [ ] , $ post = false ) { $ qargs = ( $ post ? '' : '?' ) . http_build_query ( $ args ) ; $ curl = curl_init ( $ this -> spiget . $ function . ( ! $ post ? ( sizeof ( $ args ) > 0 ? $ qargs : '' ) : '' ) ) ; curl_setopt ( $ curl , CURLOPT_USERAGENT , $ this -> userargent ) ; curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , 1 ) ; if ( $ post ) curl_setopt ( $ curl , CURLOPT_POST , 1 ) ; if ( $ post ) curl_setopt ( $ curl , CURLOPT_POSTFIELDS , $ qargs ) ; $ result = curl_exec ( $ curl ) ; $ http_response = curl_getinfo ( $ curl ) [ 'http_code' ] ; curl_close ( $ curl ) ; if ( $ http_response == 200 ) { return json_decode ( $ result , true ) ; } elseif ( $ this -> throwExceptions ) { throw new SpigetException ( json_decode ( $ result , true ) [ 'error' ] , $ http_response ) ; } else { return null ; } } | Get the result of an api - request . |
1,714 | public static function getInstance ( $ useragent = 'Spiget4PHP' ) { if ( is_null ( SpigetAPI :: $ instance ) ) { SpigetAPI :: $ instance = new SpigetAPI ( $ useragent ) ; } return SpigetAPI :: $ instance ; } | Get the current instance of the api - wrapper or create a new one . |
1,715 | public function fill ( array $ input ) { $ this -> assertIsFillable ( ) ; ArrayMap :: of ( $ input ) -> only ( $ this -> getFillable ( ) ) -> each ( function ( $ value , $ key ) { $ setter = vsprintf ( 'set%s' , [ Str :: studly ( $ key ) ] ) ; if ( method_exists ( $ this , $ setter ) ) { $ this -> $ setter ( $ value ) ; return ; } $ camel = Str :: camel ( $ key ) ; $ this -> $ camel = $ value ; } ) ; return $ this ; } | Fill properties in this object using an input array . |
1,716 | public function toArray ( ) { $ result = [ ] ; ArrayList :: of ( $ this -> getFillable ( ) ) -> append ( ArrayList :: of ( $ this -> getVisible ( ) ) ) -> unique ( SORT_STRING ) -> exceptValues ( $ this -> getHidden ( ) ) -> each ( function ( $ key ) use ( & $ result ) { $ getter = vsprintf ( 'get%s' , [ Str :: studly ( $ key ) ] ) ; if ( method_exists ( $ this , $ getter ) ) { $ result [ $ key ] = $ this -> $ getter ( ) ; return ; } $ camel = Str :: camel ( $ key ) ; $ result [ $ key ] = $ this -> $ camel ; } ) ; return $ result ; } | Get an array representation of this entity . |
1,717 | public function handleRoute ( $ fullslug ) { if ( ! $ structure = $ this -> tree -> find ( $ fullslug ) ) { $ slugParts = explode ( '/' , $ fullslug ) ; foreach ( $ this -> tree -> findBySlug ( end ( $ slugParts ) ) as $ structure ) { if ( $ fullslug == $ structure -> full_slug ) { break ; } } } if ( $ structure ) { return $ this -> renderPage ( $ structure ) ; } return '404' ; } | Handle an Incoming Route . |
1,718 | private function renderPage ( $ structure ) { $ page = $ structure -> page ; $ template = $ structure -> template ? $ structure -> template : 'pages.' . strtolower ( substr ( strrchr ( get_class ( $ page ) , "\\" ) , 1 ) ) ; return view ( $ template , [ 'page' => $ page ] ) ; } | Render a Page |
1,719 | public function deleteFromCache ( $ key ) { $ file = $ this -> cachePath . $ this -> getEncodedKey ( $ key ) ; if ( file_exists ( $ file ) ) { unlink ( $ file ) ; } } | Supprime une valeur du cache |
1,720 | public function clearCache ( ) { $ files = glob ( $ this -> cachePath ) ; foreach ( $ files as $ file ) { if ( is_file ( $ file ) ) { unlink ( $ file ) ; } } } | Supprime tout le contenu du cache |
1,721 | public function setExceptionMessages ( Exception $ e ) { $ this -> flashMessenger ( ) -> addErrorMessage ( [ 'message' => $ e -> getMessage ( ) , 'title' => 'Error!' ] ) ; $ prevException = $ e -> getPrevious ( ) ; if ( $ prevException ) { while ( $ prevException ) { $ this -> flashMessenger ( ) -> addErrorMessage ( $ prevException -> getMessage ( ) ) ; $ prevException = $ prevException -> getPrevious ( ) ; } } } | Sets a exception message for flash plugin . |
1,722 | public function dispatch ( string $ class , string $ method , array $ vars , \ Psr \ Http \ Message \ RequestInterface $ request , \ Psr \ Http \ Message \ ResponseInterface $ response , array $ middlewares ) : \ Psr \ Http \ Message \ ResponseInterface { $ middlewares [ ] = Caller :: class ; $ relayBuilder = new RelayBuilder ( function ( $ instance ) use ( $ class , $ method , $ vars ) { if ( $ instance == Caller :: class ) { return new $ instance ( $ class , $ method , $ vars ) ; } return new $ instance ( ) ; } ) ; $ relay = $ relayBuilder -> newInstance ( $ middlewares ) ; return $ relay ( $ request , $ response ) ; } | Resolver dispatch . |
1,723 | public function getAllTranslationByLanguage ( ) { $ messages = array ( ) ; foreach ( $ this -> getLanguageList ( ) as $ language ) { $ messages [ $ language ] = $ this -> getTranslationsForLanguage ( $ language ) ; } return $ messages ; } | Return the list of all translation . The table has 2 dimensions . The first is the language . The second is the key value of translation |
1,724 | public function getAllKey ( ) { $ keys = array ( ) ; foreach ( $ this -> getAllTranslationByLanguage ( ) as $ translations ) { $ keys = array_merge ( $ keys , $ translations ) ; } return array_keys ( $ keys ) ; } | Return an array with all the key create without language checking |
1,725 | public function internalize ( $ url = '' ) { if ( is_array ( $ url ) ) { $ url = implode ( '/' , $ url ) ; } if ( preg_match ( '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i' , $ url ) ) return $ url ; $ sPath = $ this -> request -> getBasePath ( ) . "/" ; if ( ! empty ( $ url ) && $ sPath <> "/" ) { $ parts = explode ( "/" , $ sPath ) ; $ segments = explode ( "/" , $ url ) ; $ segments = array_filter ( $ segments , 'strlen' ) ; $ parts = array_filter ( $ parts , 'strlen' ) ; array_unshift ( $ parts , null ) ; $ fragment = implode ( "/" , $ parts ) ; if ( is_array ( $ segments ) ) { array_unshift ( $ segments , null ) ; $ url = implode ( "/" , $ segments ) ; $ pos = strpos ( $ url , $ fragment ) ; if ( $ pos !== 0 || $ pos === FALSE ) { $ url = $ fragment . $ url ; } } } return $ url ; } | Resolves a url adds path if missing |
1,726 | public function externalize ( $ path , $ schema = "http" ) { if ( ! is_array ( $ path ) ) : if ( preg_match ( '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i' , $ path ) ) return $ path ; endif ; $ sHost = $ this -> request -> getHost ( ) ; $ path = $ schema . "://" . $ sHost . static :: internalize ( $ path ) ; return $ path ; } | Adds the schema host and path to an internal url path |
1,727 | public static function trimPattern ( $ value , array $ params ) { if ( empty ( $ value ) || empty ( $ params [ 'pattern' ] ) ) { return $ value ; } $ params [ 'limit' ] = Helper :: getValue ( $ params [ 'limit' ] , - 1 ) ; return StringHelper :: trimPattern ( $ value , $ params [ 'pattern' ] , $ params [ 'limit' ] ) ; } | Trim by pattern . |
1,728 | public static function contains ( $ value , array $ params , Template $ template ) { if ( empty ( $ params ) || count ( $ params ) < 2 || ! isset ( $ params [ 'then' ] ) ) { throw new TemplateException ( TemplateException :: UNKNOWN_PARAM_FILTER , [ 'name' => __METHOD__ ] ) ; } $ params [ 'else' ] = isset ( $ params [ 'else' ] ) ? $ params [ 'else' ] : null ; $ template = clone $ template ; $ placeholders = [ ] ; $ placeholders [ 'output' ] = $ value ; return StringHelper :: contains ( $ value , $ template -> replace ( $ params [ 'is' ] ) ) ? $ template -> replace ( $ params [ 'then' ] , $ placeholders ) : $ template -> replace ( $ params [ 'else' ] , $ placeholders ) ; } | Check contains word or char in string |
1,729 | public static function truncateWords ( $ value , array $ params ) { if ( empty ( $ params [ 'length' ] ) || ! is_numeric ( $ params [ 'length' ] ) ) { $ params [ 'length' ] = 100 ; } return StringHelper :: truncateWords ( $ value , ( int ) $ params [ 'length' ] ) ; } | Truncates a string to the number of words specified . |
1,730 | protected function updateAuthConfig ( ) { $ path = config_path ( 'auth.php' ) ; file_put_contents ( $ path , str_replace ( 'users' , 'SecUsers' , file_get_contents ( $ path ) ) ) ; file_put_contents ( $ path , str_replace ( 'App\User::class' , 'Alfredoem\Ragnarok\SecUsers\SecUser::class' , file_get_contents ( $ path ) ) ) ; } | Update the auth configuration file . |
1,731 | public function generate ( $ length = 10 , $ availables = self :: CHAR_ALPHADIGIT , array $ tokens = array ( self :: CHAR_ALPHA , self :: CHAR_DIGIT ) ) { $ tokens = array_pad ( $ tokens , $ length , $ availables ) ; shuffle ( $ tokens ) ; $ password = '' ; foreach ( $ tokens as $ token ) { $ tokenChars = '' ; foreach ( $ this -> primarySets as $ flag => $ chars ) { if ( bintest ( $ token , $ flag ) ) { $ tokenChars .= $ chars ; } } $ password .= $ tokenChars [ mt_rand ( 0 , strlen ( $ tokenChars ) - 1 ) ] ; } return $ password ; } | Generate a random complex password |
1,732 | public function bind ( $ id , $ concrete = null , $ shared = false ) { if ( null === $ concrete ) { $ concrete = $ id ; } $ id = $ this -> normalizeString ( $ id ) ; if ( is_object ( $ concrete ) && ! $ concrete instanceof \ Closure ) { $ instance = $ this -> applyExtenders ( $ id , $ concrete ) ; $ this -> sharedInstances [ $ id ] = $ instance ; return ; } $ concrete = $ this -> normalizeString ( $ concrete ) ; if ( is_callable ( $ concrete ) || ( is_array ( $ concrete ) && is_callable ( $ concrete [ 0 ] ) ) ) { if ( false === $ shared ) { $ this -> definitions [ $ id ] = ( array ) $ concrete ; return ; } $ this -> sharedDefinitions [ $ id ] = ( array ) $ concrete ; return ; } if ( is_string ( $ concrete ) && class_exists ( $ concrete ) || ( is_array ( $ concrete ) && class_exists ( $ concrete [ 0 ] ) ) ) { if ( false === $ shared ) { $ this -> definitions [ $ id ] = ( array ) $ concrete ; return ; } $ this -> sharedDefinitions [ $ id ] = ( array ) $ concrete ; return ; } $ this -> sharedInstances [ $ id ] = $ concrete ; } | Binds an id and value into the container . |
1,733 | public function extend ( $ id , callable $ extender ) { if ( ! $ this -> has ( $ id ) ) { throw new NotFoundException ( 'Alias (' . $ id . ') is not being managed by the container' ) ; } $ this -> extenders [ $ id ] [ ] = $ extender ; } | Allows registration of callbacks run before the instance is resolved from the container . |
1,734 | public function save ( ) { if ( ! $ entityMgr = $ this -> getEntityManager ( ) ) { throw new \ Exception ( 'Model can not be inserted without an Entity Manager (setEntityManager).' ) ; } if ( ! $ this -> getTableName ( ) ) { throw new \ Exception ( 'Model can not be inserted without a defined table name.' ) ; } $ stmtManager = $ entityMgr -> getStatementManager ( Simple :: class ) ; $ stmtBuilder = $ stmtManager -> getStatementBuilder ( InsertModel :: class ) ; return $ stmtManager -> setStatement ( $ stmtBuilder -> setModel ( $ this ) ) -> setConsistency ( \ Cassandra :: CONSISTENCY_LOCAL_ONE ) -> execute ( ) ; } | Saves a model to the database . |
1,735 | public function slugify ( $ name , $ pluralize = true ) { if ( class_exists ( $ name ) ) { $ name = $ this -> shortName ( $ name ) ; } $ inflector = Inflector :: get ( ) ; if ( $ pluralize === true ) { $ name = $ inflector -> pluralize ( $ name ) ; } return $ inflector -> dasherize ( $ inflector -> underscore ( $ name ) ) ; } | Constructs a slug for a class name or other subject for use in URLs . |
1,736 | public function pluralize ( $ className ) { $ className = $ this -> shortName ( $ className ) ; $ inflector = Inflector :: get ( ) ; return $ inflector -> pluralize ( $ className ) ; } | Pluralizes a class s name . |
1,737 | public final function enable ( $ state = true ) { $ old_state = $ this -> _enabled ; $ this -> _enabled = ( bool ) $ state ; return $ old_state ; } | Toggle the enabled - state of the Cache . |
1,738 | protected function validateValueSize ( $ value ) { $ size = strlen ( serialize ( $ value ) ) ; $ allowed = 1024 * 1024 * 4 ; if ( $ size > $ allowed ) { return false ; } return true ; } | Check if the serialized value is smaller than 2 MB . |
1,739 | public static function exists ( string $ file = '' ) : bool { $ file = static :: normalizePath ( $ file ) ; return static :: verifyPath ( $ file ) && \ file_exists ( $ file ) && \ is_file ( $ file ) ; } | Checks whether file exists . |
1,740 | public static function isLink ( string $ file = '' ) : bool { $ file = static :: normalizePath ( $ file ) ; return static :: exists ( $ file ) && \ is_link ( $ file ) ; } | Checks whether file is a link |
1,741 | public static function read ( string $ file = '' ) : string { $ result = false ; $ file = static :: normalizePath ( $ file ) ; if ( static :: exists ( $ file ) ) { $ result = @ \ file_get_contents ( $ file ) ; } return $ result ; } | Reads data from file . |
1,742 | public static function write ( string $ file = '' , string $ data = '' , bool $ doAppend = false ) : bool { $ result = false ; $ file = static :: normalizePath ( $ file ) ; if ( static :: verifyPath ( $ file ) && Directory :: create ( \ dirname ( $ file ) ) ) { $ flags = $ doAppend ? FILE_APPEND : 0 ; $ flags |= static :: $ writeLocks ? LOCK_EX : 0 ; $ result = @ \ file_put_contents ( $ file , $ data , $ flags ) !== false ; @ \ chmod ( $ file , static :: $ newFileMode ) ; } return $ result ; } | Writes data to file . Creates directories if required . |
1,743 | public static function append ( string $ file = '' , string $ data = '' ) : bool { return static :: write ( $ file , $ data , true ) ; } | Appends data to file . |
1,744 | public static function getThemePath ( ) { $ reflector = new \ ReflectionClass ( get_called_class ( ) ) ; $ namespaceName = $ reflector -> getNamespaceName ( ) ; static :: $ themePath = '@' . str_replace ( '\\' , '/' , $ namespaceName ) ; return static :: $ themePath ; } | Gets the called theme class path . |
1,745 | public static function registerTranslations ( ) { if ( ! isset ( Yii :: $ app -> i18n -> translations [ static :: getThemePath ( ) . '/*' ] ) && ! isset ( Yii :: $ app -> i18n -> translations [ static :: getThemePath ( ) ] ) ) { Yii :: $ app -> i18n -> translations [ static :: getThemePath ( ) . '/*' ] = [ 'class' => 'yii\i18n\PhpMessageSource' , 'sourceLanguage' => 'en-US' , 'basePath' => static :: getThemePath ( ) . '/messages' , 'fileMap' => [ static :: getThemePath ( ) . '/message' => 'message.php' , ] , ] ; } } | Registers the translation files . |
1,746 | function mf_redirect ( $ section = 'mf_dashboard' , $ action = 'main' , $ vars = array ( ) ) { $ url = $ this -> _get_url ( $ section , $ action , $ vars ) ; wp_safe_redirect ( $ url ) ; exit ; } | is a wrapper of wp_safe_redirect |
1,747 | function mf_flash ( $ message = 'Return dashoard' , $ url = array ( 'section' => 'mf_dashboard' , 'action' => 'main' , 'vars' => '' ) , $ type = 'error' ) { if ( is_array ( $ url ) ) { $ url = $ this -> _get_url ( $ url [ 'section' ] , $ url [ 'action' ] , $ url [ 'vars' ] ) ; } printf ( ' <div class="wrap"><div id="message" class="%s below-h2"><p><a href="%s">%s</a></p></div> </div>' , $ type , $ url , $ message ) ; if ( ! WP_DEBUG ) { printf ( '<script type="text/javascript"> function js_mf_redirect(){ window.location = "%s"; } setTimeout(js_mf_redirect,5000); </script>' , $ url ) ; } die ; } | Display a friendly message of error |
1,748 | public function get_custom_taxonomy_by_type ( $ type_taxonomy ) { global $ wpdb ; $ query = sprintf ( "SELECT * FROM %s WHERE type = '%s'" , MF_TABLE_CUSTOM_TAXONOMY , $ type_taxonomy ) ; $ custom_taxonomy = $ wpdb -> get_row ( $ query , ARRAY_A ) ; if ( $ custom_taxonomy ) { $ id = $ custom_taxonomy [ 'id' ] ; $ custom_taxonomy = unserialize ( $ custom_taxonomy [ 'arguments' ] ) ; $ custom_taxonomy [ 'core' ] [ 'id' ] = $ id ; return $ custom_taxonomy ; } return false ; } | get a specific custom_taxonomy |
1,749 | public function get_groups_by_post_type ( $ post_type ) { global $ wpdb ; $ query = sprintf ( "SELECT * FROM %s WHERE post_type = '%s' ORDER BY id" , MF_TABLE_CUSTOM_GROUPS , $ post_type ) ; $ groups = $ wpdb -> get_results ( $ query , ARRAY_A ) ; return $ groups ; } | return all gruops of post type |
1,750 | public function get_default_custom_group ( $ post_type ) { global $ wpdb ; $ query = sprintf ( "SELECT id FROM %s WHERE name = '__default' AND post_type = '%s' " , MF_TABLE_CUSTOM_GROUPS , $ post_type ) ; $ group = $ wpdb -> get_col ( $ query ) ; if ( ! $ group ) { $ wpdb -> insert ( MF_TABLE_CUSTOM_GROUPS , array ( 'name' => '__default' , 'label' => 'Magic Fields' , 'post_type' => $ post_type ) , array ( '%s' , '%s' , '%s' ) ) ; $ custom_group_id = $ wpdb -> insert_id ; } else { $ custom_group_id = $ group [ 0 ] ; } return $ custom_group_id ; } | Return id of default group for post type |
1,751 | public static function group_has_fields ( $ group_id ) { global $ wpdb ; $ sql = $ wpdb -> prepare ( "SELECT COUNT(1) FROM " . MF_TABLE_CUSTOM_FIELDS . " WHERE custom_group_id = %d" , $ group_id ) ; return $ wpdb -> get_var ( $ sql ) > 0 ; } | Return True if the group has at least one custom field |
1,752 | public function get_custom_fields_by_group ( $ id ) { global $ wpdb ; $ query = sprintf ( "SELECT * FROM %s WHERE custom_group_id = '%s' ORDER BY display_order" , MF_TABLE_CUSTOM_FIELDS , $ id ) ; $ fields = $ wpdb -> get_results ( $ query , ARRAY_A ) ; return $ fields ; } | return all fields of group |
1,753 | public static function get_unique_custom_fields_by_post_type ( $ post_type = "post" ) { global $ wpdb ; $ query = "SELECT DISTINCT(type) FROM " . MF_TABLE_CUSTOM_FIELDS . " WHERE post_type = '" . $ post_type . "'" ; $ fields = $ wpdb -> get_col ( $ query ) ; return $ fields ; } | return a unique type the fields of post type |
1,754 | public function get_custom_field_by_name ( $ name_custom_field , $ post_type ) { global $ wpdb ; $ query = sprintf ( 'SELECT * FROM %s WHERE name = "%s" AND post_type = "%s" ' , MF_TABLE_CUSTOM_FIELDS , $ name_custom_field , $ post_type ) ; $ field = $ wpdb -> get_row ( $ query , ARRAY_A ) ; return $ field ; } | return a field by name and post type |
1,755 | public function new_posttype ( $ data ) { global $ wpdb ; array_walk_recursive ( $ data , array ( $ this , 'escape_data' ) ) ; $ sql = $ wpdb -> prepare ( "INSERT INTO " . MF_TABLE_POSTTYPES . " (type, name, description, arguments, active)" . " values" . " (%s, %s, %s, %s, %d)" , $ data [ 'core' ] [ 'type' ] , $ data [ 'core' ] [ 'label' ] , $ data [ 'core' ] [ 'description' ] , serialize ( $ data ) , 1 ) ; $ wpdb -> query ( $ sql ) ; $ postTypeId = $ wpdb -> insert_id ; return $ postTypeId ; } | Save a new post |
1,756 | public function update_post_type ( $ data ) { global $ wpdb ; array_walk_recursive ( $ data , array ( $ this , 'escape_data' ) ) ; $ sql = $ wpdb -> prepare ( "Update " . MF_TABLE_POSTTYPES . " SET type = %s, name = %s, description = %s, arguments = %s " . " WHERE id = %d" , $ data [ 'core' ] [ 'type' ] , $ data [ 'core' ] [ 'label' ] , $ data [ 'core' ] [ 'description' ] , serialize ( $ data ) , $ data [ 'core' ] [ 'id' ] ) ; $ wpdb -> query ( $ sql ) ; } | Update Post type data |
1,757 | public function new_custom_group ( $ data ) { global $ wpdb ; array_walk_recursive ( $ data , array ( $ this , 'escape_data' ) ) ; $ sql = $ wpdb -> prepare ( "INSERT INTO " . MF_TABLE_CUSTOM_GROUPS . " (name, label, post_type, duplicated, expanded) " . " VALUES (%s, %s, %s, %d, %d)" , $ data [ 'core' ] [ 'name' ] , $ data [ 'core' ] [ 'label' ] , $ data [ 'core' ] [ 'post_type' ] , $ data [ 'core' ] [ 'duplicate' ] , 1 ) ; $ wpdb -> query ( $ sql ) ; $ postTypeId = $ wpdb -> insert_id ; return $ postTypeId ; } | Add a new custom group |
1,758 | public function update_custom_group ( $ data ) { global $ wpdb ; array_walk_recursive ( $ data , array ( $ this , 'escape_data' ) ) ; $ sql = $ wpdb -> prepare ( "UPDATE " . MF_TABLE_CUSTOM_GROUPS . " SET name = %s, label =%s, duplicated = %d, expanded = %d " . " WHERE id = %d" , $ data [ 'core' ] [ 'name' ] , $ data [ 'core' ] [ 'label' ] , $ data [ 'core' ] [ 'duplicate' ] , 1 , $ data [ 'core' ] [ 'id' ] ) ; $ wpdb -> query ( $ sql ) ; } | Update a custom group |
1,759 | public function new_custom_taxonomy ( $ data ) { global $ wpdb ; array_walk_recursive ( $ data , array ( $ this , 'escape_data' ) ) ; $ sql = $ wpdb -> prepare ( "INSERT INTO " . MF_TABLE_CUSTOM_TAXONOMY . " (type, name, description, arguments, active)" . " values" . " (%s, %s, %s, %s, %d)" , $ data [ 'core' ] [ 'type' ] , $ data [ 'core' ] [ 'name' ] , $ data [ 'core' ] [ 'description' ] , serialize ( $ data ) , 1 ) ; $ wpdb -> query ( $ sql ) ; $ custom_taxonomy_id = $ wpdb -> insert_id ; return $ custom_taxonomy_id ; } | Save a new custom taxonomy |
1,760 | public function update_custom_taxonomy ( $ data ) { global $ wpdb ; array_walk_recursive ( $ data , array ( $ this , 'escape_data' ) ) ; $ sql = $ wpdb -> prepare ( "Update " . MF_TABLE_CUSTOM_TAXONOMY . " SET type = %s, name = %s, description = %s, arguments = %s " . " WHERE id = %d" , $ data [ 'core' ] [ 'type' ] , $ data [ 'core' ] [ 'name' ] , $ data [ 'core' ] [ 'description' ] , serialize ( $ data ) , $ data [ 'core' ] [ 'id' ] ) ; $ wpdb -> query ( $ sql ) ; } | Update a custom taxonomy |
1,761 | function get ( $ name ) { if ( ! isset ( $ this -> db [ $ name ] ) ) { return null ; } $ r = $ this -> db [ $ name ] ; return $ r ( ) ; } | Get an object from the resource factory |
1,762 | public static function S2c ( $ theta , $ phi , array & $ c ) { $ cp ; $ cp = cos ( $ phi ) ; $ c [ 0 ] = cos ( $ theta ) * $ cp ; $ c [ 1 ] = sin ( $ theta ) * $ cp ; $ c [ 2 ] = sin ( $ phi ) ; return ; } | - - - - - - - i a u S 2 c - - - - - - - |
1,763 | public function run ( ) { if ( ! is_array ( $ rules = $ this -> getRules ( ) ) ) { $ rules = $ this -> convertToArray ( $ rules ) ; } if ( ! is_array ( $ datas = $ this -> getDatas ( ) ) ) { $ datas = $ this -> convertToArray ( $ datas ) ; } foreach ( $ rules as $ key => $ rule ) { $ parsedRules = explode ( "|" , $ rule ) ; foreach ( $ parsedRules as $ parsedRule ) { $ required = $ this -> handleRule ( $ parsedRule , $ key , $ datas ) ; if ( $ required !== null && $ required === false ) { break ; } } } } | determine datas is correct or not |
1,764 | private function handleRule ( $ rule , $ key , array $ allDatas ) { $ methodName = "run" ; if ( ! strstr ( $ rule , "_" ) ) { $ methodName .= ucfirst ( $ rule ) ; } else { $ parsedName = array_map ( function ( $ value ) { return ucfirst ( $ value ) ; } , explode ( "_" , $ rule ) ) ; $ methodName = $ methodName . join ( "" , $ parsedName ) ; } if ( ! strstr ( $ rule , ":" ) ) { $ called = $ this -> callMethod ( $ methodName , [ $ key , $ allDatas , $ rule ] ) ; } else { $ value = explode ( ":" , $ key ) [ 1 ] ; if ( strstr ( $ value , "," ) ) { $ sendDatas = [ explode ( "," , $ value ) , $ key , $ allDatas , $ rule ] ; } else { $ sendDatas = [ $ value , $ key , $ allDatas , $ rule ] ; } $ called = $ this -> callMethod ( $ methodName , $ sendDatas ) ; } return $ called ; } | handle the given rule |
1,765 | private function callMethod ( $ methodName , $ datas ) { if ( method_exists ( $ this , $ methodName ) ) { $ call = [ $ this , $ methodName ] ; } elseif ( isset ( $ this -> extends [ $ methodName ] ) ) { $ call = $ this -> extends [ $ methodName ] ; } else { throw new MethodNotExistsException ( sprintf ( '%s method is not exists in Validation class' , $ methodName ) ) ; } if ( $ methodName !== 'runRequired' ) { $ return = call_user_func_array ( [ $ this , 'runRequired' ] , count ( $ datas ) === 4 ? array_slice ( $ datas , 1 , 4 ) : $ datas ) ; } call_user_func_array ( $ call , $ datas ) ; return $ return ; } | calls method or callable function with given datas |
1,766 | protected function runNumeric ( $ key , $ datas , $ rule = '' ) { if ( ! isset ( $ datas [ $ key ] ) ) { if ( ! is_numeric ( $ datas [ $ key ] ) ) { $ this -> fails [ ] = $ messageKey = "numeric.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } } | determine data is numeric |
1,767 | protected function runAlpha ( $ key , $ datas , $ rule ) { $ data = $ datas [ $ key ] ; if ( ! preg_match ( "([A-Z])" , $ data ) ) { $ this -> fails [ ] = $ messageKey = "alpha.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine the data is a variable alphabetic charecter |
1,768 | protected function runEmail ( $ key , $ datas , $ rule ) { $ email = $ datas [ $ key ] ; if ( filter_var ( $ email , FILTER_VALIDATE_EMAIL ) === false ) { $ this -> fails [ ] = $ messageKey = "email.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine email is right |
1,769 | protected function runJson ( $ key , $ datas , $ rule ) { if ( json_decode ( $ datas [ $ key ] ) === false ) { $ this -> fails [ ] = $ messageKey = "json.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine if given data is a valid json data |
1,770 | protected function runSizeBetween ( $ array , $ key , $ datas , $ rule ) { $ data = $ datas [ $ key ] ; $ min = $ array [ 0 ] ; $ max = $ array [ 1 ] ; if ( $ data < $ min || $ data > $ max ) { $ this -> fails [ ] = $ messageKey = "$rule.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey , [ 'min' => $ min , 'max' => $ max ] ) ; } } | determine data is correct |
1,771 | protected function runRegex ( $ regex , $ key , $ datas , $ rule ) { if ( ! preg_match ( $ regex , $ datas [ $ key ] ) ) { $ this -> fails [ ] = $ messageKey = "regex.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine given regex is matching with given datas |
1,772 | protected function runSame ( $ same , $ key , $ datas , $ rule ) { if ( ! is_array ( $ same ) ) { $ sames = $ this -> convertToArray ( $ same ) ; } $ data = $ datas [ $ key ] ; $ status = true ; foreach ( $ sames as $ same ) { if ( $ same != $ data ) { $ status = false ; break ; } } if ( $ status === false ) { $ this -> fails [ ] = $ mKey = "same.$key" ; $ this -> addMessage ( $ key , $ rule , $ mKey , [ 'not' => $ same ] ) ; } } | determine datas are same or not |
1,773 | protected function runUrl ( $ key , $ datas , $ rule ) { $ data = $ datas [ $ key ] ; if ( ! filter_var ( $ data , FILTER_SANITIZE_URL ) ) { $ this -> fails [ ] = $ messageKey = "url.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine url is valid |
1,774 | protected function runDate ( $ key , $ datas , $ rule ) { if ( false === strtotime ( $ datas [ $ key ] ) ) { $ this -> fails [ ] = $ messageKey = "date.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine the date is a valid value |
1,775 | protected function runTableExists ( $ key , $ datas , $ rule ) { $ data = $ datas [ $ key ] ; $ advanced = Database :: table ( $ data ) -> tableExists ( ) ; if ( ! $ advanced -> isSuccess ( ) ) { $ this -> fails [ ] = $ messageKey = "$rule.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine is table exists in database . base |
1,776 | protected function runColumnExists ( $ column , $ key , $ datas , $ rule ) { $ advanced = Database :: table ( $ datas [ $ key ] ) -> columnExists ( $ column ) ; if ( ! $ advanced -> isSuccess ( ) ) { $ this -> fails [ ] = $ messageKey = "$rule.$key" ; $ this -> addMessage ( $ key , $ rule , $ messageKey ) ; } } | determine is column exists in database . base |
1,777 | protected function addMessage ( $ key , $ rule , $ specialRule , array $ datas = [ ] ) { $ specialMessages = $ this -> getMessageReposity ( ) ; $ defaultMessages = $ this -> defaultErrorMessages ; if ( count ( $ datas ) === 0 ) { $ datas = [ $ key ] ; } if ( isset ( $ specialMessages [ $ specialRule ] ) ) { $ selectedMessage = $ specialMessages [ $ specialRule ] ; } else { $ selectedMessage = $ defaultMessages [ $ rule ] ; } array_unshift ( $ datas , $ selectedMessage ) ; $ this -> failedMessages [ ] = call_user_func_array ( 'sprintf' , $ datas ) ; } | adds a error message |
1,778 | private function convertToArray ( $ notArray ) { if ( is_object ( $ notArray ) || is_string ( $ notArray ) || is_numeric ( $ notArray ) ) { return ( array ) $ notArray ; } else { throw new Exception ( sprintf ( 'your data could not convert to array' ) ) ; } } | tries convert given variable type to array |
1,779 | public function getMaxOpenFilesLimit ( ) { static $ limit = null ; if ( null === $ limit ) { $ process = new Process ( 'ulimit -n' ) ; $ process -> run ( ) ; if ( $ process -> isSuccessful ( ) ) { $ limit = ( int ) trim ( $ process -> getOutput ( ) ) ; } unset ( $ process ) ; } return $ limit ; } | Get max open files limit . |
1,780 | protected function getComposerCommand ( ) { static $ command = null ; if ( null !== $ command ) { return $ command ; } $ pharFile = $ this -> projectPath . '/composer.phar' ; if ( file_exists ( $ pharFile ) ) { return $ command = '/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off "' . $ pharFile . '"' ; } $ composerFile = $ this -> projectPath . '/composer' ; if ( file_exists ( $ composerFile ) ) { return $ command = './composer' ; } $ process = new Process ( 'hash composer' ) ; $ process -> run ( ) ; $ isSuccessful = $ process -> isSuccessful ( ) ; unset ( $ process ) ; if ( $ isSuccessful ) { return $ command = 'composer' ; } return $ command ; } | Get composer command . |
1,781 | protected function generateOptimizedClassmap ( ) { $ composerCommand = $ this -> getComposerCommand ( ) ; if ( ! $ composerCommand ) { $ this -> logger -> log ( '<error>Could not find composer command</error>' ) ; return false ; } $ process = new Process ( $ composerCommand . ' dump-autoload --optimize' , $ this -> projectPath ) ; $ process -> run ( ) ; if ( ! $ process -> isSuccessful ( ) ) { $ this -> logger -> log ( '<error>Could not optimize class map</error>' ) ; } $ this -> logger -> log ( '<info>Optimized class map</info>' ) ; unset ( $ process ) ; return true ; } | Generate optimized classmap . |
1,782 | protected function addFile ( $ phar , $ file , $ strip = true ) { $ path = strtr ( str_replace ( $ this -> projectPath , '' , $ file -> getRealPath ( ) ) , '\\' , '/' ) ; $ content = file_get_contents ( $ file ) ; $ this -> logger -> log ( '<comment>Adding file</comment> ' . $ path ) ; switch ( true ) { case ( 'LICENSE' === basename ( $ file ) ) : $ content = "\n" . $ content . "\n" ; break ; case preg_match ( '#/In2pire/Cli/Configuration/PhpConfiguration.php$#' , $ path ) : if ( $ this -> flag & STATIC :: FLAG_CACHE ) { $ configuration = $ this -> getAllConfiguration ( ) ; $ content = str_replace ( '// [CONFIGURATION]' , '$this->configuration = ' . var_export ( $ configuration , 1 ) . ';' , $ content ) ; $ content = str_replace ( [ '@version' , '@build' ] , [ $ this -> buildVersion , $ this -> buildDate ] , $ content ) ; } break ; case ( pathinfo ( $ file , PATHINFO_EXTENSION ) == 'yml' ) : $ content = str_replace ( [ '@version' , '@build' ] , [ $ this -> buildVersion , $ this -> buildDate ] , $ content ) ; break ; case $ strip : $ content = $ this -> stripWhitespace ( $ content ) ; break ; } $ phar -> addFromString ( $ path , $ content ) ; $ this -> increaseFileCounter ( ) ; } | Add file to phar package . |
1,783 | protected function addBinFile ( $ phar , $ binFile ) { $ relativeBinFile = str_replace ( $ this -> projectPath , '' , $ binFile ) ; $ this -> logger -> log ( '<comment>Adding file</comment> ' . $ relativeBinFile ) ; $ content = file_get_contents ( $ binFile ) ; $ content = preg_replace ( '{^#!/usr/bin/env php\s*}' , '' , $ content ) ; $ phar -> addFromString ( $ relativeBinFile , $ content ) ; $ this -> increaseFileCounter ( ) ; } | Add bin file . |
1,784 | protected function findFiles ( ) { $ finder = new Finder ( ) ; $ finder -> files ( ) -> ignoreVCS ( true ) -> exclude ( 'Tests' ) -> exclude ( 'tests' ) -> exclude ( 'composer.bak' ) ; if ( ! empty ( $ this -> excludeFiles ) ) { foreach ( $ this -> excludeFiles as $ file ) { $ finder -> notPath ( $ file ) ; } } return $ finder ; } | Get finder . |
1,785 | public function run ( ) { $ this -> returnCode = static :: RETURN_SUCCESS ; $ this -> lastError = null ; $ this -> builtFile = null ; if ( ! $ this -> backupComposer ( ) ) { $ this -> lastError = 'Could not backup composer directory' ; return $ this -> returnCode = static :: RETURN_ERROR ; } try { if ( $ this -> flag & static :: FLAG_OPTIMIZE ) { $ this -> generateOptimizedClassmap ( ) ; } $ this -> returnCode = $ this -> compile ( ) ; } catch ( \ Exception $ e ) { $ this -> lastError = get_class ( $ e ) . ': ' . $ e -> getMessage ( ) ; $ this -> returnCode = static :: RETURN_ERROR ; } if ( ! $ this -> restoreComposer ( ) ) { $ this -> lastError = 'Could not restore composer directory' ; return $ this -> returnCode = static :: RETURN_ERROR ; } return $ this -> returnCode ; } | Run compiler . |
1,786 | public function service ( $ name ) { if ( isset ( $ this -> resolved [ $ name ] ) ) { return $ this -> resolved [ $ name ] ; } $ service = $ this -> resolver -> resolve ( $ name ) ; $ serviceArgs = $ this -> resolveFuncArgs ( $ service ) ; return $ this -> resolved [ $ name ] = $ service -> invoke ( $ serviceArgs ) ; } | Returns the built service by name . |
1,787 | public function inject ( $ injectable ) { $ func = new Func ( $ injectable ) ; $ args = $ this -> resolveFuncArgs ( $ func ) ; return $ func -> invoke ( $ args ) ; } | Gathers the parameters for and runs the injectable . |
1,788 | protected function resolveFuncArgs ( Func $ func ) { $ params = $ this -> reader -> read ( $ func ) ; $ args = array ( ) ; foreach ( $ params as $ param ) { $ name = $ param -> name ; $ inst = $ this -> tryService ( $ name ) ; if ( ! $ inst && $ param -> hasDefault ) { $ args [ $ name ] = $ param -> default ; } else if ( $ inst && $ param -> type && $ this -> checker -> validate ( $ param -> type , $ inst ) ) { $ args [ $ name ] = $ inst ; } else if ( $ inst && $ param -> type && ! $ this -> checker -> validate ( $ param -> type , $ inst ) ) { throw new ResolutionException ( "Parameter type is not compatible with service '$name'" ) ; } else if ( $ inst ) { $ args [ $ name ] = $ inst ; } else { throw new ResolutionException ( "Could not resolve parameter '$name'" ) ; } } return $ args ; } | Guts of the operation - binds parameters to services . |
1,789 | public function createResponse ( ) { if ( ! $ this -> resource instanceof ResourceInterface ) { return $ this -> response ; } return $ this -> response -> setResource ( $ this -> resource ) -> create ( ) ; } | Create and return the resource data |
1,790 | public static function formatMessage ( $ callable , $ parameterName ) { switch ( true ) { case is_array ( $ callable ) : $ message = sprintf ( '%s::%s()' , get_class ( $ callable [ 0 ] ) , $ callable [ 1 ] ) ; break ; case is_object ( $ callable ) : $ message = get_class ( $ callable ) ; break ; default : $ message = ( string ) $ callable ; break ; } return 'Unable to match parameter named [' . $ parameterName . '] for the callable [' . $ message . ']' ; } | Method to format the exception message |
1,791 | public function setModule ( $ name , $ module , $ parameters = null ) { $ name = strtolower ( $ name ) ; if ( class_exists ( $ module , true ) ) { $ instance = new $ module ( $ parameters ) ; $ this -> registerModule ( $ name , $ instance ) ; } return $ this ; } | Set and register new module . |
1,792 | public function setService ( $ name , $ service , $ parameters = null ) { $ name = strtolower ( $ name ) ; if ( $ service instanceof \ Closure ) { $ this -> registerService ( $ name , $ service ) ; } elseif ( class_exists ( $ service , true ) ) { $ this -> registerService ( $ name , new $ service ( $ parameters ) ) ; } return $ this ; } | Set and register a new services |
1,793 | public function getServiceInstance ( $ service , $ new = false ) { if ( isset ( $ this -> services -> $ service ) ) { if ( $ new === true ) { return clone $ this -> services -> $ service ; } else { return $ this -> services -> $ service ; } } return null ; } | Get a instance of the requested service . |
1,794 | protected function hasOption ( $ name , $ shortcut = null ) { return ( $ shortcut && array_key_exists ( $ shortcut , $ _GET ) ) ? true : array_key_exists ( $ name , $ _GET ) ; } | Check option exists |
1,795 | protected function writeTable ( array $ headers , array $ rows ) { $ columnCount = count ( $ headers ) ; $ rowCount = count ( $ rows ) + 1 ; $ columns = array_fill ( 0 , $ columnCount , 0 ) ; $ tables = [ ] ; foreach ( array_merge ( [ $ headers ] , $ rows ) as $ row ) { $ i = - 1 ; $ newRow = [ ] ; foreach ( $ row as $ col ) { $ newRow [ ++ $ i ] = StringParser :: create ( $ col ) -> getParsed ( ) ; $ newRow [ $ i ] [ 'len' ] = 0 ; foreach ( $ newRow [ $ i ] as $ part ) { $ newRow [ $ i ] [ 'len' ] += strlen ( $ part [ 'original' ] ) ; } $ columns [ $ i ] = max ( $ columns [ $ i ] , $ newRow [ $ i ] [ 'len' ] ) ; } $ tables [ ] = $ newRow ; } $ i = - 1 ; $ line = str_repeat ( '-' , array_sum ( $ columns ) + $ columnCount + 2 ) ; foreach ( $ tables as $ row ) { if ( ++ $ i === 0 ) { echo $ line . PHP_EOL ; } $ j = - 1 ; foreach ( $ row as $ col ) { ++ $ j ; $ len = array_pop ( $ col ) ; foreach ( $ col as $ part ) { echo ' ' . $ part [ 'colored' ] ; echo str_repeat ( ' ' , $ columns [ $ j ] - $ len + 1 ) ; } } if ( $ i === 0 ) { echo PHP_EOL ; echo $ line ; } echo PHP_EOL ; if ( $ i === $ rowCount - 1 ) { echo $ line . PHP_EOL ; } } } | Write simple table |
1,796 | public function getProjectRoot ( string $ tail = '' ) : string { if ( empty ( $ this -> root ) || ! is_dir ( $ this -> root ) ) { throw new \ Exception ( "Invalid root dir or not set yet!" ) ; } return realpath ( $ this -> root ) . $ tail ; } | Get absolute project directory path |
1,797 | public function getCurrentUrl ( ) : string { $ wp = Core :: get ( WP :: class ) ; return $ this -> wpProvider -> homeUrl ( $ this -> wpProvider -> addQueryArg ( [ ] , $ wp -> request ) ) ; } | Get current url with WP global query |
1,798 | public function dispatch ( $ call = null ) { $ command = $ this -> routes -> get ( $ this -> arguments -> getCommand ( 1 ) , false ) ; if ( $ this -> routes -> get ( $ call , false ) ) { $ command = $ this -> routes -> get ( $ call , false ) ; } if ( $ command ) { $ handler = new ClassMethodHandler ( $ command , $ this -> arguments ) ; return $ handler -> call ( $ this -> arguments ) ; } throw new CommandNotFoundException ( sprintf ( 'Command %s is not registered.' , $ call ) ) ; } | Dispatches the command handler . |
1,799 | public static function getLogger ( Configuration $ configuration ) : LoggerInterface { $ identifier = $ configuration -> getIdentifier ( ) ; if ( isset ( self :: $ _loggers [ $ identifier ] ) ) { return self :: $ _loggers [ $ identifier ] ; } switch ( $ configuration -> getImplementation ( ) ) { case CsvLogger :: class : case FileLogger :: class : $ fileName = $ configuration -> getFileName ( ) ; if ( isset ( self :: $ _nameMap [ $ fileName ] ) ) { self :: $ _loggers [ $ identifier ] = self :: $ _loggers [ self :: $ _nameMap [ $ fileName ] ] ; break ; } self :: $ _nameMap [ $ fileName ] = $ identifier ; self :: $ _loggers [ $ identifier ] = new FileLogger ( $ configuration ) ; break ; default : $ className = $ configuration -> getImplementation ( ) ; self :: $ _loggers [ $ identifier ] = new $ className ( $ configuration ) ; } return self :: $ _loggers [ $ identifier ] ; } | Creates a new logger with the help of the given configuration data . This method has no effect if another logger with the same identifier exists yet . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.