idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
10,000
public function join ( $ table , $ alias = null , $ on = null , $ type = 'INNER JOIN' ) { $ table = $ this -> connection -> quoteIdentifier ( $ table ) ; $ this -> joins [ $ alias ] = "$type $table $alias ON $on" ; return $ this ; }
Join a table
10,001
public function leftJoin ( $ table , $ alias = null , $ on = null ) { return $ this -> join ( $ table , $ alias , $ on , 'LEFT JOIN' ) ; }
LEFT OUTER Join a table
10,002
public function rightJoin ( $ table , $ alias = null , $ on = null ) { return $ this -> join ( $ table , $ alias , $ on , 'RIGHT JOIN' ) ; }
RIGHT OUTER Join a table
10,003
public function innerJoin ( $ table , $ alias = null , $ on = null ) { return $ this -> join ( $ table , $ alias , $ on , 'INNER JOIN' ) ; }
INNER Join a table
10,004
public function getLimit ( ) { if ( $ this -> offset && $ this -> limit ) { return $ this -> offset . ',' . $ this -> limit ; } return ( string ) $ this -> limit ; }
Get limit query part
10,005
public function getSelectQuery ( ) { $ sql = 'SELECT ' . $ this -> getSelect ( ) ; $ sql .= "\nFROM " . $ this -> getFrom ( ) ; if ( $ this -> where ) { $ sql .= "\nWHERE " . $ this -> getWhere ( ) ; } if ( $ this -> groupBy ) { $ sql .= "\nGROUP BY " . $ this -> getGroupBy ( ) ; } if ( $ this -> having ) { $ sql .= "\nHAVING " . $ this -> getHaving ( ) ; } if ( $ this -> orderBy ) { $ sql .= "\nORDER BY " . $ this -> getOrderBy ( ) ; } if ( $ this -> limit ) { $ sql .= "\nLIMIT " . $ this -> getLimit ( ) ; } return $ sql ; }
Get SQL select query
10,006
public function getInsertQuery ( ) { $ sql = 'INSERT INTO ' . $ this -> getTable ( ) ; $ sql .= "\n" . $ this -> getColumns ( ) ; $ sql .= "\nVALUES " . $ this -> getValues ( ) ; return $ sql ; }
Get SQL insert query
10,007
public function getUpdateQuery ( ) { $ sql = 'UPDATE ' . $ this -> getTable ( ) ; $ sql .= "\nSET " . $ this -> getSet ( ) ; if ( $ this -> where ) { $ sql .= "\nWHERE " . $ this -> getWhere ( ) ; } if ( $ this -> orderBy ) { $ sql .= "\nORDER BY " . $ this -> getOrderBy ( ) ; } if ( $ this -> limit ) { $ sql .= "\nLIMIT " . $ this -> getLimit ( ) ; } return $ sql ; }
Get SQL update query
10,008
public function getDeleteQuery ( ) { $ sql = 'DELETE FROM ' . $ this -> getTable ( ) ; if ( $ this -> where ) { $ sql .= "\nWHERE " . $ this -> getWhere ( ) ; } if ( $ this -> limit ) { $ sql .= "\nLIMIT " . $ this -> getLimit ( ) ; } return $ sql ; }
Get SQL delete query
10,009
public function mergeParams ( $ method , Array $ params = [ ] ) { $ newParams = [ ] ; $ preparedParams = $ this -> defaultParams ; $ preparedParams [ 'bean' ] = $ params ; $ newParams [ $ method ] = $ preparedParams ; return $ newParams ; }
Group params in a bean
10,010
public function getSearchFields ( ) { $ fields = parent :: getSearchFields ( ) ; $ class = $ this -> modelClass ; $ use_autocomplete = $ this -> getConvertToAutocomplete ( ) ; $ db = Config :: inst ( ) -> get ( $ class , "db" ) ; $ has_one = Config :: inst ( ) -> get ( $ class , "has_one" ) ; $ has_many = Config :: inst ( ) -> get ( $ class , "has_many" ) ; $ many_many = Config :: inst ( ) -> get ( $ class , "many_many" ) ; $ belongs_many_many = Config :: inst ( ) -> get ( $ class , "belongs_many_many" ) ; $ associations = array_merge ( $ has_one , $ has_many , $ many_many , $ belongs_many_many ) ; return $ fields ; }
Extend default search fields and add extra functionality .
10,011
public function scan ( string $ dir , string $ type = null , & $ res = [ ] , int $ timeout = 0 ) : array { $ res = [ ] ; if ( $ dirs = $ this -> listFiles ( $ dir ) ) { foreach ( $ dirs as $ d ) { if ( $ type && ( strpos ( $ type , 'file' ) === 0 ) && ! isset ( $ d [ 'num' ] ) ) { $ res [ ] = $ d [ 'name' ] ; } else if ( $ type && ( ( strpos ( $ type , 'dir' ) === 0 ) || ( strpos ( $ type , 'fold' ) === 0 ) ) && isset ( $ d [ 'num' ] ) ) { $ res [ ] = $ d [ 'name' ] ; } else { $ res [ ] = $ d [ 'name' ] ; } if ( isset ( $ d [ 'num' ] ) ) { $ this -> scan ( $ d [ 'name' ] , $ type , $ res ) ; } } } return $ res ; }
Scans all the content from a directory including the subdirectories
10,012
public function delete ( $ item ) { self :: log ( 'delete:' . $ item ) ; if ( $ this -> checkFilePath ( $ item ) && ftp_delete ( $ this -> cn , $ item ) ) { return true ; } return false ; }
Deletes a file from the server
10,013
public function put ( $ src , $ dest ) { if ( file_exists ( $ src ) && ( $ dest = $ this -> checkFilePath ( $ dest ) ) && ftp_put ( $ this -> cn , $ dest , $ src , FTP_BINARY ) ) { return true ; } return false ; }
Puts a file on the server
10,014
public function get ( $ src , $ dest ) { if ( $ src = $ this -> checkFilePath ( $ src ) && ftp_get ( $ this -> cn , $ dest , $ src , FTP_BINARY ) ) { return true ; } return false ; }
Gets a file from the server
10,015
public function move ( string $ old , string $ new ) { if ( ! empty ( $ old ) && ! empty ( $ new ) && ( $ old = $ this -> checkFilePath ( $ old ) ) && ftp_rename ( $ this -> cn , $ old , $ new ) ) { return true ; } return false ; }
Moves or renames a file on the server
10,016
public function exists ( string $ path ) { if ( ! empty ( $ path ) ) { $ dir = dirname ( $ path ) ; $ ext = \ bbn \ str :: file_ext ( $ path ) ; $ file = basename ( $ path ) ; if ( \ is_array ( $ files = $ this -> listFiles ( $ dir ) ) ) { foreach ( $ files as $ f ) { if ( $ f [ 'basename' ] === $ file ) { return true ; } } } } return false ; }
Checks if a file is present in a folder on the server
10,017
protected function findEndStandardBlock ( $ name , $ lineNumber , $ maxLine , $ targetStepsInto = 0 ) { $ stepsInto = 0 ; for ( $ i = $ lineNumber ; $ i <= $ maxLine ; $ i ++ ) { if ( $ this -> lineTypes [ 'end' . $ name ] [ $ i ] && $ i > $ lineNumber ) { $ stepsInto -- ; if ( $ stepsInto === $ targetStepsInto ) { return $ i ; } } if ( $ this -> lineTypes [ 'start' . $ name ] [ $ i ] ) { $ stepsInto ++ ; } } throw new \ RuntimeException ( 'Cannot find the end of the ' . $ name . ' block starting in line ' . $ lineNumber . ' (' . $ this -> indenterMachine -> getLine ( $ lineNumber ) . ')' ) ; }
Generic algorithm to find the end of a block
10,018
public function equals ( Rule $ rule ) { if ( $ this -> ruleHash !== $ rule -> ruleHash ) { return false ; } if ( count ( $ this -> literals ) != count ( $ rule -> literals ) ) { return false ; } for ( $ i = 0 , $ n = count ( $ this -> literals ) ; $ i < $ n ; $ i ++ ) { if ( $ this -> literals [ $ i ] !== $ rule -> literals [ $ i ] ) { return false ; } } return true ; }
Checks if this rule is equal to another one
10,019
public static function convertBytes ( $ value ) { if ( is_numeric ( $ value ) ) { return $ value ; } $ value_length = \ strlen ( $ value ) ; $ qty = ( int ) substr ( $ value , 0 , $ value_length - 1 ) ; $ unit = Str :: strtolower ( substr ( $ value , $ value_length - 1 ) ) ; switch ( $ unit ) { case 'k' : $ qty *= 1024 ; break ; case 'm' : $ qty *= 1048576 ; break ; case 'g' : $ qty *= 1073741824 ; break ; } return $ qty ; }
Convert a shorthand byte value from a PHP configuration directive to an integer value
10,020
public function addURL ( $ url , $ options = array ( ) ) { $ ch = curl_init ( $ url ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; foreach ( $ options as $ option => $ value ) { curl_setopt ( $ ch , $ option , $ value ) ; } return $ this -> addCurl ( $ ch ) ; }
simplifies example and allows for additional curl options to be passed in via array
10,021
public function update ( UserPolicy $ user , Team $ team ) { if ( $ user -> canDo ( 'team.team.edit' ) && $ user -> isAdmin ( ) ) { return true ; } return $ team -> user_id == user_id ( ) && $ team -> user_type == user_type ( ) ; }
Determine if the given user can update the given team .
10,022
public function destroy ( UserPolicy $ user , Team $ team ) { return $ team -> user_id == user_id ( ) && $ team -> user_type == user_type ( ) ; }
Determine if the given user can delete the given team .
10,023
public function includeJavascript ( $ scripts ) { $ src = ( ! is_array ( $ scripts ) ) ? Array ( $ scripts ) : $ scripts ; $ html = '' ; foreach ( $ scripts as $ s ) { if ( ! strstr ( $ s , '/' ) ) { $ s = '/js/' . $ s ; } $ html .= "\n" . '<script type="text/javascript" src="' . $ s . '"></script>' ; } return $ html ; }
Creates a javascript include tag
10,024
public function htmlHead ( $ custom_head_markup = '' ) { if ( ! empty ( $ custom_head_markup ) ) { $ this -> custom_head_markup = $ custom_head_markup ; } $ html = $ this -> doc_type . "\n" ; $ html .= $ this -> opening_html_tag . "\n" ; $ html .= '<head>' . "\n" ; $ html .= '<meta http-equiv="Content-Type" content="text/html; charset=' . $ this -> charset . '" />' . "\n" ; $ html .= '<meta http-equiv="X-UA-Compatible" content="IE=edge" />' . "\n" ; $ html .= '<title>' . $ this -> title . '</title>' . "\n" ; if ( $ this -> meta instanceof HeadMeta ) { foreach ( get_object_vars ( $ this -> meta ) as $ key => $ val ) { $ html .= '<meta name="' . $ key . '" content="' . $ val . '" />' . "\n" ; } } $ html .= '<style type="text/css">' ; foreach ( $ this -> styles as $ style ) { if ( ! preg_match ( "~^(http|/)~" , $ style ) ) { $ style = '/css/' . $ style ; } $ html .= "@import '" . $ style . "';\n" ; } $ html .= "</style>\n" ; if ( ! empty ( $ this -> custom_head_markup ) ) { $ html .= $ this -> custom_head_markup ; } $ html .= "</head>\n" ; return $ html ; }
Renders the HTML head
10,025
public static function simplePayload ( array $ payload ) : array { $ payload = array_filter ( $ payload , function ( $ val ) { if ( $ val instanceof PayloadInterface ) { $ val = $ val -> getPayload ( ) ; } if ( is_array ( $ val ) && empty ( $ val ) ) { return false ; } if ( is_null ( $ val ) ) { return false ; } if ( $ val === '' ) { return false ; } return true ; } ) ; foreach ( $ payload as $ key => $ val ) { if ( is_array ( $ val ) ) { $ payload [ $ key ] = static :: simplePayload ( $ val ) ; } elseif ( $ val instanceof PayloadInterface ) { $ payload [ $ key ] = static :: simplePayload ( $ val -> getPayload ( ) ) ; } } return $ payload ; }
If the input array contains objects of PayloadInterface it will convert these to simple arrays Also it will remove values that are null empty string or empty arrays
10,026
public static function rollback ( ) { foreach ( array_reverse ( self :: $ migrationClasses ) as $ migrationClass ) { $ instance = new $ migrationClass ; $ instance -> rollback ( ) ; } }
Rollback application migrations .
10,027
public function streamsChannel ( $ channel ) { $ response = $ this -> client -> get ( config ( 'twitch-api.api_url' ) . '/kraken/streams/' . $ channel ) ; return $ response -> json ( ) ; }
Returns a stream object if live .
10,028
public function getInheritedElement ( ) { if ( $ this -> inheritedElement !== null ) { return $ this -> inheritedElement ; } $ associatedClass = $ this -> getParent ( ) ; if ( ! $ associatedClass instanceof ClassDescriptor && ! $ associatedClass instanceof InterfaceDescriptor ) { return null ; } $ parentClass = $ associatedClass -> getParent ( ) ; if ( $ parentClass instanceof ClassDescriptor || $ parentClass instanceof Collection ) { $ parents = $ parentClass instanceof ClassDescriptor ? array ( $ parentClass ) : $ parentClass -> getAll ( ) ; foreach ( $ parents as $ parent ) { if ( $ parent instanceof ClassDescriptor || $ parent instanceof InterfaceDescriptor ) { $ parentMethod = $ parent -> getMethods ( ) -> get ( $ this -> getName ( ) ) ; if ( $ parentMethod ) { $ this -> inheritedElement = $ parentMethod ; return $ this -> inheritedElement ; } } } } if ( $ associatedClass instanceof ClassDescriptor ) { foreach ( $ associatedClass -> getInterfaces ( ) as $ interface ) { if ( ! $ interface instanceof InterfaceDescriptor ) { continue ; } $ parentMethod = $ interface -> getMethods ( ) -> get ( $ this -> getName ( ) ) ; if ( $ parentMethod ) { $ this -> inheritedElement = $ parentMethod ; return $ this -> inheritedElement ; } } } return null ; }
Returns the Method from which this method should inherit its information if any .
10,029
public function transform ( $ translation ) { $ translation = $ this -> entityToArray ( ContentTranslation :: class , $ translation ) ; return [ 'id' => ( int ) $ translation [ 'id' ] , 'langCode' => $ translation [ 'lang_code' ] , 'title' => $ translation [ 'title' ] , 'teaser' => $ translation [ 'teaser' ] , 'body' => $ translation [ 'body' ] , 'seoTitle' => $ translation [ 'seo_title' ] , 'seoDescription' => $ translation [ 'seo_description' ] , 'isActive' => ( bool ) $ translation [ 'is_active' ] , 'createdAt' => $ translation [ 'created_at' ] , 'updatedAt' => $ translation [ 'updated_at' ] , ] ; }
Transforms content translation entity
10,030
protected function processBlockViewData ( BlockView $ blockView , ContextInterface $ context , DataAccessor $ data , $ deferred , $ encoding ) { if ( $ deferred ) { $ this -> expressionProcessor -> processExpressions ( $ blockView -> vars , $ context , $ data , true , $ encoding ) ; } $ this -> buildValueBags ( $ blockView ) ; foreach ( $ blockView -> children as $ key => $ childView ) { $ this -> processBlockViewData ( $ childView , $ context , $ data , $ deferred , $ encoding ) ; if ( ! $ childView -> isVisible ( ) ) { unset ( $ blockView -> children [ $ key ] ) ; } } }
Processes expressions that work with data
10,031
public static function fromArrayAndSettings ( $ cfg , $ settings , $ artifact = null ) { $ fileSpecification = new static ( $ cfg , $ settings -> getDirectory ( ) , $ artifact ) ; $ fileSpecification -> set ( "relativeSource" , $ fileSpecification -> getSource ( ) ) ; $ fileSpecification -> set ( "source" , $ settings -> getPath ( $ fileSpecification -> getSource ( ) ) ) ; $ fileSpecification -> set ( "target" , fphp \ Helper \ Path :: join ( $ settings -> getOptional ( "target" , null ) , $ fileSpecification -> getTarget ( ) ) ) ; if ( ! file_exists ( $ fileSpecification -> getSource ( ) ) ) throw new FileSpecificationException ( "file \"{$fileSpecification->getSource()}\" does not exist" ) ; return $ fileSpecification ; }
Creates a file specification from a plain settings array . The settings context is taken into consideration to generate paths relative to the settings .
10,032
public function setInterval ( $ interval ) { $ this -> interval = $ interval instanceof DateInterval ? $ interval : new DateInterval ( $ interval ) ; return $ this ; }
Set the limit interval
10,033
public function redirect ( $ default = 'home' ) { $ redirect = $ this -> getController ( ) -> plugin ( 'redirect' ) ; $ route = $ this -> getSession ( ) -> route ; if ( null === $ route ) { return $ redirect -> toRoute ( $ default ) ; } return $ redirect -> toRoute ( $ route -> getMatchedRouteName ( ) , $ route -> getParams ( ) ) ; }
Redirect to last route
10,034
public function url ( $ default = 'home' ) { $ url = $ this -> getController ( ) -> plugin ( 'url' ) ; $ route = $ this -> getSession ( ) -> route ; if ( null === $ route ) { return $ url -> fromRoute ( $ default ) ; } return $ url -> fromRoute ( $ route -> getMatchedRouteName ( ) , $ route -> getParams ( ) ) ; }
Get last route URL
10,035
public function storeRoute ( MvcEvent $ event ) { if ( $ this -> ignore ) { return ; } $ request = $ event -> getRequest ( ) ; if ( $ request -> isXmlHttpRequest ( ) ) { return ; } $ appConfig = $ event -> getApplication ( ) -> getServiceManager ( ) -> get ( 'config' ) ; $ config = array_key_exists ( self :: CONFIG_KEY , $ appConfig ) ? $ appConfig [ self :: CONFIG_KEY ] : array ( ) ; if ( array_key_exists ( 'blacklist' , $ config ) ) { $ this -> setBlacklist ( $ config [ 'blacklist' ] ) ; } $ routeMatch = $ event -> getRouteMatch ( ) ; if ( null === $ routeMatch || in_array ( $ routeMatch -> getMatchedRouteName ( ) , $ this -> blacklist ) ) { return ; } $ this -> getSession ( ) -> route = $ routeMatch ; }
Store route in session so it can be returned to later .
10,036
public function resourceSupports ( ) { $ this -> supportedTypes = array_merge ( func_get_args ( ) , $ this -> supportedTypes ) ; $ this -> canClientAcceptThisResponse ( ) ; return $ this ; }
Set a list of content types that this resource supports .
10,037
public function resourceRequires ( ) { $ this -> requiredTypes = array_merge ( func_get_args ( ) , $ this -> requiredTypes ) ; $ this -> canServerSupportThisRequest ( ) ; return $ this ; }
Set a list of content types this resource requires .
10,038
public function renderResource ( $ view , array $ parameters = [ ] , $ statusCode = 200 ) { $ this -> findContentType ( ) -> findViewType ( ) -> buildViewTemplate ( $ view ) -> checkViewTemplateExists ( ) ; $ response = $ this -> createResponse ( $ statusCode ) ; $ response -> headers -> set ( 'Content-Type' , $ this -> contentType ) ; return $ this -> render ( $ this -> viewTemplateName , $ parameters , $ response ) ; }
Creates a Response object and returns it .
10,039
protected function convertToArrayDescriptor ( $ descriptor ) { $ arrayDescriptor = new CollectionDescriptor ( 'array' ) ; $ arrayDescriptor -> setTypes ( array ( $ descriptor ) ) ; $ arrayDescriptor -> setKeyTypes ( array ( 'mixed' ) ) ; return $ arrayDescriptor ; }
Wraps the given Descriptor inside a Collection Descriptor of type array and returns that .
10,040
protected function findClassNameForType ( $ type ) { $ className = ( isset ( $ this -> typeToValueObjectClassName [ $ type ] ) ) ? $ this -> typeToValueObjectClassName [ $ type ] : false ; return $ className ; }
Returns the class name of the Value Object class associated with a given type or false if the type is unknown .
10,041
static public function getImplementations ( ) { $ list = array ( ) ; foreach ( self :: $ implementations as $ name => $ className ) { $ list [ ] = $ name ; } return $ list ; }
Returns a list with supported database implementations .
10,042
static public function create ( $ dbParams ) { if ( is_string ( $ dbParams ) ) { $ dbParams = self :: parseDSN ( $ dbParams ) ; } else if ( ! is_array ( $ dbParams ) ) { throw new ezcBaseValueException ( 'dbParams' , $ dbParams , 'string or array' , 'parameter' ) ; } $ impName = null ; foreach ( $ dbParams as $ key => $ val ) { if ( in_array ( $ key , array ( 'phptype' , 'type' , 'handler' , 'driver' ) ) ) { $ impName = $ val ; break ; } } if ( $ impName === null || ! array_key_exists ( $ impName , self :: $ implementations ) ) { throw new ezcDbHandlerNotFoundException ( $ impName , array_keys ( self :: $ implementations ) ) ; } $ className = self :: $ implementations [ $ impName ] ; $ instance = new $ className ( $ dbParams ) ; return $ instance ; }
Creates and returns an instance of the specified ezcDbHandler implementation .
10,043
public function execute ( $ command , & $ output = null ) { $ cmd = "smbclient '\\\\{$this->host}\\{$this->share}' $this->password -U $this->username -W $this->domain -c '$command' 2>&1" ; exec ( $ cmd , $ output , $ return ) ; if ( $ return === 1 ) { $ errmsg = sprintf ( "Host: %s / Share: %s / Username: %s / Domain: %s / Error Message: %s" , $ this -> host , $ this -> share , $ this -> username , $ this -> domain , implode ( " " , $ output ) ) ; throw new \ Exception ( $ errmsg ) ; } if ( $ this -> debug == true ) { file_put_contents ( "php://stdout" , "\n" . $ cmd ) ; file_put_contents ( "php://stdout" , "\n" . print_r ( $ output , 1 ) ) ; } if ( self :: $ log ) { self :: $ log -> samba ( "Command: $cmd \n Output:" . print_r ( $ output , 1 ) . "\n Return: " . print_r ( $ return , 1 ) . "\n\n\n" ) ; } return $ return ; }
Executes the command line function that completes the remote windows operations
10,044
private function parseListing ( $ listing , $ subdir = '' ) { $ ret = new \ sb \ Samba \ Listing ( ) ; $ exp = '/^\s{2}([\w \-]+\.?\w{3,4})\s+([A-Z]?)\s+(\d+)\s+(\w{3}.+)$/' ; preg_match_all ( $ exp , $ listing , $ matches ) ; if ( $ matches [ 0 ] ) { $ ret -> name = $ matches [ 1 ] [ 0 ] ; $ ret -> type = $ matches [ 2 ] [ 0 ] ; $ ret -> size = $ matches [ 3 ] [ 0 ] ; $ ret -> path = $ subdir ; $ ret -> datemodified = $ matches [ 4 ] [ 0 ] ; return $ ret ; } return 0 ; }
Converts a line of returned output into a \ sb \ Samba_Listing object
10,045
public function get ( $ id ) { $ data = $ this -> execute ( self :: HTTP_GET , self :: DOMUSERP_API_PEDIDOVENDA . '/empresas/' . $ this -> companyId . '/filiais/' . $ id ) ; return $ data ; }
Gets the branch data according to the id parameter
10,046
protected static function getReferrerLocalList ( ) { $ botreferrerlist = array ( ) ; if ( isset ( $ GLOBALS [ 'BOTDETECTION' ] [ 'BOT_REFERRER' ] ) && \ is_array ( $ GLOBALS [ 'BOTDETECTION' ] [ 'BOT_REFERRER' ] ) ) { foreach ( $ GLOBALS [ 'BOTDETECTION' ] [ 'BOT_REFERRER' ] as $ search ) { $ botreferrerlist [ ] = $ search ; } return $ botreferrerlist ; } return false ; }
Get Referrer List self defined over localconfig
10,047
public function channelFileList ( $ cid , $ cpw = "" , $ path = "/" , $ recursive = FALSE ) { $ files = $ this -> execute ( "ftgetfilelist" , array ( "cid" => $ cid , "cpw" => $ cpw , "path" => $ path ) ) -> toArray ( ) ; $ count = count ( $ files ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ files [ $ i ] [ "sid" ] = $ this -> getId ( ) ; $ files [ $ i ] [ "cid" ] = $ files [ 0 ] [ "cid" ] ; $ files [ $ i ] [ "path" ] = $ files [ 0 ] [ "path" ] ; $ files [ $ i ] [ "src" ] = new Str ( $ cid ? $ files [ $ i ] [ "path" ] : "/" ) ; if ( ! $ files [ $ i ] [ "src" ] -> endsWith ( "/" ) ) { $ files [ $ i ] [ "src" ] -> append ( "/" ) ; } $ files [ $ i ] [ "src" ] -> append ( $ files [ $ i ] [ "name" ] ) ; if ( $ recursive && $ files [ $ i ] [ "type" ] == TeamSpeak3 :: FILE_TYPE_DIRECTORY ) { $ files = array_merge ( $ files , $ this -> channelFileList ( $ cid , $ cpw , $ path . $ files [ $ i ] [ "name" ] , $ recursive ) ) ; } } uasort ( $ files , array ( __CLASS__ , "sortFileList" ) ) ; return $ files ; }
Returns a list of files and directories stored in the specified channels file repository .
10,048
public function channelGetById ( $ cid ) { if ( ! array_key_exists ( ( string ) $ cid , $ this -> channelList ( ) ) ) { throw new Exception ( "invalid channelID" , 0x300 ) ; } return $ this -> channelList [ intval ( ( string ) $ cid ) ] ; }
Returns the Channel object matching the given ID .
10,049
public function channelGetByName ( $ name ) { foreach ( $ this -> channelList ( ) as $ channel ) { if ( $ channel [ "channel_name" ] == $ name ) return $ channel ; } throw new Exception ( "invalid channelID" , 0x300 ) ; }
Returns the Channel object matching the given name .
10,050
public function clientList ( array $ filter = array ( ) ) { if ( $ this -> clientList === null ) { $ clients = $ this -> request ( "clientlist -uid -away -badges -voice -info -times -groups -icon -country -ip" ) -> toAssocArray ( "clid" ) ; $ this -> clientList = array ( ) ; foreach ( $ clients as $ clid => $ client ) { if ( $ this -> getParent ( ) -> getExcludeQueryClients ( ) && $ client [ "client_type" ] ) continue ; $ this -> clientList [ $ clid ] = new Client ( $ this , $ client ) ; } uasort ( $ this -> clientList , array ( __CLASS__ , "sortClientList" ) ) ; $ this -> resetNodeList ( ) ; } return $ this -> filterList ( $ this -> clientList , $ filter ) ; }
Returns an array filled with Client objects .
10,051
public function clientGetByName ( $ name ) { foreach ( $ this -> clientList ( ) as $ client ) { if ( $ client [ "client_nickname" ] == $ name ) return $ client ; } throw new Exception ( "invalid clientID" , 0x200 ) ; }
Returns the Client object matching the given name .
10,052
public function clientGetByUid ( $ uid ) { foreach ( $ this -> clientList ( ) as $ client ) { if ( $ client [ "client_unique_identifier" ] == $ uid ) return $ client ; } throw new Exception ( "invalid clientID" , 0x200 ) ; }
Returns the Client object matching the given unique identifier .
10,053
public function clientGetByDbid ( $ dbid ) { foreach ( $ this -> clientList ( ) as $ client ) { if ( $ client [ "client_database_id" ] == $ dbid ) return $ client ; } throw new Exception ( "invalid clientID" , 0x200 ) ; }
Returns the Client object matching the given database ID .
10,054
public function clientMove ( $ clid , $ cid , $ cpw = null ) { $ this -> clientListReset ( ) ; $ this -> execute ( "clientmove" , array ( "clid" => $ clid , "cid" => $ cid , "cpw" => $ cpw ) ) ; if ( $ clid instanceof Node ) { $ clid = $ clid -> getId ( ) ; } if ( $ cid instanceof Node ) { $ cid = $ cid -> getId ( ) ; } if ( ! is_array ( $ clid ) && $ clid == $ this -> whoamiGet ( "client_id" ) ) { $ this -> getParent ( ) -> whoamiSet ( "client_channel_id" , $ cid ) ; } }
Moves a client to another channel .
10,055
public function serverGroupGetById ( $ sgid ) { if ( ! array_key_exists ( ( string ) $ sgid , $ this -> serverGroupList ( ) ) ) { throw new Exception ( "invalid groupID" , 0xA00 ) ; } return $ this -> sgroupList [ intval ( ( string ) $ sgid ) ] ; }
Returns the Servergroup object matching the given ID .
10,056
public function selectList ( $ meta , ... $ args ) { if ( ! $ args ) { throw new \ InvalidArgumentException ( ) ; } $ fields = null ; $ query = null ; if ( ! isset ( $ args [ 1 ] ) && $ args [ 0 ] instanceof Query \ Select ) { $ query = $ args [ 0 ] ; } elseif ( ( is_array ( $ args [ 0 ] ) || is_string ( $ args [ 0 ] ) ) && ! isset ( $ args [ 2 ] ) ) { $ fields = $ args [ 0 ] ; $ query = isset ( $ args [ 1 ] ) ? $ args [ 1 ] : null ; } else { throw new \ InvalidArgumentException ( ) ; } $ query = $ query instanceof Query \ Select ? $ query : Query \ Select :: fromParamArgs ( [ $ query ] ) ; if ( $ fields ) { $ query -> fields = $ fields ; } if ( ! $ query -> fields ) { throw new \ InvalidArgumentException ( ) ; } $ singleMode = false ; if ( is_string ( $ query -> fields ) ) { $ singleMode = true ; $ query -> fields = [ $ query -> fields ] ; } $ mapper = $ this -> mapper ; $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; list ( $ sql , $ params , $ props ) = $ query -> buildQuery ( $ meta ) ; if ( $ props ) { $ params = $ this -> mapper -> formatParams ( $ meta , $ props , $ params ) ; } $ stmt = $ this -> getConnector ( ) -> prepare ( $ sql ) -> execute ( $ params ) ; $ mappedRows = [ ] ; while ( $ row = $ stmt -> fetch ( \ PDO :: FETCH_ASSOC ) ) { $ mappedRow = $ mapper -> mapRowToProperties ( $ meta , $ row ) ; if ( $ singleMode ) { $ mappedRows [ ] = current ( $ mappedRow ) ; } else { $ mappedRows [ ] = $ mappedRow ; } } return $ mappedRows ; }
Dunno about this . Consider it unstable don t count on it still being here in v6
10,057
public function assignRelated ( $ source , $ relationNames = null , $ meta = null ) { if ( ! $ source ) { return ; } $ stack = [ ] ; $ sourceIsArray = is_array ( $ source ) || $ source instanceof \ Traversable ; if ( ! $ sourceIsArray ) { $ source = array ( $ source ) ; } if ( $ meta !== null ) { $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; } else { $ meta = $ this -> mapper -> getMeta ( get_class ( $ source [ 0 ] ) ) ; } if ( ! $ relationNames ) { if ( $ meta -> autoRelations ) { $ relationNames = $ meta -> autoRelations ; } else { throw new Exception ( "relationNames not passed, class {$meta->class} does not define autoRelations" ) ; } } $ relationMap = [ ] ; foreach ( ( array ) $ relationNames as $ relationName ) { if ( ! isset ( $ meta -> relations [ $ relationName ] ) ) { throw new Exception ( "Unknown relation $relationName on {$meta->class}" ) ; } $ relationMap [ $ relationName ] = $ rel = $ meta -> relations [ $ relationName ] ; if ( $ rel [ 'mode' ] == 'class' ) { throw new Exception ( "Relation $relationName is not assignable for class {$meta->class}" ) ; } } $ done = [ ] ; foreach ( $ relationMap as $ relationName => $ relation ) { if ( isset ( $ done [ $ relationName ] ) ) { continue ; } $ done [ $ relationName ] = true ; $ missing = [ ] ; foreach ( $ source as $ idx => $ item ) { if ( isset ( $ relation [ 'getter' ] ) || ! isset ( $ item -> { $ relationName } ) || ! $ item -> { $ relationName } ) { $ missing [ $ idx ] = $ item ; } } if ( $ missing ) { $ result = $ this -> getRelated ( $ missing , $ relationName , [ 'stack' => $ stack ] , $ meta ) ; $ relator = $ this -> getRelator ( $ meta , $ relationName ) ; $ this -> populateObjectsWithRelated ( $ missing , $ result , $ relation ) ; } } }
Retrieve related objects from the database and assign them to the source if the source field is not yet populated .
10,058
public function getRelated ( $ source , $ relationName , $ query = null , $ meta = null ) { if ( ! $ source ) { return ; } $ sourceIsArray = false ; $ test = $ source ; if ( is_array ( $ test ) || $ test instanceof \ Traversable ) { $ sourceIsArray = true ; $ test = $ test [ 0 ] ; } if ( ! $ meta ) { if ( $ query instanceof Meta ) { list ( $ meta , $ query ) = [ $ query , null ] ; } else { $ meta = $ this -> mapper -> getMeta ( get_class ( $ test ) ) ; } } else { $ meta = $ meta instanceof Meta ? $ meta : $ this -> mapper -> getMeta ( $ meta ) ; } if ( ! isset ( $ meta -> relations [ $ relationName ] ) ) { throw new Exception ( "Unknown relation $relationName on {$meta->class}" ) ; } $ relation = $ meta -> relations [ $ relationName ] ; $ relator = $ this -> getRelator ( $ relation ) ; if ( $ query ) { $ query = $ query instanceof Query \ Criteria ? $ query : Query \ Select :: fromParamArgs ( [ $ query ] ) ; $ stack = $ query -> stack ; } else { $ stack = [ ] ; } $ stack [ $ meta -> class ] = true ; if ( $ sourceIsArray ) { return $ relator -> getRelatedForList ( $ meta , $ source , $ relation , $ query ? : null , $ stack ) ; } else { return $ relator -> getRelated ( $ meta , $ source , $ relation , $ query ? : null , $ stack ) ; } }
Get related objects from the database
10,059
public function insertTable ( $ meta , $ query ) { $ meta = $ meta instanceof Meta ? $ meta : $ this -> mapper -> getMeta ( $ meta ) ; if ( ! $ meta -> canInsert ) { throw new Exception ( "Class {$meta->class} prohibits insert" ) ; } $ query = $ query instanceof Query \ Insert ? $ query : new Query \ Insert ( [ 'values' => $ query ] ) ; $ query -> values = $ this -> mapper -> mapPropertiesToRow ( $ meta , $ query -> values ) ; if ( ! $ query -> table ) { $ query -> table = $ meta -> table ; } list ( $ sql , $ params ) = $ query -> buildQuery ( $ meta ) ; $ stmt = $ this -> getConnector ( ) -> prepare ( $ sql ) ; $ stmt -> execute ( $ params ) ; $ lastInsertId = $ this -> getConnector ( ) -> lastInsertId ( ) ; return $ lastInsertId ; }
Insert values into a table
10,060
public function insert ( $ object , $ meta = null ) { $ query = new Query \ Insert ; if ( is_array ( $ meta ) ) { throw new \ BadMethodCallException ( "Please use insertTable()" ) ; } if ( $ meta ) { $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; } else { $ meta = $ this -> mapper -> getMeta ( get_class ( $ object ) ) ; } if ( ! $ meta -> canInsert ) { throw new Exception ( "Meta {$meta->id} prohibits insert" ) ; } event_before : { if ( isset ( $ meta -> on [ 'beforeInsert' ] ) ) { foreach ( $ meta -> on [ 'beforeInsert' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'beforeInsert' ] ) ) { foreach ( $ this -> on [ 'beforeInsert' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } query : { $ query -> values = $ this -> mapper -> mapObjectToRow ( $ object , $ meta , 'insert' ) ; if ( ! $ query -> table ) { $ query -> table = $ meta -> table ; } list ( $ sql , $ params , $ props ) = $ query -> buildQuery ( $ meta ) ; $ stmt = $ this -> getConnector ( ) -> prepare ( $ sql ) ; $ stmt -> execute ( $ params ) ; } $ lastInsertId = null ; if ( $ object && $ meta -> primary ) { $ lastInsertId = $ this -> getConnector ( ) -> lastInsertId ( ) ; if ( $ lastInsertId && $ meta -> autoinc ) { $ field = $ meta -> fields [ $ meta -> autoinc ] ; $ handler = $ this -> mapper -> determineTypeHandler ( Mapper :: AUTOINC_TYPE ) ; if ( ! $ handler ) { throw new \ UnexpectedValueException ( ) ; } $ meta -> setValue ( $ object , $ meta -> autoinc , $ lastInsertId ) ; } } event_after : { if ( isset ( $ meta -> on [ 'afterInsert' ] ) ) { foreach ( $ meta -> on [ 'afterInsert' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'afterInsert' ] ) ) { foreach ( $ this -> on [ 'afterInsert' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } return $ lastInsertId ; }
Insert an object into the database or values into a table
10,061
public function updateTable ( $ meta , ... $ args ) { $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; if ( ! $ meta -> canUpdate ) { throw new Exception ( "Meta {$meta->id} prohibits update" ) ; } $ query = Query \ Update :: fromParamArgs ( $ args ) ; if ( ! $ query -> set ) { throw new \ InvalidArgumentException ( "Query missing 'set' values" ) ; } list ( $ sql , $ params , $ setProps , $ whereProps ) = $ query -> buildQuery ( $ meta ) ; if ( $ setProps ) { $ params = $ this -> mapper -> formatParams ( $ meta , $ setProps , $ params ) ; } if ( $ whereProps ) { $ params = $ this -> mapper -> formatParams ( $ meta , $ whereProps , $ params ) ; } return $ this -> getConnector ( ) -> exec ( $ sql , $ params ) ; }
Update a table by criteria .
10,062
public function update ( $ object , $ meta = null ) { $ query = new Query \ Update ( ) ; if ( ! is_object ( $ object ) ) { throw new \ BadMethodCallException ( "Please use updateTable()" ) ; } if ( $ meta ) { $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; } else { $ meta = $ this -> mapper -> getMeta ( get_class ( $ object ) ) ; } if ( ! $ meta -> primary ) { throw new Exception ( "Cannot update: meta {$meta->id} has no primary key" ) ; } if ( ! $ meta -> canUpdate ) { throw new Exception ( "Meta {$meta->id} prohibits update" ) ; } event_before : { if ( isset ( $ meta -> on [ 'beforeUpdate' ] ) ) { foreach ( $ meta -> on [ 'beforeUpdate' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'beforeUpdate' ] ) ) { foreach ( $ this -> on [ 'beforeUpdate' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } query : { $ query -> set = $ this -> mapper -> mapObjectToRow ( $ object , $ meta , 'update' ) ; $ query -> where = $ meta -> getIndexValue ( $ object ) ; list ( $ sql , $ params , $ props ) = $ query -> buildQuery ( $ meta ) ; $ return = $ this -> getConnector ( ) -> exec ( $ sql , $ params ) ; } event_after : { if ( isset ( $ meta -> on [ 'afterUpdate' ] ) ) { foreach ( $ meta -> on [ 'afterUpdate' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'afterUpdate' ] ) ) { foreach ( $ this -> on [ 'afterUpdate' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } return $ return ; }
Update an object in the database or update a table by criteria .
10,063
public function deleteTable ( $ meta , ... $ args ) { if ( ! isset ( $ args [ 0 ] ) ) { throw new \ InvalidArgumentException ( "Cannot delete from table without a condition (pass the string '1=1' if you really meant to do this)" ) ; } $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; if ( ! $ meta -> canDelete ) { throw new Exception ( "Meta {$meta->id} prohibits update" ) ; } $ query = Query \ Criteria :: fromParamArgs ( $ args ) ; return $ this -> executeDelete ( $ meta , $ query ) ; }
Delete from a table by criteria
10,064
public function delete ( $ object , $ meta = null ) { $ query = new Query \ Criteria ( ) ; if ( ! is_object ( $ object ) ) { throw new \ BadMethodCallException ( "Please use deleteTable()" ) ; } if ( $ meta ) { $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; } else { $ meta = $ this -> mapper -> getMeta ( get_class ( $ object ) ) ; } if ( ! $ meta -> canDelete ) { throw new Exception ( "Meta {$meta->id} prohibits delete" ) ; } event_before : { if ( isset ( $ meta -> on [ 'beforeDelete' ] ) ) { foreach ( $ meta -> on [ 'beforeDelete' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'beforeDelete' ] ) ) { foreach ( $ this -> on [ 'beforeDelete' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } $ query -> where = $ meta -> getIndexValue ( $ object ) ; $ return = $ this -> executeDelete ( $ meta , $ query ) ; event_after : { if ( isset ( $ meta -> on [ 'afterDelete' ] ) ) { foreach ( $ meta -> on [ 'afterDelete' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'afterDelete' ] ) ) { foreach ( $ this -> on [ 'afterDelete' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } return $ return ; }
Delete an object from the database
10,065
public function save ( $ object , $ meta = null ) { if ( $ meta ) { $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; } else { $ meta = $ this -> mapper -> getMeta ( get_class ( $ object ) ) ; } if ( ! $ meta -> primary ) { throw new Exception ( "No primary key for {$meta->id}" ) ; } $ shouldInsert = null ; $ prival = null ; if ( $ meta -> autoinc ) { $ prival = $ meta -> getValue ( $ object , $ meta -> autoinc ) ; $ shouldInsert = ! $ prival ; } else { $ prival = $ meta -> getIndexValue ( $ object ) ; } event_before : { if ( isset ( $ meta -> on [ 'beforeSave' ] ) ) { foreach ( $ meta -> on [ 'beforeSave' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'beforeSave' ] ) ) { foreach ( $ this -> on [ 'beforeSave' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } if ( $ shouldInsert === null ) { $ newpri = $ meta -> getIndexValue ( $ object ) ; $ shouldInsert = $ newpri != $ prival ; } if ( $ shouldInsert ) { $ this -> insert ( $ object , $ meta ) ; } else { $ this -> update ( $ object , $ meta ) ; } event_after : { if ( isset ( $ meta -> on [ 'afterSave' ] ) ) { foreach ( $ meta -> on [ 'afterSave' ] as $ cb ) { $ cb = [ $ object , $ cb ] ; $ cb ( ) ; } } if ( isset ( $ this -> on [ 'afterSave' ] ) ) { foreach ( $ this -> on [ 'afterSave' ] as $ cb ) { $ cb ( $ object , $ meta ) ; } } } }
If an object has an autoincrement primary key insert or update as necessary .
10,066
public function createKeyCriteria ( $ meta , $ id , $ indexId = null ) { if ( $ indexId == null ) { $ indexId = 'primary' ; } $ meta = ! $ meta instanceof Meta ? $ this -> mapper -> getMeta ( $ meta ) : $ meta ; if ( ! isset ( $ meta -> indexes [ $ indexId ] ) ) { throw new Exception ( "Index $indexId does not exist on meta {$meta->id}" ) ; } $ index = $ meta -> indexes [ $ indexId ] ; if ( ! $ index [ 'key' ] ) { throw new Exception ( "Index $indexId is not a key index for meta {$meta->id}" ) ; } if ( ! is_array ( $ id ) ) { $ id = array ( $ id ) ; } $ where = array ( ) ; foreach ( $ index [ 'fields' ] as $ idx => $ p ) { $ idVal = isset ( $ id [ $ p ] ) ? $ id [ $ p ] : ( isset ( $ id [ $ idx ] ) ? $ id [ $ idx ] : null ) ; if ( ! $ idVal ) { throw new \ InvalidArgumentException ( "Couldn't get ID value when getting {$meta->id} by index '{$indexId}'" ) ; } $ where [ $ p ] = $ idVal ; } return array ( 'where' => $ where ) ; }
Creates an array criteria for a key index
10,067
public function next ( $ is_string = false ) { $ package = '' ; while ( true ) { if ( $ this -> pointer >= $ this -> length ) { return false ; } $ string = $ this -> string [ $ this -> pointer ] ; $ this -> pointer ++ ; if ( $ is_string === true ) { return ord ( $ string ) ; } $ value = decbin ( ord ( $ string ) ) ; if ( $ value >= 10000000 && $ is_string === false ) { $ package .= $ value ; } else { $ value = substr ( '00000000' , 0 , 8 - strlen ( $ value ) % 8 ) . $ value ; return $ this -> base128 -> getValue ( $ package . $ value ) ; } } return $ package ; }
get the next
10,068
public static function registerAutoload ( $ base_namespace , $ base_path , $ extension = '.php' ) { spl_autoload_register ( function ( $ class_name ) use ( $ base_namespace , $ base_path , $ extension ) { $ file_path = self :: getFilePathForClassName ( $ class_name , $ base_namespace , $ base_path , $ extension ) ; if ( $ file_path ) { require_once $ file_path ; } } ) ; }
For Autoload File
10,069
public static function removeFromArray ( & $ array , $ keychain ) { if ( ! is_array ( $ array ) ) { $ array = [ ] ; } if ( ! is_array ( $ keychain ) ) { $ keychain = [ $ keychain ] ; } $ headKey = array_shift ( $ keychain ) ; if ( empty ( $ keychain ) ) { unset ( $ array [ $ headKey ] ) ; } else { if ( isset ( $ array [ $ headKey ] ) ) { self :: removeFromArray ( $ array [ $ headKey ] , $ keychain ) ; } } }
Unset item and nested item in array
10,070
public function wd ( $ dir = null , $ code = E_USER_WARNING ) { if ( null !== $ dir && is_dir ( $ dir ) ) { $ this -> wd = $ dir ; if ( chdir ( $ dir ) === false ) { throw new \ Exception ( 'Cannot change to directory ' . $ dir . ' in ' . __METHOD__ , $ code ) ; return $ this ; } } else { $ dir = $ this -> wd ; } return $ this ; }
set working directory
10,071
protected function formatJSON ( SS_List $ list ) { $ ret = array ( ) ; foreach ( $ list as $ item ) { $ ret [ ] = array ( 'id' => $ item -> { $ this -> idField } , 'label' => $ item -> { $ this -> labelField } ) ; } return Convert :: array2json ( $ ret ) ; }
Formats JSON so that it is usable by the JS component
10,072
public function query ( SS_HTTPRequest $ r ) { return $ this -> formatJSON ( $ this -> source -> filter ( array ( $ this -> labelField . ':PartialMatch' => $ r -> getVar ( 'q' ) ) ) -> limit ( 10 ) ) ; }
An AJAX endpoint for querying the typeahead
10,073
protected function getValuesJSON ( ) { $ value = $ this -> value ; if ( $ value instanceof SS_List ) { $ values = $ value -> column ( $ this -> idField ) ; } else if ( is_array ( $ value ) ) { $ values = array_keys ( $ value ) ; } else if ( is_string ( $ value ) ) { $ values = explode ( ',' , $ value ) ; $ values = str_replace ( '{comma}' , ',' , $ values ) ; } return $ this -> formatJSON ( $ this -> source -> filter ( array ( $ this -> idField => $ values ) ) ) ; }
Gets the current values assigned to the field formatted as a JSON array
10,074
public function setPrefetch ( SS_List $ list ) { if ( ! $ list instanceof SS_List ) { throw new Exception ( 'Prefetch list must be an instance of SS_List' ) ; } $ this -> prefetch = $ list ; return $ this ; }
Sets the prefetch records list
10,075
public function Field ( $ properties = array ( ) ) { Requirements :: javascript ( BOOTSTRAP_TAGFIELD_DIR . '/javascript/typeahead.js' ) ; Requirements :: javascript ( BOOTSTRAP_TAGFIELD_DIR . '/javascript/bootstrap-tagfield.js' ) ; Requirements :: javascript ( BOOTSTRAP_TAGFIELD_DIR . '/javascript/bootstrap-tagfield-init.js' ) ; Requirements :: css ( BOOTSTRAP_TAGFIELD_DIR . '/css/bootstrap-tagfield.css' ) ; $ this -> setAttribute ( 'data-value' , $ this -> getValuesJSON ( ) ) -> setAttribute ( 'data-bootstrap-tags' , true ) -> setAttribute ( 'data-query-url' , $ this -> Link ( 'query' ) ) -> setAttribute ( 'data-prefetch-url' , $ this -> Link ( 'prefetch' ) ) -> setAttribute ( 'data-freeinput' , $ this -> freeInput ) -> setAttribute ( 'class' , 'text' ) ; return $ this -> renderWith ( $ this -> getTemplates ( ) ) ; }
Renders the field
10,076
public function parse ( $ input ) { if ( strlen ( $ input ) == 0 ) { return null ; } return $ this -> parser -> parse ( new TokenStream ( $ this -> tokenizer -> getTokens ( $ input ) ) ) ; }
Parses the raw string input and returns the resulting root node .
10,077
public function compile ( $ input ) { if ( strlen ( $ input ) == 0 ) { return null ; } try { $ buffer = new Buffer ( ) ; $ this -> parse ( $ input ) -> compile ( $ buffer ) ; $ code = $ buffer -> getResult ( ) ; return $ code ; } catch ( \ UnexpectedValueException $ e ) { throw new \ UnexpectedValueException ( 'Error while compiling input: ' . Util :: toPhp ( $ input ) , 0 , $ e ) ; } }
Compile an input string to PHP code
10,078
protected function unlock ( string $ key ) { if ( ! isset ( $ this -> locks [ $ key ] ) ) { throw new InvalidArgumentError ( 'No lock was set on the given key.' ) ; } $ awaitable = $ this -> locks [ $ key ] ; unset ( $ this -> locks [ $ key ] ) ; $ awaitable -> resolve ( ) ; }
Unlocks the given key . Throws if the key was not locked .
10,079
private function _warmup ( ) { $ warmup = new Test ( 'warmup' , function ( ) { } ) ; $ this -> _overhead = $ warmup -> runTest ( $ this -> _count ) ; foreach ( $ this -> _tests as $ test ) { $ test -> runTest ( 1 ) ; } $ this -> out ( 'PHP Overhead: ' . 'time=' . Timer :: formatMS ( $ this -> _overhead [ 'time' ] ) . '; ' . 'memory=' . FS :: format ( $ this -> _overhead [ 'memory' ] , 2 ) . ';' . PHP_EOL ) ; }
Runs an empty test to determine the benchmark overhead and run each test once
10,080
public function outputTable ( array $ lines , $ padding = 4 ) { $ pad = function ( $ string , $ width ) use ( $ padding ) { if ( $ width > 0 ) { return str_pad ( $ string , $ width , ' ' ) . str_repeat ( ' ' , $ padding ) ; } else { return str_pad ( $ string , - $ width , ' ' , STR_PAD_LEFT ) . str_repeat ( ' ' , $ padding ) ; } } ; $ cols = array_combine ( array_keys ( $ lines [ 0 ] ) , array_map ( 'strlen' , array_keys ( $ lines [ 0 ] ) ) ) ; foreach ( $ cols as $ col => $ width ) { foreach ( $ lines as $ line ) { $ width = max ( $ width , strlen ( $ line [ $ col ] ) ) ; } if ( $ col !== self :: COL_NAME ) { $ width = - $ width ; } $ this -> out ( $ pad ( $ col , $ width ) , false ) ; $ cols [ $ col ] = $ width ; } $ this -> out ( '' ) ; foreach ( $ lines as $ line ) { foreach ( $ cols as $ col => $ width ) { $ this -> out ( $ pad ( $ line [ $ col ] , $ width ) , false ) ; } $ this -> out ( '' ) ; } }
Output results in columns padding right if values are string left if numeric
10,081
public function formatResults ( array $ results ) { uasort ( $ results [ 'list' ] , function ( $ testOne , $ testTwo ) { if ( $ testOne [ 'time' ] === $ testTwo [ 'time' ] ) { return 0 ; } else { return ( $ testOne [ 'time' ] < $ testTwo [ 'time' ] ) ? - 1 : 1 ; } } ) ; $ minTime = INF ; $ minMemory = INF ; foreach ( $ results [ 'list' ] as $ name => $ result ) { $ time = $ result [ 'time' ] ; $ results [ 'list' ] [ $ name ] [ 'time' ] = $ time ; $ minTime = min ( $ minTime , $ time ) ; $ memory = $ results [ 'list' ] [ $ name ] [ 'memory' ] ; $ memory -= $ this -> _overhead [ 'memory' ] ; $ results [ 'list' ] [ $ name ] [ 'memory' ] = $ memory ; $ minMemory = min ( $ minMemory , $ memory ) ; } $ output = array ( ) ; $ isOne = count ( $ results [ 'list' ] ) === 1 ; foreach ( $ results [ 'list' ] as $ name => $ result ) { if ( $ isOne ) { $ output [ ] = array ( self :: COL_NAME => $ name , self :: COL_TIME => $ this -> _timeFormat ( $ result [ 'time' ] , 0 ) , self :: COL_TIME_ONE => $ this -> _timeFormat ( $ result [ 'time' ] / $ this -> _count ) , self :: COL_MEMORY => FS :: format ( $ result [ 'memory' ] , 2 ) , ) ; } else { $ output [ ] = array ( self :: COL_NAME => $ name , self :: COL_TIME => $ this -> _timeFormat ( $ result [ 'time' ] , 0 ) , self :: COL_TIME_ONE => $ this -> _timeFormat ( $ result [ 'time' ] / $ this -> _count ) , self :: COL_TIME_REL => Vars :: relativePercent ( $ minTime , $ result [ 'time' ] ) , self :: COL_MEMORY => FS :: format ( $ result [ 'memory' ] , 2 ) , self :: COL_MEMORY_REL => Vars :: relativePercent ( $ minMemory , $ result [ 'memory' ] ) , ) ; } } return $ output ; }
Format the results rounding numbers showing difference percentages and removing a flat time based on the benchmark overhead
10,082
protected function shouldSelect ( array $ columns = [ '*' ] ) { if ( $ columns === [ '*' ] ) { $ columns = [ $ this -> related -> getTable ( ) . '.*' ] ; } return array_merge ( $ columns , $ this -> aliasedPivotColumns ( ) ) ; }
Get the select columns for the relation query .
10,083
public function getProxyServer ( ) { $ proxy_options = $ this -> getOption ( EnumRequestOption :: PROXY_OPTIONS , [ ] ) ; return isset ( $ proxy_options [ EnumProxyOption :: PROXY_SERVER ] ) ? $ proxy_options [ EnumProxyOption :: PROXY_SERVER ] : '' ; }
Returns proxy server
10,084
public function getProxyPort ( ) { $ proxy_options = $ this -> getOption ( EnumRequestOption :: PROXY_OPTIONS , [ ] ) ; return isset ( $ proxy_options [ EnumProxyOption :: PROXY_PORT ] ) ? $ proxy_options [ EnumProxyOption :: PROXY_PORT ] : '' ; }
Returns proxy port
10,085
public function getProxyType ( ) { $ proxy_options = $ this -> getOption ( EnumRequestOption :: PROXY_OPTIONS , [ ] ) ; return isset ( $ proxy_options [ EnumProxyOption :: PROXY_TYPE ] ) ? $ proxy_options [ EnumProxyOption :: PROXY_TYPE ] : 'http' ; }
Returns proxy type
10,086
public function getProxyAuth ( ) { $ proxy_options = $ this -> getOption ( EnumRequestOption :: PROXY_OPTIONS , [ ] ) ; return isset ( $ proxy_options [ EnumProxyOption :: PROXY_AUTH ] ) ? $ proxy_options [ EnumProxyOption :: PROXY_AUTH ] : null ; }
Returns proxy auth
10,087
protected function build_input ( $ data , array $ fields = [ ] ) { $ fields = implode ( ' ' , $ fields ) ; return sprintf ( '<textarea id="%1$s" name="%1$s" %2$s>%3$s</textarea>%4$s' , $ this -> name , $ fields , esc_textarea ( $ data ) , $ this -> length_helper ( $ data ) ) ; }
Make input field
10,088
public function resolve ( $ route , $ req , $ res , array $ args ) { $ result = false ; if ( is_array ( $ route ) || is_string ( $ route ) ) { if ( is_string ( $ route ) && $ req -> params ( 'controller' ) ) { $ route = [ $ req -> params ( 'controller' ) , $ route ] ; } elseif ( is_string ( $ route ) ) { $ route = [ $ this -> defaultController , $ route ] ; } elseif ( count ( $ route ) == 1 ) { $ route [ ] = $ this -> defaultAction ; } list ( $ controller , $ method ) = $ route ; $ controller = $ this -> namespace . '\\' . $ controller ; if ( ! class_exists ( $ controller ) ) { throw new \ Exception ( "Controller does not exist: $controller" ) ; } $ controllerObj = new $ controller ( ) ; if ( method_exists ( $ controllerObj , 'setApp' ) ) { $ controllerObj -> setApp ( $ this -> app ) ; } if ( isset ( $ route [ 2 ] ) ) { $ params = $ route [ 2 ] ; $ req -> setParams ( $ params ) ; } $ result = $ controllerObj -> $ method ( $ req , $ res , $ args ) ; } elseif ( is_callable ( $ route ) ) { $ result = call_user_func ( $ route , $ req , $ res , $ args ) ; } if ( $ result instanceof View ) { $ res -> render ( $ result ) ; } return $ res ; }
Executes a route handler .
10,089
public function convert ( \ DOMElement $ parent , InterfaceDescriptor $ interface ) { $ child = new \ DOMElement ( 'interface' ) ; $ parent -> appendChild ( $ child ) ; foreach ( $ interface -> getParent ( ) as $ parentInterface ) { $ parentFqcn = is_string ( $ parentInterface ) === false ? $ parentInterface -> getFullyQualifiedStructuralElementName ( ) : $ parentInterface ; $ child -> appendChild ( new \ DOMElement ( 'extends' , $ parentFqcn ) ) ; } $ namespace = $ interface -> getNamespace ( ) -> getFullyQualifiedStructuralElementName ( ) ; $ child -> setAttribute ( 'namespace' , ltrim ( $ namespace , '\\' ) ) ; $ child -> setAttribute ( 'line' , $ interface -> getLine ( ) ) ; $ child -> appendChild ( new \ DOMElement ( 'name' , $ interface -> getName ( ) ) ) ; $ child -> appendChild ( new \ DOMElement ( 'full_name' , $ interface -> getFullyQualifiedStructuralElementName ( ) ) ) ; $ this -> docBlockConverter -> convert ( $ child , $ interface ) ; foreach ( $ interface -> getConstants ( ) as $ constant ) { $ this -> constantConverter -> convert ( $ child , $ constant ) ; } foreach ( $ interface -> getMethods ( ) as $ method ) { $ this -> methodConverter -> convert ( $ child , $ method ) ; } return $ child ; }
Export the given reflected interface definition to the provided parent element .
10,090
private function handle ( $ key , ChildProcessContainer $ child ) { $ tube = $ this -> tube ; $ child -> processOutput ( 'child_' . $ tube . $ key ) ; if ( ! $ child -> checkHealth ( ) ) { $ child -> getReadyForBed ( ) ; } $ readyStatusses = array ( ChildProcessContainer :: STATUS_READY , ChildProcessContainer :: STATUS_ALIVE ) ; if ( $ child -> getAge ( ) >= $ this -> input -> getOption ( 'max-worker-age' ) && in_array ( $ child -> status , $ readyStatusses ) ) { $ child -> bedtime ( ) ; } if ( $ child -> getBufferLength ( ) >= $ this -> input -> getOption ( 'max-worker-buffer' ) && in_array ( $ child -> status , $ readyStatusses ) ) { $ child -> bedtime ( ) ; } if ( $ child -> isDead ( ) ) { $ child -> cleanUp ( ) ; } if ( $ child -> isCleanedUp ( ) ) { $ this -> verboseOutput ( "<info>Unsetting Child</info>: $key" ) ; unset ( $ this -> family [ $ key ] ) ; $ this -> verboseOutput ( "<info>Children left</info>: " . count ( $ this -> family ) ) ; } }
Handles all child communication things
10,091
private function familyPlanning ( ) { list ( $ total , $ available ) = $ this -> countWorkers ( ) ; if ( $ this -> shutdownGracefully ) { if ( $ total > 0 ) { $ this -> verboseOutput ( "<info>Shutting down</info> $total remaining children" ) ; foreach ( $ this -> family as $ cnr => $ child ) { $ this -> verboseOutput ( "<info>Child: $cnr </info>" . $ child -> status ) ; } $ this -> tellChildrenToPrepareForBed ( ) ; } else { $ this -> keepWorking = false ; } return ; } list ( $ shouldHaveLessWorkers , $ shouldHaveMoreWorkers ) = $ this -> moreOrLess ( $ total , $ available ) ; if ( $ shouldHaveMoreWorkers ) { $ this -> family [ ] = $ this -> spawnChild ( ) ; } if ( $ shouldHaveLessWorkers ) { if ( $ this -> findDisposableWorkers ( ) ) { $ this -> verboseOutput ( "<info>Found a disposable worker</info>" ) ; } } }
Produce more hands for the work needed
10,092
public function countWorkers ( ) { $ total = count ( $ this -> family ) ; $ busy = 0 ; $ available = 0 ; foreach ( $ this -> family as & $ child ) { switch ( $ child -> status ) { case ChildProcessContainer :: STATUS_ALIVE : case ChildProcessContainer :: STATUS_READY : $ available ++ ; break ; case ChildProcessContainer :: STATUS_BUSY : case ChildProcessContainer :: STATUS_BUSY_BUT_SLEEPY : $ busy ++ ; break ; } } return array ( $ total , $ available ) ; }
Returns an array with the worker counts
10,093
public function moreOrLess ( $ total , $ available ) { $ shouldHaveMoreWorkers = false ; $ shouldHaveLessWorkers = false ; $ minWorkers = $ this -> input -> getOption ( 'min-workers' ) ; $ maxWorkers = $ this -> input -> getOption ( 'max-workers' ) ; $ spareWorkers = $ this -> input -> getOption ( 'spare-workers' ) ; if ( $ total < $ minWorkers ) { $ shouldHaveMoreWorkers = true ; $ this -> verboseOutput ( "<info>Too little workers</info>: $total / $minWorkers" ) ; } elseif ( ( $ available < $ spareWorkers ) && ( $ total <= $ maxWorkers ) ) { $ shouldHaveMoreWorkers = true ; $ this -> verboseOutput ( "<info>Too little spare workers</info>: $available / $spareWorkers" ) ; } elseif ( $ total >= $ maxWorkers ) { $ shouldHaveLessWorkers = true ; } elseif ( $ available >= $ minWorkers + $ spareWorkers && ! $ shouldHaveMoreWorkers ) { $ shouldHaveLessWorkers = true ; } return array ( $ shouldHaveLessWorkers , $ shouldHaveMoreWorkers ) ; }
Returns two booleans if there should be more or less workers
10,094
private function findDisposableWorkers ( ) { $ disposableStatusses = array ( ChildProcessContainer :: STATUS_READY , ChildProcessContainer :: STATUS_ALIVE ) ; foreach ( $ this -> family as & $ child ) { if ( in_array ( $ child -> status , $ disposableStatusses ) ) { if ( $ child -> getAge ( ) < 10 ) { continue ; } $ child -> bedTime ( ) ; return true ; } } return false ; }
Finds disposable workers if it finds them it returns true
10,095
private function spawnChild ( ) { $ child = new ChildProcessContainer ( $ this -> consolePath , $ this -> input -> getOption ( 'worker-command' ) , $ this -> tube , $ this ) ; $ child -> start ( ) ; return $ child ; }
Spawns a new child
10,096
protected function createEventObject ( $ eventName , array $ data ) { if ( ! array_key_exists ( $ eventName , $ this -> options [ 'events' ] ) ) { throw new \ InvalidArgumentException ( 'Event is not defined.' ) ; } $ namespace = $ this -> options [ 'events' ] [ $ eventName ] [ 'object' ] ; $ instance = new $ namespace ( $ eventName , $ data ) ; if ( ! ( $ instance instanceof EventInterface ) ) { throw new \ LogicException ( 'Invalid interface of event object' ) ; } return $ instance ; }
return event object or create it if not exist
10,097
public function triggerEvent ( $ name , array $ data = [ ] ) { try { $ event = $ this -> createEventObject ( $ name , $ data ) ; } catch ( \ InvalidArgumentException $ exception ) { return $ this ; } foreach ( $ this -> options [ 'events' ] [ $ name ] [ 'listeners' ] as $ eventListener ) { if ( $ event -> isPropagationStopped ( ) ) { $ this -> loggerInstance -> makeLogEvent ( $ name , $ eventListener , self :: EVENT_STATUS_BREAK ) ; break ; } $ this -> executeListener ( $ eventListener , $ event , $ name ) ; } return $ this ; }
trigger new event with automatic call all subscribed listeners
10,098
public function addEventListener ( $ eventName , array $ listeners ) { if ( ! array_key_exists ( $ eventName , $ this -> options [ 'events' ] ) ) { $ this -> options [ 'events' ] [ $ eventName ] = [ 'object' => BaseEvent :: class , 'listeners' => $ listeners , ] ; } $ this -> options [ 'events' ] [ $ eventName ] [ 'listeners' ] = array_merge ( $ this -> options [ 'events' ] [ $ eventName ] [ 'listeners' ] , $ listeners ) ; return $ this ; }
dynamically add new listener or listeners for given event name listeners are added at end of the list
10,099
public function readEventConfiguration ( $ path , $ type ) { if ( ! file_exists ( $ path ) ) { throw new \ InvalidArgumentException ( 'File ' . $ path . 'don\'t exists.' ) ; } $ name = '\BlueEvent\Event\Config\\' . ucfirst ( $ type ) . 'Config' ; if ( ! class_exists ( $ name ) ) { throw new \ InvalidArgumentException ( 'Incorrect configuration type: ' . $ type ) ; } $ reader = new $ name ; return $ this -> setEventConfiguration ( $ reader -> readConfig ( $ path ) ) ; }
read configuration from file