idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
16,200
public function setParam ( $ name , $ value ) { switch ( $ name ) { case 'processor' : $ this -> setProcessor ( $ value ) ; break ; case 'message' : $ this -> setMessage ( $ value ) ; break ; case 'result' : $ this -> setResult ( $ value ) ; break ; default : parent :: setParam ( $ name , $ value ) ; break ; } return $ this ; }
Set an individual event parameter
16,201
public function build ( ) { switch ( $ this -> provider ) { default : case Provider :: RACKSPACE : $ class = __NAMESPACE__ . '\\RackspaceFactory' ; break ; case Provider :: OPENSTACK : $ class = __NAMESPACE__ . '\\OpenStackFactory' ; break ; } return $ this -> buildFactory ( $ class ) -> buildClient ( ) ; }
Will initialize the build process ; first the factory is built then the factory builds the client
16,202
protected function buildFactory ( $ factoryClass ) { $ factory = $ factoryClass :: newInstance ( ) ; $ factory -> setConfig ( $ this -> config ) ; $ factory -> validateConfig ( ) ; return $ factory ; }
Build the concrete factory class responsible for creating a concrete client object
16,203
public function getStartDate ( ) { $ topic = BaseManager :: build ( 'FelixOnline\Core\Topic' , 'article_topic' , 'topic' ) -> filter ( 'topic = "%s"' , array ( $ this -> getSlug ( ) ) ) ; $ article = BaseManager :: build ( 'FelixOnline\Core\Article' , 'article' , 'id' ) -> join ( $ topic , 'LEFT' , 'id' , 'article' ) -> filter ( 'published > 0' ) -> order ( 'published' , 'ASC' ) -> limit ( 0 , 1 ) -> values ( ) ; if ( ! $ article ) { throw new \ FelixOnline \ Exceptions \ InternalException ( 'No articles posted in this topic' ) ; } return ( $ article [ 0 ] -> getPublished ( ) ) ; }
Get date that the first article was posted
16,204
public static function setEnvironment ( $ env = self :: ENV_STAGE ) { $ prefix = '' ; if ( $ env === self :: ENV_STAGE ) { $ prefix = 's' ; } static :: $ apiHost = $ prefix . 'api.fortifi.io' ; }
Set the environment to connect to
16,205
public function trigger ( Payload $ payload ) { if ( ! $ this -> command ) { return $ this -> targetState ( ) ; } return call_user_func ( $ this -> command , $ payload ) ? $ this -> targetState ( ) : $ this -> errorState ( ) ; }
Triggers event and return next state name or null if there is no state change
16,206
public function parse ( ) { $ data = file_get_contents ( "http://api.openweathermap.org/data/2.5/weather?zip=420000,ru&units=metric" ) ; $ this -> record -> formatted = str_replace ( "{weather}" , $ data , $ this -> record -> formatted ) ; return $ this -> record ; }
Replace macros with useful data
16,207
public function addComment ( $ orderIncrementId , $ status , $ comment = null , $ notify = null ) { return $ this -> __createAction ( 'salesOrderAddComment' , func_get_args ( ) ) ; }
Allows you to add a new comment to the order .
16,208
public static function getRaw ( $ name ) { $ value = null ; $ rawCookies = ! empty ( $ _SERVER [ 'HTTP_COOKIE' ] ) ? explode ( '; ' , $ _SERVER [ 'HTTP_COOKIE' ] ) : array ( ) ; foreach ( $ rawCookies as $ kv ) { $ pair = explode ( '=' , $ kv , 2 ) ; $ k = array_shift ( $ pair ) ; $ v = array_shift ( $ pair ) ; $ k = str_replace ( ' ' , '_' , urldecode ( $ k ) ) ; if ( $ k == $ name ) { $ value = urldecode ( $ v ) ; break ; } } return $ value ; }
Returns the coocie value that s received in the header
16,209
protected static function cookieParams ( $ args = array ( ) ) { $ params = array ( ) ; if ( count ( $ args ) == 1 ) { if ( is_array ( $ args [ 0 ] ) ) { $ params = $ args [ 0 ] ; } else { $ params [ 'value' ] = $ args [ 0 ] ; } } elseif ( count ( $ args ) == 2 ) { if ( is_string ( $ args [ 1 ] ) ) { $ params [ 'name' ] = $ args [ 1 ] ; } else { $ params = $ args [ 1 ] ; } $ params [ 'value' ] = $ args [ 0 ] ; } $ domainRegex = '/([^.]+\.[a-z]{2,})(:\d{1,4})?$/i' ; $ paramsDefault = array ( 'value' => '' , 'domain' => preg_match ( $ domainRegex , $ _SERVER [ 'HTTP_HOST' ] , $ matches ) ? '.' . $ matches [ 1 ] : '' , ) ; $ params = array_merge ( $ paramsDefault , self :: $ cfgStatic , $ params ) ; if ( isset ( $ params [ 'lifetime' ] ) ) { $ params [ 'expiry' ] = time ( ) + $ params [ 'lifetime' ] ; } elseif ( $ params [ 'expiry' ] < time ( ) && $ params [ 'expiry' ] != 0 ) { $ params [ 'expiry' ] += time ( ) ; } return $ params ; }
return cookie parameters
16,210
static public function getType ( $ strType ) { $ arrReservere = array ( 'array' => 'ArrayObject' , 'bool' => 'BooleanObject' , 'boolean' => 'BooleanObject' , 'datetime' => 'DateTimeObject' , 'dictionary' => 'DictionaryObject' , 'enum' => 'EnumObject' , 'id' => 'IdObject' , 'int' => 'IntObject' , 'float' => 'FloatObject' , 'string' => 'StringObject' , 'resource' => 'ResourceObject' , 'object' => 'ObjectObject' , 'objectarray' => 'ObjectArrayObject' , 'number' => 'NumberObject' , 'numeric' => 'NumberObject' , 'fixeddictionary' => 'FixedDictionaryObject' ) ; if ( array_key_exists ( strtolower ( $ strType ) , $ arrReservere ) ) { $ strType = $ arrReservere [ strtolower ( $ strType ) ] ; } $ strType = 'Frozensheep\\Synthesize\\Type\\' . ucfirst ( $ strType ) ; return $ strType ; }
Get Type Method
16,211
private function setViewService ( Di $ di , Config $ config , $ moduleName ) { $ viewsDir = $ config [ 'view' ] [ $ moduleName ] ; $ volt = $ this -> setVoltOptions ( $ config , $ moduleName ) ; $ options = [ 'di' => $ di , 'views_dir' => $ viewsDir , 'volt' => $ volt ] ; $ di -> set ( 'view' , new View ( $ options ) , true ) ; return $ this ; }
Set service view for application when module start
16,212
private function setUrlService ( Di $ di , Config $ config , $ name ) { $ base = $ static = '/' ; if ( isset ( $ config [ 'url' ] ) ) { $ default = isset ( $ config [ 'url' ] [ 'default' ] ) ? $ config [ 'url' ] [ 'default' ] : '/' ; if ( isset ( $ config [ 'url' ] [ $ name ] ) ) { $ base = isset ( $ config [ 'url' ] [ $ name ] [ 'uri' ] ) ? $ config [ 'url' ] [ $ name ] [ 'uri' ] : $ default ; $ static = isset ( $ config [ 'url' ] [ $ name ] [ 'static' ] ) ? $ config [ 'url' ] [ $ name ] [ 'static' ] : $ default ; } } $ url = new UrlService ( ) ; $ url -> setBaseUri ( $ base ) ; $ url -> setStaticBaseUri ( $ static ) ; $ di -> set ( 'url' , $ url , true ) ; return $ this ; }
Set url service when module start
16,213
public function check_dir ( $ need_not_empty = true ) { $ ok = false ; if ( is_dir ( $ this -> _dir_path ) && is_readable ( $ this -> _dir_path ) ) { $ ok = true ; if ( $ need_not_empty ) { $ ok = ( count ( scandir ( $ this -> _dir_path ) ) > 0 ) ? true : false ; } } return $ ok ; }
Verifie la validite du repertoire .
16,214
public function get_path_files ( ) { $ path_files = array ( ) ; $ tmp_contents_dir = scandir ( $ this -> _dir_path ) ; foreach ( $ tmp_contents_dir as $ tmp_content_dir ) { if ( is_file ( $ this -> _dir_path . $ tmp_content_dir ) ) { $ service_name = strtolower ( preg_replace ( '/\\.[^.\\s]{3,4}$/' , '' , $ tmp_content_dir ) ) ; $ path_files [ $ service_name ] = $ tmp_content_dir ; } } return $ path_files ; }
Donne le chemin de tout les fichiers contenus dans le repertoire
16,215
protected function _setColumnNumber ( $ columnNumber ) { if ( $ columnNumber !== null ) { try { $ columnNumber = $ this -> _normalizeInt ( $ columnNumber ) ; } catch ( RootException $ e ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid column number' ) , null , $ e , $ columnNumber ) ; } if ( $ columnNumber < 1 ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Column number must be positive' ) , null , null , $ columnNumber ) ; } } $ this -> columnNumber = $ columnNumber ; }
Assigns a column number to this instance .
16,216
public function wizardAction ( ) { $ this -> writeln ( 'DB wizard for a profile' ) ; $ profileName = $ this -> ask ( 'Enter the <underline>profile name</underline> to edit' , 'default' ) ; $ fields = $ this -> askArray ( array ( 'name' => array ( 'DB name' , ) , 'user' => array ( 'DB user' , 'root' , ) , 'pass' => array ( 'DB password' , 'root' , ) , 'host' => array ( 'DB host' , '127.0.0.1' , ) , ) ) ; if ( $ this -> confirm ( 'Write to file' , true ) ) { $ config = DC :: getDatabaseConfig ( ) ; foreach ( $ fields as $ field => $ value ) { $ config -> set ( 'profiles/' . $ profileName . '/' . $ field , $ value ) ; } $ config -> save ( ) ; $ this -> notify ( ConfigService :: getConfigsPath ( ) . 'database.yml' , 'saved' ) ; } else { $ this -> writeln ( 'exiting.' ) ; } }
Using for generating profile for database
16,217
public function updateAllAction ( ) { QC :: executeSQL ( 'SET FOREIGN_KEY_CHECKS = 0' ) ; ModelOperator :: getInstance ( DC :: getEnvironment ( ) -> getUserClassesRoot ( ) . 'db/' ) -> updateDBForAllModels ( ) ; ModelOperator :: getInstance ( ) -> generateAllModelClasses ( ) ; $ this -> writeln ( 'DB updated' ) ; }
Update database and models
16,218
public function createDbAction ( ) { $ config = DC :: getDatabaseConfig ( 'profiles/default' ) ; DatabaseService :: configProfile ( array ( 'user' => $ config [ 'user' ] , 'pass' => $ config [ 'pass' ] , ) ) ; DBOperator :: getInstance ( ) -> createDB ( $ config [ 'name' ] ) ; $ this -> notify ( $ config [ 'name' ] , '+Database created:' ) ; }
Created database for profile default
16,219
public function addChild ( Node $ child ) { $ this -> children [ ] = $ child ; $ child -> parent = $ this ; $ child -> properties [ 'parent' ] = $ this -> getId ( ) ; }
Adds the given node to this node s children
16,220
private function getSibling ( $ offset ) { $ siblingsAndSelf = $ this -> parent -> getChildren ( ) ; $ pos = array_search ( $ this , $ siblingsAndSelf ) ; if ( isset ( $ siblingsAndSelf [ $ pos + $ offset ] ) ) { return $ siblingsAndSelf [ $ pos + $ offset ] ; } return null ; }
Returns the sibling with the given offset from this node or NULL if there is no such sibling
16,221
public function getSiblings ( $ includeSelf = false ) { $ siblings = array ( ) ; foreach ( $ this -> parent -> getChildren ( ) as $ child ) { if ( $ includeSelf || $ child -> getId ( ) != $ this -> getId ( ) ) { $ siblings [ ] = $ child ; } } return $ siblings ; }
Returns siblings of the node optionally including the node itself .
16,222
public function get ( $ name ) { $ lowerName = strtolower ( $ name ) ; if ( isset ( $ this -> properties [ $ lowerName ] ) ) { return $ this -> properties [ $ lowerName ] ; } throw new \ InvalidArgumentException ( "Undefined property: $name (Node ID: " . $ this -> properties [ 'id' ] . ')' ) ; }
Returns a single node property by its name .
16,223
public function createNew ( string $ name , bool $ production ) : array { return $ this -> sendPost ( sprintf ( '/companies/%s/credentials' , $ this -> companySlug ) , [ ] , [ 'name' => $ name , 'production' => $ production ] ) ; }
Creates a new credential for the given company .
16,224
public function listen ( int $ port = 119 , string $ address = self :: DEFAULT_ADDRESS , array $ options = [ ] ) { $ server = $ this -> factory -> create ( $ address , $ port , $ options ) ; $ this -> servers [ ] = $ server ; $ coroutine = new Coroutine ( $ this -> accept ( $ server ) ) ; $ coroutine -> done ( ) ; }
Starts the server and begins listening for connections .
16,225
public function getHandler ( string $ handler ) : Handler { if ( ! isset ( $ this -> handlers [ $ handler ] ) ) { if ( ! class_exists ( $ handler ) || ! class_implements ( $ handler , Handler :: class ) ) { throw new \ RuntimeException ( "No handler found for '$handler'." ) ; } $ instance = new $ handler ( ) ; $ this -> handlers [ $ handler ] = $ instance ; } else { $ instance = $ this -> handlers [ $ handler ] ; } return $ instance ; }
Gets a command handler instance .
16,226
private function accept ( SocketServer $ server ) : Generator { yield from log ( ) -> log ( Log :: INFO , 'NNTP server listening on %s:%d' , $ server -> getAddress ( ) , $ server -> getPort ( ) ) ; while ( $ server -> isOpen ( ) ) { $ socket = yield from $ server -> accept ( ) ; $ coroutine = new Coroutine ( $ this -> handleClient ( $ socket ) ) ; $ coroutine -> done ( ) ; } }
Accepts incoming connections as they are made .
16,227
public static function create ( array $ data ) : Location { $ location = new Location ( ) ; parent :: fill ( $ data , $ location ) ; return $ location ; }
Creates a location object with the given data
16,228
protected function createId ( $ id ) { if ( is_null ( $ id ) ) { return md5 ( join ( '_' , [ $ this -> config [ 'shortcode' ] , $ this -> mobile , time ( ) , ] ) ) ; } return $ id ; }
Create a message id .
16,229
static public function getHeaders ( $ url ) { $ ch = curl_init ( $ url ) ; curl_setopt ( $ ch , CURLOPT_NOBODY , true ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , false ) ; curl_setopt ( $ ch , CURLOPT_HEADER , false ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ ch , CURLOPT_MAXREDIRS , 3 ) ; curl_exec ( $ ch ) ; $ headers = curl_getinfo ( $ ch ) ; curl_close ( $ ch ) ; return $ headers ; }
Get Headers function
16,230
public static function get ( $ var , $ key , $ default = null ) { if ( $ key === null ) return $ var ; elseif ( isset ( $ var -> $ key ) ) return $ var -> $ key ; elseif ( isset ( $ var [ $ key ] ) ) return $ var [ $ key ] ; else return $ default ; }
Return value of the specified key from an array or object or a default if the key isn t set .
16,231
public static function pluck ( $ vars , $ field , $ preserve_keys = true ) { $ values = [ ] ; foreach ( $ vars as $ k => $ v ) { $ values [ $ k ] = static :: get ( $ v , $ field ) ; } return $ preserve_keys ? $ values : array_values ( $ values ) ; }
Extract a single field from an array of arrays or objects .
16,232
public function findActual ( ) { if ( null === $ this -> actual ) { $ this -> actual = $ this -> find ( $ this -> getSiteInfo ( ) -> getSubdomainId ( ) ) ; } return $ this -> actual ; }
Find the current actual sub - domain
16,233
protected function renderElementIcon ( ElementInterface $ element ) { $ render = '' ; $ icon = $ element -> getOption ( 'icon' ) ; if ( $ icon ) { $ iconHelper = $ this -> getIconHelper ( ) ; $ render = $ iconHelper ( $ icon ) ; } return $ render ; }
Render element icon
16,234
protected function setElementClass ( ElementInterface $ element ) { $ class = $ element -> getAttribute ( 'class' ) ; $ type = $ element -> getOption ( 'type' ) ? : self :: TYPE_DEFAULT ; if ( ! in_array ( $ type , self :: TYPES , true ) ) { throw new Exception \ DomainException ( sprintf ( '%s requires that the button type is one of "' . implode ( '", "' , self :: TYPES ) . '"' , __METHOD__ ) ) ; } if ( $ class ) { $ class .= ' ' ; } $ class .= 'btn btn-' . $ type ; $ element -> setAttribute ( 'class' , $ class ) ; }
Set element class
16,235
public function offsetGet ( $ offset ) { if ( $ this -> get !== null ) { return $ this -> get -> invoke ( $ this -> obj , $ offset ) ; } throw new NoSuchPropertyException ( $ this -> name ) ; }
Executes the accessor for a given array property
16,236
public function offsetSet ( $ offset , $ value ) : void { if ( $ this -> set !== null ) { $ this -> set -> invoke ( $ this -> obj , $ offset , $ value ) ; return ; } throw new NoSuchPropertyException ( $ this -> name ) ; }
Executes the mutator for a given array property
16,237
public function getIterator ( ) : Traversable { if ( $ this -> iterator !== null ) { return $ this -> iterator -> invoke ( $ this -> obj ) ; } throw new NoSuchPropertyException ( $ this -> name ) ; }
Returns the iterator for the array
16,238
public function send ( ) { foreach ( $ this -> messages as $ mail ) { $ this -> mailer -> send ( $ mail ) ; } return $ this ; }
Send all messages
16,239
private function getScreenshotStatus ( $ status ) : int { switch ( mb_strtoupper ( $ status ) ) { case 'IN_QUEUE' : return ScreenshotStatus :: IN_QUEUE ; case 'IN_PROCESS' : return ScreenshotStatus :: IN_PROCESS ; case 'FINISHED' : return ScreenshotStatus :: FINISHED ; case 'ERROR' : return ScreenshotStatus :: ERROR ; } return ScreenshotStatus :: UNKNOWN ; }
Get screenshot status by its name
16,240
public static function send ( $ clean = TRUE ) { if ( ! headers_sent ( ) ) { foreach ( self :: $ headers as $ header ) { if ( is_array ( $ header ) ) { call_user_func_array ( 'header' , $ header ) ; } else { header ( $ header ) ; } } if ( $ clean ) { self :: $ headers = array ( ) ; } } self :: $ sent = TRUE ; }
Send HTTP Headers
16,241
public static function location ( $ url , $ code = 301 ) { self :: set ( array ( 'Location: ' . $ url , TRUE , $ code ) ) ; return self :: send ( ) ; }
Set and redirect HTTP Header Location
16,242
public static function contentType ( $ type , $ charset = 'utf-8' ) { $ type = isset ( self :: $ types [ $ type ] ) ? self :: $ types [ $ type ] : $ type ; self :: set ( 'Content-Type: ' . $ type . '; charset=' . $ charset ) ; }
Set HTTP Content - Type
16,243
protected function readFile ( string $ file ) : array { if ( ! file_exists ( $ file ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Configuration %s is not exists' , $ file ) , E_WARNING ) ; } if ( ! is_array ( ( $ configs = $ this -> parseFromFile ( $ file ) ) ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid %s configuration from file: %s' , ltrim ( strrchr ( get_class ( $ this ) , '\\' ) , '\\' ) , $ file ) , E_NOTICE ) ; } return $ configs ; }
Read current file
16,244
public static function getTypes ( ) : array { return [ self :: TYPE_DELIVERY => self :: TYPE_DELIVERY , self :: TYPE_SALE => self :: TYPE_SALE , self :: TYPE_REGULATION => self :: TYPE_REGULATION , self :: TYPE_RETURN => self :: TYPE_RETURN , ] ; }
Returns the valid types .
16,245
protected function updateCurrency ( Money $ money ) : self { if ( $ this -> currency && $ money -> getCurrency ( ) -> getCode ( ) !== $ this -> currency ) { throw new CurrencyMismatchException ( 'The currency on this stock movement is not the same as the one your Money object' ) ; } $ this -> currency = $ money -> getCurrency ( ) -> getCode ( ) ; return $ this ; }
Updates the shared currency .
16,246
protected function money ( int $ val ) : Money { if ( ! $ this -> currency ) { throw new UnsetCurrencyException ( 'The currency is not set on this stock movement' ) ; } return new Money ( $ val , new Currency ( $ this -> currency ) ) ; }
Returns a new Money object based on the shared currency If no currency is set it throws an exception .
16,247
private static function treeGoDown ( $ id , $ data , & $ hidden ) { foreach ( $ data as $ row ) { if ( $ row [ 'parent_id' ] == $ id ) { if ( false === in_array ( $ row [ 'id' ] , $ hidden ) ) { $ hidden [ ] = $ row [ 'id' ] ; } self :: treeGoDown ( $ row [ 'id' ] , $ data , $ hidden ) ; } } }
Recursively finds all children of node with given id
16,248
public function handle ( ) { $ response = '' ; try { $ this -> app -> instance ( 'mode' , 'web' ) ; $ this -> app -> boot ( ) ; $ request = $ this -> prepareRequest ( ) ; $ response = $ this -> runRoute ( $ request ) ; } catch ( \ Exception $ e ) { $ this -> reportException ( $ e ) ; $ response = Router :: toResponse ( $ request , $ this -> renderException ( $ request , $ e ) ) ; } $ this -> terminate ( $ request , $ response ) ; return $ response ; }
Handle web .
16,249
public static function Folders ( $ SourceFolders ) { if ( ! is_array ( $ SourceFolders ) ) $ SourceFolders = array ( $ SourceFolders ) ; $ BlackList = Gdn :: Config ( 'Garden.FolderBlacklist' ) ; if ( ! is_array ( $ BlackList ) ) $ BlackList = array ( '.' , '..' ) ; $ Result = array ( ) ; foreach ( $ SourceFolders as $ SourceFolder ) { if ( $ DirectoryHandle = opendir ( $ SourceFolder ) ) { while ( ( $ Item = readdir ( $ DirectoryHandle ) ) !== FALSE ) { $ SubFolder = CombinePaths ( array ( $ SourceFolder , $ Item ) ) ; if ( ! in_array ( $ Item , $ BlackList ) && is_dir ( $ SubFolder ) ) $ Result [ ] = $ Item ; } closedir ( $ DirectoryHandle ) ; } } if ( count ( $ Result ) == 0 ) return FALSE ; return $ Result ; }
Returns an array of all folder names within the source folder or FALSE if SourceFolder does not exist .
16,250
public static function GetContents ( ) { $ File = CombinePaths ( func_get_args ( ) ) ; if ( file_exists ( $ File ) && is_file ( $ File ) ) return self :: _GetContents ( $ File ) ; else return FALSE ; }
Returns the contents of the specified file or FALSE if it does not exist . Note that this is only useful for static content since any php code will be parsed as if it were within this method of this object .
16,251
public static function SaveFile ( $ FileName , $ FileContents , $ Flags = VANILLA_FILE_PUT_FLAGS ) { $ DirName = dirname ( $ FileName ) ; $ FileBaseName = basename ( $ FileName ) ; if ( ! is_dir ( $ DirName ) ) throw new Exception ( sprintf ( 'Requested save operation [%1$s] could not be completed because target folder [%2$s] does not exist.' , $ FileBaseName , $ DirName ) ) ; if ( ! IsWritable ( $ DirName ) ) throw new Exception ( sprintf ( 'Requested save operation [%1$s] could not be completed because target folder [%2$s] is not writable.' , $ FileBaseName , $ DirName ) ) ; if ( file_put_contents ( $ FileName , $ FileContents , $ Flags ) === FALSE ) throw new Exception ( sprintf ( 'Requested save operation [%1$s] could not be completed!' , $ FileBaseName ) ) ; return TRUE ; }
Saves the specified file with the provided file contents .
16,252
public static function ServeFile ( $ File , $ Name = '' , $ MimeType = '' , $ ServeMode = 'attachment' ) { $ FileIsLocal = ( substr ( $ File , 0 , 4 ) == 'http' ) ? FALSE : TRUE ; $ FileAvailable = ( $ FileIsLocal ) ? is_readable ( $ File ) : TRUE ; if ( $ FileAvailable ) { Gdn :: Database ( ) -> CloseConnection ( ) ; $ NameExtension = strtolower ( pathinfo ( $ Name , PATHINFO_EXTENSION ) ) ; $ FileExtension = strtolower ( pathinfo ( $ File , PATHINFO_EXTENSION ) ) ; if ( $ NameExtension == '' ) { if ( $ Name == '' ) { $ Name = pathinfo ( $ File , PATHINFO_FILENAME ) . '.' . $ FileExtension ; } elseif ( ! StringEndsWith ( $ Name , '.' . $ FileExtension ) ) { $ Name .= '.' . $ FileExtension ; } } else { $ Extension = $ NameExtension ; } $ Name = rawurldecode ( $ Name ) ; $ MimeTypes = array ( "pdf" => "application/pdf" , "txt" => "text/plain" , "html" => "text/html" , "htm" => "text/html" , "exe" => "application/octet-stream" , "zip" => "application/zip" , "doc" => "application/msword" , "xls" => "application/vnd.ms-excel" , "ppt" => "application/vnd.ms-powerpoint" , "gif" => "image/gif" , "png" => "image/png" , "jpeg" => "image/jpg" , "jpg" => "image/jpg" , "php" => "text/plain" , "ico" => "image/vnd.microsoft.icon" ) ; if ( $ MimeType == '' ) { if ( array_key_exists ( $ FileExtension , $ MimeTypes ) ) { $ MimeType = $ MimeTypes [ $ FileExtension ] ; } else { $ MimeType = 'application/force-download' ; } ; } ; @ ob_end_clean ( ) ; if ( ini_get ( 'zlib.output_compression' ) ) ini_set ( 'zlib.output_compression' , 'Off' ) ; if ( $ ServeMode == 'inline' ) header ( 'Content-Disposition: inline; filename="' . $ Name . '"' ) ; else header ( 'Content-Disposition: attachment; filename="' . $ Name . '"' ) ; header ( 'Content-Type: ' . $ MimeType ) ; header ( "Content-Transfer-Encoding: binary" ) ; header ( 'Accept-Ranges: bytes' ) ; header ( "Cache-control: private" ) ; header ( 'Pragma: private' ) ; header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ) ; readfile ( $ File ) ; exit ( ) ; } else { die ( 'not readable' ) ; } }
Serves a file to the browser .
16,253
public static function Copy ( $ source , $ dest , $ options = array ( 'folderPermission' => 0755 , 'filePermission' => 0755 ) ) { $ result = false ; if ( is_file ( $ source ) ) { if ( $ dest [ strlen ( $ dest ) - 1 ] == '/' ) { if ( ! file_exists ( $ dest ) ) { cmfcDirectory :: makeAll ( $ dest , $ options [ 'folderPermission' ] , true ) ; } $ __dest = $ dest . "/" . basename ( $ source ) ; } else { $ __dest = $ dest ; } $ result = copy ( $ source , $ __dest ) ; chmod ( $ __dest , $ options [ 'filePermission' ] ) ; } elseif ( is_dir ( $ source ) ) { if ( $ dest [ strlen ( $ dest ) - 1 ] == '/' ) { if ( $ source [ strlen ( $ source ) - 1 ] == '/' ) { } else { $ dest = $ dest . basename ( $ source ) ; @ mkdir ( $ dest ) ; chmod ( $ dest , $ options [ 'filePermission' ] ) ; } } else { if ( $ source [ strlen ( $ source ) - 1 ] == '/' ) { @ mkdir ( $ dest , $ options [ 'folderPermission' ] ) ; chmod ( $ dest , $ options [ 'filePermission' ] ) ; } else { @ mkdir ( $ dest , $ options [ 'folderPermission' ] ) ; chmod ( $ dest , $ options [ 'filePermission' ] ) ; } } $ dirHandle = opendir ( $ source ) ; while ( $ file = readdir ( $ dirHandle ) ) { if ( $ file != "." && $ file != ".." ) { if ( ! is_dir ( $ source . "/" . $ file ) ) { $ __dest = $ dest . "/" . $ file ; } else { $ __dest = $ dest . "/" . $ file ; } $ result = Gdn_FileSystem :: Copy ( $ source . "/" . $ file , $ __dest , $ options ) ; } } closedir ( $ dirHandle ) ; } else { $ result = false ; } return $ result ; }
Copy file or folder from source to destination
16,254
function save ( string $ filename = null ) : bool { if ( ! empty ( $ filename ) ) $ this -> filename = $ filename ; return ( file_put_contents ( $ this -> filename , json_encode ( $ this -> confValues , JSON_PRETTY_PRINT ) ) !== false ) ; }
Save Configuration file
16,255
public function get ( string $ key , string $ default = null ) { $ keys = explode ( '.' , $ key ) ; $ val = $ this -> confValues ; for ( $ i = 0 ; $ i < count ( $ keys ) ; $ i ++ ) { $ val = ( $ val [ $ keys [ $ i ] ] ?? null ) ; if ( is_null ( $ val ) ) break ; } return $ val ?? $ default ; }
Get a config item
16,256
protected function resolveThemeFile ( $ type , $ file , $ scope , $ asFileInfo = false ) { $ themePath = ( $ scope ) ? $ scope . '/' . ltrim ( $ file , '/' ) : ltrim ( $ file , '/' ) ; $ path = false ; $ stack = $ this -> getFallbackThemes ( ) ; array_unshift ( $ stack , $ this -> getCurrentTheme ( ) ) ; while ( ( $ path === false ) && ( $ theme = array_shift ( $ stack ) ) ) { $ path = $ this -> findThemeFile ( $ type , $ theme , $ themePath ) ; } if ( ! $ asFileInfo && ( $ path !== false ) ) { $ path = $ path -> getPathname ( ) ; } return $ path ; }
Internal resolve theme file
16,257
public function getPath ( ) { $ sname = '' ; $ gname = '' ; $ vname = $ this -> getName ( ) ; if ( $ this -> getConfigGroup ( ) ) { if ( $ this -> getConfigGroup ( ) -> getConfigSection ( ) ) { $ sname = $ this -> getConfigGroup ( ) -> getConfigSection ( ) -> getName ( ) ; } $ gname = $ this -> getConfigGroup ( ) -> getName ( ) ; } return sprintf ( '%s:%s:%s' , $ sname , $ gname , $ vname ) ; }
Return the path for this ConfigValue
16,258
public function returnFullDataStorage ( ) { $ aStorage = $ this -> getSNMP ( ) -> realWalk1d ( self :: OID_STORAGE ) ; $ aReturn = Array ( ) ; $ aReturn [ 'memory_size' ] = $ aStorage [ self :: OID_STORAGE_MEMORY_SIZE ] [ 0 ] ; $ aReturn [ 'index' ] = $ aStorage [ self :: OID_STORAGE_INDEX ] ; $ aReturn [ 'type' ] = $ aStorage [ self :: OID_STORAGE_TYPE ] ; $ aReturn [ 'description' ] = $ aStorage [ self :: OID_STORAGE_DESCR ] ; $ aReturn [ 'allocation_units' ] = $ aStorage [ self :: OID_STORAGE_ALLOCATION_UNITS ] ; $ aReturn [ 'size' ] = $ aStorage [ self :: OID_STORAGE_SIZE ] ; $ aReturn [ 'used' ] = $ aStorage [ self :: OID_STORAGE_USED ] ; return $ aReturn ; }
Returns Full Data Storage
16,259
public function get_cookie ( $ name ) { $ retval = NULL ; if ( isset ( $ _COOKIE ) && isset ( $ _COOKIE [ $ name ] ) ) { $ retval = $ _COOKIE [ $ name ] ; } return ( $ retval ) ; }
Retrieve data for an existing cookie .
16,260
public static function fromString ( $ string , $ separator = ' ' ) { $ string = ( string ) $ string ; if ( $ separator === '' ) { return new StringList ( str_split ( $ string ) , '' ) ; } $ prefix = '' ; $ suffix = '' ; if ( $ string [ 0 ] == $ separator ) { $ prefix = $ separator ; } if ( $ string [ strlen ( $ string ) - 1 ] == $ separator ) { $ suffix = $ separator ; } $ strList = new StringList ( explode ( $ separator , trim ( $ string , $ separator ) ) , $ separator ) ; $ strList -> prefix = $ prefix ; $ strList -> suffix = $ suffix ; return $ strList ; }
Creates a Stringlist from a string .
16,261
public function copy ( ) { $ copy = parent :: copy ( ) ; $ copy -> delimiter = $ this -> delimiter ; $ copy -> prefix = $ this -> prefix ; $ copy -> suffix = $ this -> suffix ; return $ copy ; }
Returns a copy
16,262
public function onRegister ( Event \ Register $ event ) { $ userModel = $ this -> getServiceLocator ( ) -> get ( 'Grid\User\Model\User\Model' ) ; $ user = $ userModel -> register ( $ event -> getData ( ) ) ; $ event -> setUser ( $ user ) ; if ( is_null ( $ event -> getUser ( ) ) ) { $ event -> stopPropagation ( true ) ; } return $ event ; }
Handles register event
16,263
public function onSave ( Event \ Save $ event ) { $ success = $ event -> getUser ( ) -> save ( ) ; $ event -> setResult ( ( bool ) $ success ) ; if ( $ event -> getResult ( ) === false ) { $ event -> stopPropagation ( true ) ; } return $ event ; }
Handles save event
16,264
public function onDelete ( Event \ Delete $ event ) { $ success = $ event -> getUser ( ) -> delete ( ) ; $ event -> setResult ( ( bool ) $ success ) ; if ( $ event -> getResult ( ) === false ) { $ event -> stopPropagation ( true ) ; } return $ event ; }
Handles delete event
16,265
public function run ( callable $ applicationThick ) { try { $ promiseManager = $ this -> getContainerManager ( ) -> getContainer ( ) -> get ( PromiseManager :: class ) ; $ promiseManager -> addPromise ( 'shutdown' , function ( ) { ShutdownPromisePool :: callAllPromises ( ) ; } ) ; $ applicationThick ( ) ; RouterStore :: makeBinding ( ) ; } catch ( \ Throwable $ e ) { if ( ! is_null ( $ this -> logger ) ) { $ this -> logger -> error ( $ e -> getMessage ( ) , [ 'stacktrace' => $ e -> getTrace ( ) , ] ) ; } } finally { ShutdownPromisePool :: callAllPromises ( ) ; } }
Run the App
16,266
public function setPath ( string $ appRoot ) { $ this -> path = new Path ( $ appRoot , $ this -> coreRoot ) ; $ this -> containerManager -> getContainer ( ) -> instance ( Path :: class , $ this -> path ) ; }
Set path instance by App
16,267
public function env ( string $ var , $ default = null ) { $ value = getenv ( $ var ) ?? null ; if ( $ value === false ) { return $ default instanceof Closure ? $ default ( ) : $ default ; } switch ( strtolower ( $ value ) ) { case 'true' : case '(true)' : return true ; case 'false' : case '(false)' : return false ; case 'empty' : case '(empty)' : return '' ; case 'null' : case '(null)' : return null ; } if ( strlen ( $ value ) > 1 && ( 0 === strpos ( $ value , '"' ) ) && ( strlen ( $ value ) - 1 === strpos ( $ value , '"' ) ) ) { return substr ( $ value , 1 , - 1 ) ; } return $ value ; }
Accessor to environment vars
16,268
protected function initServiceContainer ( Container $ container ) { $ sr = new ServiceRegistrator ( $ this -> coreRoot , "Wpci\\Core\\" , $ container ) ; $ sr -> exclude ( Path :: class ) ; $ sr -> prepareArguments ( View :: class , [ TemplateInterface :: class => MustacheTemplate :: class , ResponseInterface :: class => WpResponse :: class ] ) ; $ sr -> walkDirForServices ( 'Flow' ) ; $ sr -> walkDirForServices ( 'DataSource' ) ; $ sr -> walkDirForServices ( 'Helpers' ) ; $ sr -> walkDirForServices ( 'Http' ) ; $ sr -> walkDirForServices ( 'Render' ) ; $ sr -> walkDirForServices ( 'Wordpress' ) ; $ container -> singleton ( 'router-store' , \ Wpci \ Core \ Http \ RouterStore :: class ) ; $ container -> instance ( 'promise-pool.shutdown' , new PromisePool ( ) ) ; }
Service container inti instructions
16,269
final protected function isCollectionClass ( $ collectionItem ) { if ( is_null ( $ this -> collectionClass ) ) { return true ; } else { return is_a ( $ collectionItem , $ this -> collectionClass -> getValue ( ) ) ; } }
Checks if a proposed collection item is the correct collection item class .
16,270
final protected function setCollectionClass ( $ class ) { try { $ this -> collectionClass = new StringType ( $ class ) ; } catch ( TypeValidationException $ e ) { $ this -> collectionClass = CollectionConstants :: _UNMAPPABLE_CLASS ; } catch ( ValueOutOfBoundsException $ e ) { $ this -> collectionClass = CollectionConstants :: _UNMAPPABLE_CLASS ; } }
Sets the expected class for the collection s items .
16,271
public function log ( $ message , $ level , array $ context = array ( ) ) { $ return = true ; if ( ! isset ( self :: $ levels [ $ level ] ) ) { throw new \ OutOfBoundsException ( 'Log level invalid' ) ; } if ( ( int ) $ level <= $ this -> level ) { $ message = sprintf ( $ this -> logFormat . PHP_EOL , date ( $ this -> dateFormat ) , self :: $ levels [ $ level ] , $ this -> interpolate ( ( string ) $ message , $ context ) ) ; if ( false === fwrite ( $ this -> handle , $ message ) ) { $ return = false ; } } return $ return ; }
Writes a log message of a given level .
16,272
public function showAction ( $ id ) { $ acl = $ this -> get ( 'bacon_acl.service.authorization' ) ; if ( ! $ acl -> authorize ( 'users' , 'SHOW' ) ) { throw $ this -> createAccessDeniedException ( ) ; } $ breadcumbs = $ this -> container -> get ( 'bacon_breadcrumbs' ) ; $ breadcumbs -> addItem ( array ( 'title' => 'User' , 'route' => 'admin_user' , ) ) ; $ breadcumbs -> addItem ( array ( 'title' => 'Details' , 'route' => '' , ) ) ; $ className = $ this -> getParameter ( 'fos_user.model.user.class' ) ; $ entity = $ this -> getDoctrine ( ) -> getRepository ( $ className ) -> find ( $ id ) ; if ( ! $ entity ) { $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'message' , array ( 'type' => 'error' , 'message' => 'The registry not Found' , ) ) ; return $ this -> redirect ( $ this -> generateUrl ( 'admin_user' ) ) ; } $ deleteForm = $ this -> createDeleteForm ( $ id ) ; return array ( 'entity' => $ entity , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Finds and displays a User entity .
16,273
public function getUser ( ) { if ( null === $ this -> user && $ this -> isLogin ( ) ) { $ username = Base :: instance ( ) -> get ( static :: SESSION_USER ) ; $ this -> user = Security :: instance ( ) -> getUserProvider ( ) -> loadByUsername ( $ username ) ; try { Authentication :: instance ( ) -> checkUser ( $ this -> user ) ; } catch ( Exception $ e ) { $ this -> user = null ; } } return $ this -> user ; }
Get user load from session if needed
16,274
public function setUri ( $ uri ) { $ uri = ( string ) $ uri ; if ( empty ( $ uri ) ) { $ uri = '#' ; } else if ( ! preg_match ( '(^(' . static :: VALID_SCHEMES . '))' , $ uri ) ) { if ( preg_match ( '(^[a-z0-9-]+(\.[a-z0-9-]+)+(/.*)?$)' , $ uri ) ) { $ uri = static :: DEFAULT_SCHEME . $ uri ; } else { $ uri = '/' . ltrim ( $ uri , '/' ) ; } } $ this -> uri = $ uri ; return $ this ; }
Setter for uri
16,275
public static function buildDeleteRelationQuery ( Relation $ relation ) { $ query = "DELETE FROM `" . $ relation -> getTable ( ) . "` " ; $ query .= "WHERE " . $ relation -> getLocalColumn ( ) . " = :id;" ; return $ query ; }
Build a delete query for a relation .
16,276
public static function buildRelationQuery ( $ entity , Relation $ relation ) { $ relQuery = "" ; $ getid = "getId" ; if ( $ relation -> getCardinality ( ) == Relation :: $ manyToMany ) { $ m = "get" . $ relation -> getName ( ) ; $ relQuery .= "INSERT INTO " . $ relation -> getTable ( ) . " (" . $ relation -> getLocalColumn ( ) . ", " . $ relation -> getForeignColumn ( ) . ") " ; $ relQuery .= "VALUES (:" . $ relation -> getLocalColumn ( ) . ", :" . $ relation -> getForeignColumn ( ) . ");" ; } if ( $ relation -> getCardinality ( ) == Relation :: $ oneToMany ) { $ relMapper = MapperBuilder :: buildFromName ( $ this -> mapping , $ relation -> getEntity ( ) ) ; $ m = "get" . $ relation -> getName ( ) ; foreach ( $ entity -> $ m ( ) as $ rel ) { $ setid = "set" . $ relMapper -> getNameForColumn ( $ relation -> getForeignColumn ( ) ) ; $ rel -> $ setid ( $ entity -> $ getid ( ) ) ; $ relQuery .= $ this -> buildInsertQuery ( $ rel ) ; } } return $ relQuery ; }
Return the insert relation query .
16,277
public static function buildUpdateQuery ( $ entity , Mapper $ mapper ) { $ fields = "" ; foreach ( $ mapper -> getPropertys ( ) as $ property ) { if ( $ property -> getColumn ( ) != "id" ) { $ method = "get" . $ property -> getName ( ) ; $ entity -> $ method ( ) ; if ( $ property -> isNumeric ( ) ) { $ fieldValue = "`=:" . $ property -> getColumn ( ) . ", " ; } else { $ fieldValue = "`=:" . $ property -> getColumn ( ) . ", " ; } $ fields .= "`" . $ property -> getColumn ( ) . $ fieldValue ; } } $ fields = substr_replace ( $ fields , "" , - 2 ) ; $ query = "UPDATE `" . $ mapper -> getTable ( ) . "` SET " . $ fields . " WHERE id=:id" ; return $ query ; }
Return the update query for the entity .
16,278
public static function buildSelectRelation ( $ relation , $ mapperRelation ) { $ query = "" ; $ fields = "" ; foreach ( $ mapperRelation -> getPropertys ( ) as $ property ) { $ fields .= "c." . $ property -> getColumn ( ) . ", " ; } $ fields = substr_replace ( $ fields , "" , - 2 ) ; if ( $ relation -> getCardinality ( ) == Relation :: $ manyToMany ) { $ query = "select " . $ fields . " from " . $ mapperRelation -> getTable ( ) . " c " ; $ query .= "inner join " . $ relation -> getTable ( ) . " nc on nc." . $ relation -> getForeignColumn ( ) . " = c.id " ; $ query .= "where nc." . $ relation -> getLocalColumn ( ) . " = :id" ; } if ( $ relation -> getCardinality ( ) == Relation :: $ oneToMany ) { $ query = "select " . $ fields . " from " . $ mapperRelation -> getTable ( ) . " c " ; $ query .= "where c." . $ relation -> getForeignColumn ( ) . " = :id" ; } return $ query ; }
Get the query for select the related entitys .
16,279
public function getData ( $ key , $ fetcher = self :: DEFAULT_FETCHER_NAME ) { return $ this -> getDataFetcher ( $ fetcher ) -> getData ( $ key ) ; }
Get real substitution data
16,280
public static function getCurrentIP ( ) { $ ip = '' ; foreach ( [ 'HTTP_CLIENT_IP' , 'HTTP_X_FORWARDED_FOR' , 'HTTP_X_FORWARDED' , 'HTTP_X_CLUSTER_CLIENT_IP' , 'HTTP_FORWARDED_FOR' , 'HTTP_FORWARDED' , 'REMOTE_ADDR' ] as $ headerKey ) { if ( $ item = getenv ( $ headerKey ) ) { foreach ( array_filter ( explode ( ',' , $ item ) , 'trim' ) as $ ipAddress ) { if ( $ ip = filter_var ( $ ipAddress , FILTER_VALIDATE_IP , FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { break 2 ; } } } } return ( string ) $ ip ; }
Gets the current IP address
16,281
public function renderMethod ( MethodInterface $ method ) { if ( ! $ method -> supports ( MethodInterface :: BROWSER_PLATFORM ) ) { throw new \ InvalidArgumentException ( 'Renderer only accepts browser methods.' ) ; } return 'window.analytics.' . $ method -> getName ( ) . '(' . $ this -> renderArguments ( $ method ) . ');' ; }
Renders the library method .
16,282
public function renderPage ( $ name = null , $ category = null , array $ properties = array ( ) ) { return $ this -> renderMethod ( new PageMethod ( $ name , $ category , $ properties ) ) ; }
Renders a page method .
16,283
public function renderQueue ( Queue $ queue ) { $ render = '' ; while ( $ method = $ queue -> dequeue ( MethodInterface :: BROWSER_PLATFORM ) ) { $ render .= $ this -> renderMethod ( $ method ) . "\n" ; } return trim ( $ render ) ; }
Renders a queue of library methods .
16,284
private function renderArgument ( $ argument ) { if ( is_array ( $ argument ) ) { $ argument = json_encode ( $ argument ) ; } elseif ( null === $ argument ) { $ argument = 'null' ; } elseif ( is_string ( $ argument ) ) { $ argument = '"' . $ argument . '"' ; } return $ argument ; }
Renders a method argument .
16,285
public static function identity ( $ type = Matrix44 :: class ) : Matrix { $ matrix = new $ type ( ) ; for ( $ i = 0 ; $ i < $ type :: ROWS ; $ i ++ ) { for ( $ j = 0 ; $ j < $ type :: COLUMNS ; $ j ++ ) { $ matrix [ $ i ] [ $ j ] = $ i === $ j ? 1 : 0 ; } } return $ matrix ; }
Create an identity matrix of given matrix type .
16,286
public static function mul ( Matrix $ matrix , $ value ) : Matrix { if ( $ value instanceof Matrix ) { return self :: mulMatrix ( $ matrix , $ value ) ; } if ( is_numeric ( $ value ) ) { return self :: mulScalar ( $ matrix , $ value ) ; } $ type = gettype ( $ value ) ; throw new InvalidArgumentException ( "Invalid type. Can not multiply a matrix with {$type}." ) ; }
Matrix multiplication .
16,287
public static function mulScalar ( Matrix $ matrix , float $ scalar ) : Matrix { $ type = get_class ( $ matrix ) ; $ result = new $ type ( ) ; for ( $ i = 0 ; $ i < $ type :: ROWS ; $ i ++ ) { for ( $ j = 0 ; $ j < $ type :: COLUMNS ; $ j ++ ) { $ result [ $ i ] [ $ j ] = $ matrix [ $ i ] [ $ j ] * $ scalar ; } } return $ result ; }
Matrix scalar multiplication .
16,288
public static function add ( Matrix $ matrix , Matrix $ matrix2 ) : Matrix { $ type = get_class ( $ matrix ) ; $ type2 = get_class ( $ matrix2 ) ; if ( $ type !== $ type2 ) { throw new InvalidArgumentException ( "Can only add matrices of same size." ) ; } $ result = new $ type ( ) ; for ( $ i = 0 ; $ i < $ type :: ROWS ; $ i ++ ) { for ( $ j = 0 ; $ j < $ type :: COLUMNS ; $ j ++ ) { $ result [ $ i ] [ $ j ] = $ matrix [ $ i ] [ $ j ] + $ matrix2 [ $ i ] [ $ j ] ; } } return $ result ; }
Matrix Matrix addition .
16,289
public static function makeRotationX ( float $ angle , string $ type = Math :: DEGREES ) : Matrix33 { if ( $ type === Math :: DEGREES ) { $ angle = Math :: degToRad ( $ angle ) ; } return new Matrix33 ( 1 , 0 , 0 , 0 , cos ( $ angle ) , - sin ( $ angle ) , 0 , sin ( $ angle ) , cos ( $ angle ) ) ; }
Create a rotation matrix with given X angle rotation .
16,290
public static function pickAppDir ( $ path ) { if ( $ path [ 0 ] !== '/' ) return $ path ; $ root = null ; foreach ( self :: $ namespaces as $ p => $ ns ) { if ( strpos ( $ path , $ p ) === 0 ) { if ( $ root === null || strlen ( $ root ) < strlen ( $ p ) ) $ root = $ p ; } } return $ root ? $ root : $ path ; }
pick the app dir from some path .
16,291
public static function pickRootDir ( $ path ) { if ( $ path [ 0 ] !== '/' ) return $ path ; $ f = function ( $ names , $ count ) { for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { array_pop ( $ names ) ; } return $ names ; } ; $ root = null ; foreach ( self :: $ namespaces as $ p => $ ns ) { $ d = join ( DS , $ f ( explode ( DS , $ p ) , count ( explode ( '\\' , $ ns ) ) ) ) ; if ( strpos ( $ path , $ d ) === 0 ) { if ( $ root === null || strlen ( $ root ) < strlen ( $ d ) ) $ root = $ d ; } } return $ root ? $ root : $ path ; }
pick the root dir from some path .
16,292
public static function getNamespaceByPath ( $ path , $ is_dir = true ) { if ( $ path [ 0 ] !== '/' ) return null ; $ root_ns = '' ; $ filepath = $ path ; foreach ( self :: $ namespaces as $ p => $ ns ) { if ( strpos ( $ path , $ p ) !== false ) { $ root_ns = $ ns ; $ filepath = substr ( $ path , strlen ( $ p ) + 1 ) ; break ; } } $ ns = $ filepath ? explode ( DS , $ filepath ) : [ ] ; if ( ! $ is_dir ) array_pop ( $ ns ) ; array_unshift ( $ ns , $ root_ns ) ; return join ( '\\' , $ ns ) ; }
get namespace by filepath
16,293
public function rest_api_init ( $ server ) { register_rest_route ( 'sekisyo/v1' , 'license/(?P<guid>[^/]+)/?' , [ [ 'methods' => 'POST' , 'callback' => [ $ this , 'handle_rest_post' ] , 'args' => [ 'guid' => [ 'required' => true , ] , 'license' => [ 'required' => true , ] , ] , 'permission_callback' => function ( $ request ) { return current_user_can ( 'activate_plugins' ) ; } , ] , [ 'methods' => 'DELETE' , 'callback' => [ $ this , 'handle_rest_delete' ] , 'args' => [ 'guid' => [ 'required' => true , ] , 'license' => [ 'required' => true , ] , ] , 'permission_callback' => function ( $ request ) { return current_user_can ( 'activate_plugins' ) ; } , ] , ] ) ; }
Handle API request
16,294
public function check_validity ( ) { foreach ( $ this -> plugins as $ plugin ) { if ( $ plugin -> valid ) { $ plugin -> update_license ( $ plugin -> license , true ) ; if ( ! $ plugin -> fail_limit ) { continue ; } do_action ( 'sekisyo_update_error' , $ plugin -> guid , $ plugin -> failed , $ plugin ) ; if ( $ plugin -> failed > $ plugin -> fail_limit ) { $ plugin -> inactivate ( ) ; } } } }
Check validity with cron job
16,295
public static function get ( $ guid ) { $ instance = self :: get_instance ( ) ; if ( isset ( $ instance -> plugins [ $ guid ] ) ) { return $ instance -> plugins [ $ guid ] ; } else { new \ WP_Error ( sprintf ( __ ( 'Plugin %s is not registered.' , 'sekisyo' ) , $ guid ) , 404 , [ 'status' => 404 , ] ) ; } }
Get plugin instance .
16,296
public static function is_valid ( $ guids = [ ] ) { $ instance = self :: get_instance ( ) ; foreach ( $ guids as $ guid ) { if ( isset ( $ instance -> plugins [ $ guid ] ) && $ instance -> plugins [ $ guid ] -> valid ) { return true ; } } return false ; }
Detect if this plugin is valid
16,297
public function addMetaBoxes ( ) { $ this -> metaBoxes -> rewind ( ) ; while ( $ this -> metaBoxes -> valid ( ) ) { $ metaBox = $ this -> metaBoxes -> current ( ) ; foreach ( $ metaBox -> getSupportedPostTypes ( ) as $ postType ) { add_meta_box ( $ metaBox -> getID ( ) , $ metaBox -> getTitle ( ) , array ( $ metaBox , 'getCallback' ) , $ postType , $ metaBox -> getContext ( ) , $ metaBox -> getPriority ( ) , $ metaBox -> getCallbackArgs ( ) ) ; add_action ( 'save_post' , array ( $ metaBox , 'savePostCallback' ) ) ; } $ this -> metaBoxes -> next ( ) ; } }
Registers all the meta boxes added
16,298
public static function set ( Grid $ grid , Tile $ tile ) { $ rows = $ grid -> rows - $ tile -> height + 1 ; $ columns = $ grid -> columns - $ tile -> width + 1 ; $ row = rand ( 0 , $ rows - 1 ) ; $ column = rand ( 0 , $ columns - 1 ) ; $ initialRow = $ row ; $ initialColumn = $ column ; while ( ! $ grid -> isEmptyForTile ( $ row , $ column , $ tile ) ) { $ column = ( $ column + 1 ) % $ columns ; if ( $ column === 0 ) { $ row = ( $ row + 1 ) % $ rows ; } if ( $ row === $ initialRow && $ column === $ initialColumn ) { throw new InvalidArgumentException ( "No empty slot for {$tile} tile in grid: {$grid}" ) ; } } $ grid -> set ( $ row , $ column , $ tile ) ; return [ $ row , $ column ] ; }
Set a tile randomly within a grid .
16,299
public static function tryToFill ( Grid $ grid , Distribution $ distribution ) { $ smallTiles = $ distribution -> small ; $ tallTiles = $ distribution -> tall ; $ wideTiles = $ distribution -> wide ; for ( $ i = 0 ; $ i < $ distribution -> getTiles ( ) ; $ i ++ ) { if ( $ wideTiles === 0 && $ tallTiles === 0 ) { static :: set ( $ grid , Tile :: SMALL ( ) ) ; $ smallTiles -= 1 ; } elseif ( $ tallTiles >= $ wideTiles ) { static :: set ( $ grid , Tile :: TALL ( ) ) ; $ tallTiles -= 1 ; } else { static :: set ( $ grid , Tile :: WIDE ( ) ) ; $ wideTiles -= 1 ; } } }
Fill a tiles distribution randomly within a grid .