idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
13,000 | protected function getRequestBody ( ServerRequestInterface $ request ) : string { if ( $ decryptedBody = $ request -> getAttribute ( 'ncryptf-decrypted-body' , false ) ) { return $ decryptedBody ; } return $ request -> getBody ( ) -> getContents ( ) ; } | Returns the plaintext request body . |
13,001 | public function authenticate ( HTTPRequest $ request ) : HTTPRequest { $ requestAdapter = new HttpRequestAdapter ( ) ; $ responseAdapter = new HttpResponseAdapter ( ) ; $ this -> addMissingServerVariables ( $ requestAdapter ) ; $ server = $ this -> getServer ( ) ; $ psrRequest = $ requestAdapter -> toPsr7 ( $ request )... | Authenticate the request . Adds oauth fields as headers on the request . |
13,002 | protected function createServer ( ) : ResourceServer { $ accessTokenRepository = new AccessTokenRepository ( ) ; $ publicKeyPath = Environment :: getEnv ( 'OAUTH_PUBLIC_KEY_PATH' ) ; $ publicKeyPath = str_replace ( '{BASE_DIR}' , Director :: baseFolder ( ) , $ publicKeyPath ) ; return new ResourceServer ( $ accessToken... | Create a default ResourceServer . Used if one isn t provided . |
13,003 | public function setNodeBin ( $ nodeBin ) { $ this -> nodeBin = empty ( $ nodeBin ) ? null : ( string ) $ nodeBin ; return $ this ; } | Set the path to the node . js binary . |
13,004 | public static function getDatePlaceholder ( string $ format ) : string { $ format = str_replace ( 'Y' , 'YYYY' , $ format ) ; $ format = str_replace ( 'm' , 'MM' , $ format ) ; $ format = str_replace ( 'd' , 'DD' , $ format ) ; $ format = str_replace ( 'H' , 'HH' , $ format ) ; $ format = str_replace ( 'i' , 'MM' , $ f... | Get placeholder base on format |
13,005 | public static function dateFormat ( $ value , string $ type = 'date' , array $ options = [ ] ) { if ( empty ( $ value ) ) return null ; $ format = $ options [ 'format' ] ?? self :: getDateFormat ( $ type ) ; if ( is_float ( $ value ) ) { $ temp = explode ( '.' , $ value . '' ) ; $ value = date ( 'Y-m-d H:i:s' , ( int )... | Format date based on format |
13,006 | public static function niceDatetime ( $ value , array $ options = [ ] ) { if ( ! isset ( $ value ) ) return '' ; try { $ server_timezone = self :: $ options [ 'server_timezone_code' ] ?? Application :: get ( 'php.date.timezone' ) ; $ object = new DateTime ( $ value , new DateTimeZone ( $ server_timezone ) ) ; if ( empt... | Format nice datetime |
13,007 | public static function niceTimestamp ( $ value , array $ options = [ ] ) { if ( ! isset ( $ value ) ) return '' ; try { $ server_timezone = self :: $ options [ 'server_timezone_code' ] ?? Application :: get ( 'php.date.timezone' ) ; $ object = new DateTime ( $ value , new DateTimeZone ( $ server_timezone ) ) ; if ( emp... | Format nice timestamp |
13,008 | public static function now ( string $ type = 'datetime' , array $ options = [ ] ) { list ( $ msec , $ time ) = explode ( " " , microtime ( ) ) ; if ( ! empty ( $ options [ 'add_seconds' ] ) ) { $ time += $ options [ 'add_seconds' ] ; } if ( ! empty ( $ options [ 'format' ] ) ) { return self :: { $ type } ( $ time + $ m... | Current date and time |
13,009 | public static function readTime5 ( $ time ) { if ( empty ( $ time ) || $ time == 'NULL' ) return null ; if ( is_numeric ( $ time ) ) { return '00:' . $ time ; } else { $ temp = explode ( ':' , $ time ) ; return str_pad ( intval ( $ temp [ 0 ] ) , 2 , '0' , STR_PAD_LEFT ) . ':' . str_pad ( intval ( $ temp [ 1 ] ) , 2 , ... | Read 5 character time string |
13,010 | public static function getVersion ( ) { if ( empty ( self :: $ version ) ) { $ filename = Application :: get ( [ 'application' , 'path_full' ] ) . ( Application :: isDeployed ( ) ? '../../../deployed' : '../../deployed' ) ; self :: $ version = filemtime ( $ filename ) ; } return self :: $ version ; } | Get application version |
13,011 | public static function renderCss ( $ options = [ ] ) { $ result = '' ; $ list = [ ] ; $ css = Application :: get ( array ( 'layout' , 'css' ) ) ; if ( ! empty ( $ css ) ) { asort ( $ css ) ; foreach ( $ css as $ k => $ v ) { $ script = $ k . ( strpos ( $ k , '?' ) !== false ? '&' : '?' ) . self :: getVersion ( ) ; $ li... | Render css files |
13,012 | public static function addJs ( string $ js , int $ sort = 0 , array $ options = [ ] ) { $ js = str_replace ( '\\' , '/' , $ js ) ; Application :: set ( [ 'layout' , 'js' , $ js ] , $ sort ) ; if ( ! empty ( $ options ) ) { Application :: set ( [ 'layout' , 'js_options' , $ js ] , $ options ) ; } } | Add JavaScript file to the layout |
13,013 | public static function renderJs ( $ options = [ ] ) { $ result = '' ; $ list = [ ] ; $ js = Application :: get ( [ 'layout' , 'js' ] ) ; if ( ! empty ( $ js ) ) { asort ( $ js ) ; foreach ( $ js as $ k => $ v ) { $ script = $ k . ( strpos ( $ k , '?' ) !== false ? '&' : '?' ) . self :: getVersion ( ) ; $ list [ ] = $ s... | Render javascript files |
13,014 | public static function renderOnLoad ( ) { if ( ! empty ( self :: $ onload ) || ! empty ( self :: $ onload_first ) ) { return \ HTML :: script ( [ 'value' => '$(document).ready(function(){ ' . self :: $ onload_first . self :: $ onload . ' });' ] ) ; } } | Render onload js |
13,015 | public static function renderBreadcrumbs ( ) : string { if ( ! empty ( Application :: $ controller -> breadcrumbs ) ) { return \ HTML :: breadcrumbs ( Application :: $ controller -> breadcrumbs ) ; } else { return '' ; } } | Render bread crumbs |
13,016 | public static function renderAs ( $ data , string $ content_type , array $ options = [ ] ) { \ Helper \ Ob :: cleanAll ( ) ; Application :: set ( 'flag.global.__content_type' , $ content_type ) ; Application :: set ( 'flag.global.__skip_layout' , 1 ) ; header ( "Content-type: " . $ content_type ) ; if ( ! empty ( $ opt... | Render as content type non HTML output should go though this function |
13,017 | public static function includeMedia ( $ path , $ controller , $ view , $ class ) { $ valid_extensions = [ 'js' , 'css' ] ; if ( Application :: get ( 'dep.submodule.numbers.frontend.media.scss' ) ) { $ valid_extensions [ ] = 'scss' ; } $ path_fixed = str_replace ( '/' , '_' , $ path ) ; $ path_js = str_replace ( '_' . $... | Include all media files for controller |
13,018 | public function setCreatedAt ( $ time ) { if ( $ time instanceof \ DateTimeInterface ) { $ time = $ time -> format ( DATE_RFC3339 ) ; } $ this -> setValue ( 'date' , ( string ) $ time ) ; } | Set creation date and time . |
13,019 | public function setAuthor ( $ objectOrId ) { $ this -> dropCachedProperty ( 'author' ) ; if ( ! $ objectOrId instanceof Account ) { $ objectOrId = new Account ( [ 'id' => $ objectOrId ] ) ; } $ this -> setValue ( 'author' , $ objectOrId -> export ( ) ) ; } | Set Attachment author . |
13,020 | protected function cleanupObsoleteFiles ( OutputInterface $ output , $ language , $ destinationFiles ) { if ( $ this -> cleanup && ( $ files = array_diff ( $ this -> determinePresentFiles ( $ language ) , $ destinationFiles ) ) ) { $ this -> writeln ( $ output , sprintf ( 'the following obsolete files have been found a... | Cleanup anything that is obsolete now . |
13,021 | public function renderPage ( $ templateName , $ templateVars = [ ] ) { return $ this -> render ( $ templateName , array_merge ( $ templateVars , [ 'wp_head' => $ this -> wpHead ( ) , 'wp_footer' => $ this -> wpFooter ( ) , ] ) ) ; } | head + template + footer |
13,022 | public function execute ( \ Magento \ Framework \ Event \ Observer $ observer ) { $ product = $ observer -> getData ( self :: DATA_PRODUCT ) ; if ( $ product instanceof \ Magento \ Catalog \ Model \ Product ) { $ product -> setSpecialPrice ( null ) ; } } | Don t save special price in DB . We use warehouse related special prices . |
13,023 | private function detectLineBreak ( ) : void { $ sample = $ this -> stream -> read ( 10000 ) ; if ( $ this -> stream -> isSeekable ( ) ) { $ this -> stream -> rewind ( ) ; } else { $ this -> stream = new AppendStream ( [ StreamFactoryDiscovery :: find ( ) -> createStream ( $ sample ) , $ this -> stream , ] ) ; } $ sampl... | Reads a 10k sample from the stream the most occurring EOL character wins . |
13,024 | public function onAdd ( OrderItemEvent $ event ) { $ order = $ event -> getOrder ( ) ; $ item = $ event -> getItem ( ) ; $ order -> addItem ( $ item ) ; } | Item add event handler . |
13,025 | public function onRemove ( OrderItemEvent $ event ) { $ order = $ event -> getOrder ( ) ; $ item = $ event -> getItem ( ) ; $ order -> removeItem ( $ item ) ; } | Item remove event handler . |
13,026 | private function prepareEvent ( OrderItemEvent $ event ) { if ( ! $ event -> hasItem ( ) ) { if ( ! $ event -> hasSubject ( ) ) { throw new LogicException ( 'At least the item or the subject must be set.' ) ; } $ event -> setItem ( $ this -> helper -> transform ( $ event -> getSubject ( ) ) ) ; } } | Prepares the event by transforming the subject if needed . |
13,027 | public function whereGroup ( $ conditions , $ logic = 'AND' ) { $ whereGroup = $ this -> _append ( 'Where_Group' , $ conditions , $ logic ) ; if ( $ group = $ whereGroup -> __toString ( ) ) { $ this -> where ( '(' . $ group . ')' , null , $ logic ) ; } return $ this ; } | Where conditions group |
13,028 | public static function generateUrl ( $ email , $ size = null , $ default = null ) { if ( $ size == null && isset ( $ GLOBALS [ 'TL_CONFIG' ] [ 'gravatarSize' ] ) ) { $ size = $ GLOBALS [ 'TL_CONFIG' ] [ 'gravatarSize' ] ; } if ( $ default == null ) { if ( isset ( $ GLOBALS [ 'TL_CONFIG' ] [ 'gravatarDefault' ] ) ) { $ ... | generate gravatar url |
13,029 | public static function exceptionHandler ( \ Throwable $ e ) { $ code = $ e -> getCode ( ) ; if ( get_class ( $ e ) == 'Object\Error\UserException' ) { $ code = - 1 ; } self :: $ errors [ ] = [ 'errno' => $ code , 'error' => [ $ e -> getMessage ( ) ] , 'file' => $ e -> getFile ( ) , 'line' => $ e -> getLine ( ) , 'code'... | Exception handler function |
13,030 | public static function getCode ( $ file , $ line ) { if ( empty ( $ file ) ) { return '' ; } $ rows = explode ( "\n" , file_get_contents ( $ file ) ) ; $ start = ( $ line - 6 ) > 0 ? ( $ line - 6 ) : 0 ; $ end = ( $ line + 5 ) < count ( $ rows ) ? ( $ line + 5 ) : count ( $ rows ) ; $ result = [ ] ; for ( $ i = $ start... | Get code snippet |
13,031 | public static function debugBacktraceString ( $ trace = null ) { $ result = [ ] ; if ( ! \ Debug :: $ debug ) return $ result ; $ i = 1 ; if ( empty ( $ trace ) ) { $ trace = debug_backtrace ( ) ; unset ( $ trace [ 0 ] ) ; } foreach ( $ trace as $ v ) { $ stack = '#' . $ i . ' ' . ( isset ( $ v [ 'file' ] ) ? $ v [ 'fi... | Format debug trace |
13,032 | public function index ( ) : HTTPResponse { $ body = null ; $ contentType = $ this -> getRequest ( ) -> getHeader ( 'Content-Type' ) ; if ( $ contentType === 'application/json' ) { $ body = json_decode ( $ this -> getRequest ( ) -> getBody ( ) , true ) ; } else { $ body = $ this -> getRequest ( ) -> postVars ( ) ; } if ... | Handles authorisation . |
13,033 | public function setTerm ( $ term ) { if ( ! $ term instanceof Term ) { $ this -> getTerm ( ) -> setHtml ( $ term ) ; } $ this -> term = $ term ; } | Set the term |
13,034 | public function setDescription ( $ desc ) { if ( ! $ this -> description instanceof Description ) { $ this -> getDescription ( ) -> setHtml ( $ html ) ; } $ this -> description = $ desc ; } | Set the description |
13,035 | public function addKeywords ( $ keywords ) { if ( is_string ( $ keywords ) ) { $ keywords = explode ( ',' , $ keywords ) ; } foreach ( $ keywords as $ keyword ) { $ this -> addKeyword ( $ keyword ) ; } return $ this ; } | Add many of the keywords |
13,036 | public function assemble ( ) { $ keysTag = new Tag ( 'meta' ) ; $ keysTag -> setClosed ( ) ; $ keysTag -> name = 'keywords' ; $ keysTag -> content = $ this -> getKeywords ( ) ; return $ keysTag -> render ( ) ; } | Assemble the keywords tag |
13,037 | public function serveAction ( string $ path ) : Response { $ media_repo = $ this -> em -> getRepository ( Media :: class ) ; $ path_parts = explode ( '/' , $ path ) ; $ filename = array_pop ( $ path_parts ) ; $ filename_parts = explode ( '_' , $ filename ) ; if ( count ( $ filename_parts ) > 1 ) { $ media = $ media_rep... | Reverses a media path into a media object and sends as download . |
13,038 | public function getTopologyId ( ) { if ( $ this -> backendId === null ) { $ this -> backendId = self :: createId ( ) ; } return $ this -> backendId ; } | Get the unique decorator ID |
13,039 | protected function ensureParameter ( $ name ) { if ( ! isset ( $ this -> $ name ) ) { throw new \ InvalidArgumentException ( get_class ( $ this ) . ' is missing parameter: ' . $ name ) ; } return $ this -> $ name ; } | Ensure a parameter exists and return its value . |
13,040 | protected function post ( $ command , $ params = null , $ postcontenttype = 'application/json' ) { return $ this -> transport -> post ( $ command , $ params , $ postcontenttype ) ; } | Post a command to the API . |
13,041 | protected function put ( $ command , $ params = null , $ putcontenttype = 'application/json' ) { return $ this -> transport -> put ( $ command , $ params , $ putcontenttype ) ; } | Put some data to the API . |
13,042 | public function setAssetsPath ( $ path ) { $ path = realpath ( rtrim ( $ path , DIRECTORY_SEPARATOR ) ) ; if ( $ path === false || ! is_readable ( $ path ) ) { throw new InvalidPath ( 'Path to the assets must exists and be readable' ) ; } $ this -> assetsPath = $ path ; } | Set the assets path |
13,043 | public function addInfo ( Infoset $ infoset ) { if ( $ infoset -> getLevel ( ) > Infoset :: LEVEL_ALERT ) { $ this -> info [ ] = $ infoset ; } else { $ this -> info -> unshift ( $ infoset ) ; } } | Add the information set |
13,044 | protected function createTab ( Infoset $ info ) { $ title = $ this -> specialCharsHandle ( $ info -> getTitle ( ) ) ; $ title = $ this -> bbCodesHandle ( $ title ) ; $ infoTag = new Tag ( 'span' , $ title , 'debug-info-holder' ) ; $ tabElement = new ListElement ( $ infoTag -> render ( ) ) ; $ tabElement -> addClass ( '... | Create the tab element |
13,045 | protected function handleIcon ( Infoset $ info , Tag $ tabElement ) { switch ( $ info -> getIconType ( ) ) { case Infoset :: ICON_ASSET : $ icon = Icons :: getIcon ( $ info -> getIconSource ( ) ) ; $ tabElement -> addClass ( 'hasicon' ) ; $ tabElement -> addStyle ( 'background-image' , "url($icon)" ) ; return ; case In... | Handle the icon |
13,046 | protected function createPanel ( Infoset $ info ) { $ content = $ this -> createContent ( $ info ) ; $ titleValue = $ info -> getName ( ) . ' :: ' . $ this -> stripBbCodes ( $ info -> getTitle ( ) ) ; $ titleValue = $ this -> specialCharsHandle ( $ titleValue ) ; $ title = new Tag ( 'h4' , $ titleValue , 'debug-bar-wra... | Create the panel |
13,047 | protected function createDump ( Infoset $ info ) { $ content = '' ; foreach ( $ info as $ part ) { $ content .= Dump :: getDump ( $ part ) ; } return $ content ; } | Create the dump of the exception |
13,048 | protected function createTopology ( Infoset $ into ) { $ topology = $ this -> getTagsLocator ( ) -> get ( 'topology' ) ; $ html = '' ; foreach ( $ into as $ descriptor ) { $ html .= $ topology -> render ( $ descriptor ) ; } return $ html ; } | Create the topology |
13,049 | protected function getAsset ( $ name ) { $ path = $ this -> assetsPath . DIRECTORY_SEPARATOR . $ name ; $ asset = file_get_contents ( $ path ) ; if ( $ asset === false ) { throw new InvalidPath ( 'Unable to get asset "' . $ name . '" by path "' . $ path . '"' ) ; } return $ asset ; } | Get the asset |
13,050 | protected function getTagsLocator ( ) { if ( $ this -> tagsLocator === null ) { $ di = new Container ( ) ; $ di -> keyword = function ( ) { return new Tag ( 'span' , null , 'content-keyword' ) ; } ; $ di -> alert = function ( ) { return new Tag ( 'span' , null , 'content-alert' ) ; } ; $ di -> warning = function ( ) { ... | Get the tags instances locator |
13,051 | final public function add_action ( $ tag , $ function_to_add , $ priority = 10 , $ accepted_args = 1 ) { $ this -> add_filter ( $ tag , $ function_to_add , $ priority , $ accepted_args ) ; } | Syntactic sugar around add_filter for grouping hooks together based on type . |
13,052 | final public function remove_hook ( $ tag , $ function_to_remove , $ priority = 10 ) { if ( \ is_string ( $ function_to_remove ) && \ is_callable ( [ $ this , $ function_to_remove ] ) ) { $ function_to_remove = [ $ this , $ function_to_remove ] ; } if ( \ is_array ( $ tag ) ) { foreach ( $ tag as $ hook ) { remove_filt... | Removes a the given callback from a specific hook . |
13,053 | final public function add_filter ( $ tag , $ function_to_add , $ priority = 10 , $ accepted_args = 1 ) { $ callback = $ function_to_add ; if ( \ is_string ( $ function_to_add ) && \ is_callable ( [ $ this , $ function_to_add ] ) ) { $ callback = [ $ this , $ function_to_add ] ; } if ( ! \ is_array ( $ tag ) ) { $ tag =... | A wrapper for add_filter . Multiple hooks can be passed as an array to apply the callback to multiple filters within the same method call . |
13,054 | final private function get_argument_count ( $ callback , $ accepted_args = 1 ) { try { if ( \ is_string ( $ callback ) && \ is_callable ( [ $ this , $ callback ] ) ) { $ reflector = new ReflectionMethod ( $ this , $ callback ) ; return $ reflector -> getNumberOfParameters ( ) ; } if ( \ is_object ( $ callback ) && $ ca... | Use reflection to count the amount of arguments a hook callback expects . |
13,055 | public function getDisplayNameAttribute ( ) { if ( ! is_null ( $ this -> details -> display_name ) ) { return $ this -> details -> display_name ; } if ( ! is_null ( $ this -> details -> full_name ) ) { return $ this -> details -> full_name ; } return $ this -> email ; } | Get the most logical display name for the user . |
13,056 | public function trackTime ( $ column , $ time = null ) { $ search = [ 'user_id' => $ this -> id , ] ; $ attributes = [ $ column => setTime ( 'now' ) , ] ; Timestamp :: updateOrCreate ( $ search , $ attributes ) ; } | Track when something important happened . |
13,057 | public static function parse_host_parts ( $ host ) { if ( false === ( $ host = static :: parse_host ( $ host ) ) ) { return false ; } $ out = static :: HOST_PARTS ; if ( \ filter_var ( $ host , \ FILTER_VALIDATE_IP ) ) { $ out [ 'host' ] = $ host ; $ out [ 'domain' ] = $ host ; return $ out ; } $ suffixes = data :: SUF... | Parse Host Parts |
13,058 | public function strip_www ( ) { if ( ! $ this -> is_valid ( ) || \ is_null ( $ this -> subdomain ) ) { return false ; } if ( ( 'www' === $ this -> subdomain ) || ( 0 === \ strpos ( $ this -> subdomain , 'www.' ) ) ) { $ this -> subdomain = \ preg_replace ( '/^www\.?/u' , '' , $ this -> subdomain ) ; if ( ! \ strlen ( $... | Strip Leading WWW |
13,059 | public function when ( $ template , callable $ callback ) { if ( \ is_array ( $ template ) ) { foreach ( $ template as $ current ) { static :: $ composers [ $ current ] [ ] = $ callback ; } return ; } static :: $ composers [ $ template ] [ ] = $ callback ; } | Adds data to specific templates only . |
13,060 | public function add_shared_data ( $ key , $ value = null ) { if ( \ is_array ( $ key ) ) { static :: $ global_data = \ array_merge ( static :: $ global_data , $ key ) ; return ; } static :: $ global_data [ $ key ] = $ value ; } | Adds shared data which is passed to all templates . |
13,061 | public function save ( string $ filename , bool $ debug = false ) : bool { $ yaml = false ; try { $ fileObject = ! $ debug ? new \ SplFileObject ( $ filename , 'w' ) : new \ SplTempFileObject ( ) ; $ yaml = Export :: save ( $ fileObject , $ this -> show ( ) ) ; } catch ( YamlException $ e ) { ! $ this -> _strict ? : di... | Save Yaml to file |
13,062 | public function show ( ) : string { $ yaml = false ; try { $ yaml = Export :: show ( $ this -> get ( ) ) ; } catch ( YamlException $ e ) { ! $ this -> _strict ? : die ( ) ; } return $ yaml ; } | Return ready for usage generated Yaml |
13,063 | public function read ( string $ filename = null , string $ data = null ) : Interfaces \ Yaml { try { $ yaml = ! empty ( $ data ) ? Import :: fromData ( $ data ) : Import :: fromFile ( $ filename ) ; $ this -> set ( $ yaml ) ; } catch ( YamlException $ e ) { ! $ this -> _strict ? : die ( ) ; } return $ this ; } | Read Yaml from file |
13,064 | private function parse ( array $ parameters , array $ schema , string $ parent_key = null ) { array_map ( function ( $ key , $ value ) use ( $ schema , $ parent_key ) { if ( array_key_exists ( $ key , $ schema ) ) { if ( is_array ( $ value ) && is_array ( $ schema [ $ key ] ) ) { $ this -> parse ( $ value , $ schema [ ... | Compare current parameters with required schema |
13,065 | public function validate ( array $ schema , bool $ strong = false ) : Interfaces \ Yaml { $ valid = new Validation ( ) ; $ valid -> compare ( $ schema , $ this -> _parameters ) ; $ parameters = $ this -> get ( ) ; $ this -> parse ( $ parameters , $ schema ) ; return $ this ; } | Validate Yaml before saving |
13,066 | public function compare ( array $ schema , array $ array ) { try { ArrayException :: isAssoc ( $ schema ) ; } catch ( ArrayException $ e ) { ! $ this -> _strict ? : die ( ) ; } $ this -> _schema = $ schema ; } | Compare array with array s schema |
13,067 | public static function decodeQueryString ( $ source , $ rfc = self :: RFC_3986 ) { $ ret = [ ] ; if ( $ source !== '' ) { $ decode = self :: getQueryStringDecoder ( $ rfc ) ; $ queryPairs = explode ( '&' , $ source ) ; foreach ( $ queryPairs as $ pair ) { $ parts = explode ( '=' , $ pair , 2 ) ; $ key = $ decode ( $ pa... | Parse a url encoded string into an array of values |
13,068 | public static function encodeQueryString ( array $ query , $ rfc = self :: RFC_3986 ) { $ ret = [ ] ; $ encode = self :: getQueryStringEncoder ( $ rfc ) ; foreach ( $ query as $ name => $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ v ) { $ ret [ ] = $ name . '=' . $ encode ( $ v ) ; } } else { $ ret ... | Create a url encoded string |
13,069 | public static function createFromString ( $ url ) { if ( ! is_string ( $ url ) ) { throw new \ InvalidArgumentException ( "invalid value provided for 'url'; expecting a string" ) ; } $ ret = new Url ; if ( ( $ url = trim ( $ url ) ) === '' ) { return $ ret ; } if ( ( $ url = parse_url ( $ url ) ) === false ) { throw ne... | Parse a url string into an object |
13,070 | public static function createFromArray ( array $ arr ) { $ ret = new Url ; $ keys = [ 'scheme' , 'user' , 'pass' , 'host' , 'port' , 'path' , 'query' , 'fragment' ] ; foreach ( $ keys as $ key ) { if ( array_key_exists ( $ key , $ arr ) ) { $ fn = 'set' . ucfirst ( $ key ) ; call_user_func ( [ $ ret , $ fn ] , $ arr [ ... | Create a url instance given an array of url properties and values |
13,071 | public function setPort ( $ port = null ) { if ( is_null ( $ port ) || is_int ( $ port ) ) { $ this -> port = $ port ; } else if ( is_string ( $ port ) && preg_match ( '/^[0-9]+$/' , $ port ) !== 0 ) { $ this -> port = ( int ) $ port ; } else { throw new \ InvalidArgumentException ( "invalid value provided for 'port'; ... | Set the port portion of the url |
13,072 | public function setPath ( $ path = null ) { if ( is_string ( $ path ) ) { if ( $ path { 0 } !== '/' ) { $ path = "/$path" ; } } else if ( ! is_null ( $ path ) ) { throw new \ InvalidArgumentException ( "invalid value provided for 'path'; " . " expecting a string or null" ) ; } $ this -> path = $ path ; } | Set the path portion of the url |
13,073 | public function setQuery ( $ query = null ) { $ this -> query = [ ] ; return ( $ query === null ) ? $ this : $ this -> addQueryData ( $ query ) ; } | Set the query data |
13,074 | public function addQueryData ( $ data ) { if ( is_string ( $ data ) ) { $ data = self :: decodeQueryString ( $ data ) ; } else if ( is_object ( $ data ) ) { $ data = ( array ) $ data ; } else if ( ! is_array ( $ data ) ) { throw new \ InvalidArgumentException ( "invalid value provided for 'query'; " . "expecting a stri... | Add more data to the query |
13,075 | public function merge ( $ to ) { if ( is_array ( $ to ) ) { $ to = Url :: createFromArray ( $ to ) ; } else if ( is_string ( $ to ) ) { $ to = self :: createFromString ( $ to ) ; } else if ( ( $ to instanceof Url ) === false ) { throw new \ InvalidArgumentException ( "invalid value provided for 'to'; expecting a url as... | Update missing properties in the url with those of another url |
13,076 | protected function log ( $ level , $ mesg , $ context = array ( ) ) { if ( $ logger = $ this -> getLogger ( ) ) { $ context = array_merge ( $ this -> getDefaultContext ( ) , $ context ) ; $ logger -> log ( $ level , $ mesg , $ context ) ; } } | log Log a message to the log handler if set . |
13,077 | public static function getTypeFromExtension ( string $ ext , string $ default = "application/octet-stream" ) : string { $ ext = strtolower ( $ ext ) ; return self :: $ extensions [ $ ext ] ?? $ default ; } | Get a content type from a file extension |
13,078 | public static function getTypeFromFile ( string $ path ) : string { if ( ! is_file ( $ path ) || ! is_readable ( $ path ) ) { throw new \ InvalidArgumentException ( "invalid value provided for 'path'; " . "expecting an absolute path to a readable file" ) ; } $ finfo = new \ finfo ( FILEINFO_MIME_TYPE ) ; $ type = @ $ f... | Get a content type from file contents |
13,079 | public static function getExtension ( string $ type , string $ default = "unknown" ) : string { return array_key_exists ( $ type , self :: $ types ) ? self :: $ types [ $ type ] : $ default ; } | Get a file extension from a content type |
13,080 | final public static function getInstance ( ) { $ cls = static :: class ; if ( isset ( static :: $ instances [ $ cls ] ) ) { return static :: $ instances [ $ cls ] ; } if ( $ cls === self :: class ) { throw new \ LogicException ( "$cls cannot be used directly. Please subclass in your project." ) ; } return static :: $ i... | Return the singleton instance for the called class . |
13,081 | protected static function create ( ) { $ config = new static ( ) ; $ config -> config = ( new ConfigFactory ( ) ) -> create ( $ config -> getProjectPath ( ) , $ config -> CONFIG_FILE ) ; return $ config ; } | Create an instance of Config . Override if you need to change how ConfigBags are created . |
13,082 | protected function getProjectPath ( ) : string { if ( ! $ this -> projectPath ) { $ cls = new \ ReflectionClass ( static :: class ) ; $ baseDir = dirname ( $ cls -> getFileName ( ) ) ; $ this -> projectPath = Path :: makeAbsolute ( $ this -> PROJECT_DIR , $ baseDir ) ; } return $ this -> projectPath ; } | Return the absolute project root path . |
13,083 | public function addItem ( $ item ) { if ( ! $ this -> getItems ( ) ) { return $ this -> setItems ( array ( $ item ) ) ; } else { return $ this -> setItems ( array_merge ( $ this -> getItems ( ) , array ( $ item ) ) ) ; } } | Append Items to the list . |
13,084 | public function getConfigDir ( ) { if ( null === $ this -> configDir ) { $ this -> configDir = $ this -> getRootDir ( ) . '/app/config/' ; } return ( $ this -> configDir ) ; } | getConfigDir Get the global app config directory |
13,085 | public function getRootDir ( ) { if ( null === $ this -> rootDir ) { $ reflector = new \ ReflectionClass ( $ this ) ; $ rootDir = dirname ( $ reflector -> getFileName ( ) ) ; $ this -> rootDir = str_replace ( 'vendor/james481/micro-cms/src/MicroCMS/Kernel' , '' , $ rootDir ) ; } return ( $ this -> rootDir ) ; } | getRootDir Gets the application root directory |
13,086 | public function handle ( Request $ request ) { if ( ! $ this -> booted ) { $ this -> bootstrap ( ) ; } $ this -> request = $ request ; try { $ req_info = $ this -> router -> matchRequest ( $ request ) ; $ resolver = new Resolver ( ) ; $ controller = $ resolver -> resolveController ( $ req_info [ '_controller' ] ) ; if ... | handle The main application handler . |
13,087 | protected function buildContainer ( ) { $ builder = new ContainerBuilder ( $ this -> getContainerBuilder ( ) ) ; $ config_dirs = array ( $ this -> getSystemConfigDir ( ) , $ this -> getConfigDir ( ) ) ; $ config_locator = new FileLocator ( $ config_dirs ) ; $ builder -> setConfigLocator ( $ config_locator ) ; $ contain... | buildContainer Build the MicroCMS specific DI container |
13,088 | protected function buildRouter ( ) { $ builder = new RouterBuilder ( $ this -> container -> get ( 'template_resolver' ) , $ this -> container -> get ( 'kernel.config_locator' ) , $ this -> container -> getParameter ( 'kernel.env' ) ) ; if ( $ this -> container -> has ( 'logger' ) ) { $ builder -> setLogger ( $ this -> ... | buildRouter Build the router for matching requests to controllers . |
13,089 | protected function getSystemConfigDir ( ) { if ( null === $ this -> systemConfigDir ) { $ reflector = new \ ReflectionClass ( $ this ) ; $ rootDir = dirname ( $ reflector -> getFileName ( ) ) ; $ this -> systemConfigDir = $ rootDir . '/Resources/config/' ; } return ( $ this -> systemConfigDir ) ; } | getSystemConfigDir Get the system configuration directory . |
13,090 | public static function key ( string $ key , array $ params = [ ] ) : string { $ key = md5 ( serialize ( $ key ) ) ; if ( count ( $ params ) > 0 ) { $ key .= '-' . md5 ( serialize ( $ params ) ) ; } return $ key ; } | Generate key based on input key and parameters . Used in more sophisticated keys . |
13,091 | public static function expiration ( string $ key , ? string $ storage = 'global' ) : ? int { if ( ! self :: has ( $ key ) ) { return null ; } $ fileKey = self :: key ( $ key ) ; $ content = null ; if ( file_exists ( self :: $ path . '/' . $ storage . '/' . $ fileKey ) ) { $ content = file_get_contents ( self :: $ path ... | Get expiration from key . |
13,092 | public static function put ( string $ key , $ value , string $ storage = 'global' ) : void { self :: initialize ( $ storage ) ; $ expiration = time ( ) + intval ( self :: $ seconds ) ; $ value = $ expiration . self :: $ marker . serialize ( $ value ) ; $ fileKey = self :: key ( $ key ) ; @ file_put_contents ( self :: $... | Put cache . |
13,093 | public static function has ( string $ key , string $ storage = 'global' ) : bool { $ fileKey = self :: key ( $ key ) ; return file_exists ( self :: $ path . '/' . $ storage . '/' . $ fileKey ) ; } | Has key . |
13,094 | public static function forget ( string $ key , string $ storage = 'global' ) : void { $ fileKey = self :: key ( $ key ) ; if ( self :: has ( $ key ) ) { @ unlink ( self :: $ path . '/' . $ storage . '/' . $ fileKey ) ; } } | Forget key . |
13,095 | public static function flush ( string $ storage = 'global' ) : void { $ filenames = scandir ( self :: $ path . '/' . $ storage ) ; if ( count ( $ filenames ) > 0 ) { foreach ( $ filenames as $ filename ) { if ( substr ( $ filename , 0 , 1 ) === '.' ) { continue ; } @ unlink ( self :: $ path . '/' . $ storage . '/' . $ ... | Flush storage . |
13,096 | public static function get ( $ name ) { if ( isset ( self :: $ _cached_settings [ $ name ] ) ) { return self :: $ _cached_settings [ $ name ] ; } return NULL ; } | Get one setting value by name |
13,097 | public function init ( $ no_cache = false ) { $ this -> bootCacher ( ) ; if ( self :: $ _cached_settings && is_array ( self :: $ _cached_settings ) && ! $ no_cache ) { return self :: $ _cached_settings ; } if ( $ no_cache ) { self :: $ _cached_settings = [ ] ; } else { self :: $ _cached_settings = Cacher :: getInstance... | Init all settings |
13,098 | private function bootCacher ( ) { $ cacher = Cacher :: getInstance ( ) ; if ( MemcachedCache :: itWorks ( ) ) { $ cacher -> setDefaultCacher ( 'MemcachedCache' ) ; } elseif ( MemcacheCache :: itWorks ( ) ) { $ cacher -> setDefaultCacher ( 'MemcacheCache' ) ; } elseif ( RedisCache :: itWorks ( ) ) { $ cacher -> setDefau... | Set current default cache class |
13,099 | public function set ( $ name , $ value = '' ) { if ( ! $ name ) { return false ; } $ setting = SettingEntityRepository :: findOneEntityByCriteria ( [ 'name' => $ name ] ) ; if ( ! $ setting ) { $ setting = new SettingEntity ( ) ; $ setting -> setName ( $ name ) ; } $ setting -> setValue ( $ value ) ; $ setting -> save ... | Set new setting or update existing |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.