idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
28,700
public function getReportLoader ( $ attachAssetUrl = null , $ assetRoute = null , $ routeParameters = null ) { $ attachAssetUrl = $ attachAssetUrl ? : $ this -> defaultAttachAssetUrl ; $ assetRoute = $ assetRoute ? : $ this -> defaultAssetRoute ; $ routeParameters = $ routeParameters ? : $ this -> routeParameters ; $ routeParameters [ 'asset' ] = '!asset!' ; $ routeParameters [ 'requestId' ] = '!requestId!' ; if ( $ attachAssetUrl ) { $ assetUrl = $ this -> router -> generate ( $ assetRoute , $ routeParameters ) ; } return new ReportLoader ( $ this -> reportCacheDir , $ attachAssetUrl , $ assetUrl , $ this -> defaultPage ) ; }
Builds a report loader with the given parameters
28,701
public function setRouter ( Symfony \ Component \ Routing \ Router $ router ) { $ this -> router = $ router ; return $ this ; }
Sets the Reference to Symfony s routing service .
28,702
public function generatePageLinks ( $ url , $ currentPage , $ lastPage , $ options = array ( ) ) { $ idTemplate = ( isset ( $ options [ 'idTemplate' ] ) && null != $ options [ 'idTemplate' ] ) ? $ options [ 'idTemplate' ] : null ; $ classes = ( isset ( $ options [ 'classes' ] ) && null != $ options [ 'classes' ] ) ? $ options [ 'classes' ] : array ( ) ; $ currentPageClass = ( isset ( $ options [ 'currentPageClass' ] ) && null != $ options [ 'currentPageClass' ] ) ? $ options [ 'currentPageClass' ] : '' ; $ this -> links -> push ( $ this -> createPageLink ( $ url , 1 , $ currentPage , $ idTemplate , $ classes , $ currentPageClass ) ) ; if ( $ currentPage - 2 > 1 ) { $ firstBreak = new PageLink ( '...' ) ; $ firstBreak -> setDisabled ( true ) ; $ this -> links -> push ( $ firstBreak ) ; } if ( $ currentPage - 10 > 1 ) { $ this -> links -> push ( $ this -> createPageLink ( $ url , $ currentPage - 10 , $ currentPage , $ idTemplate , $ classes , $ currentPageClass ) ) ; } if ( $ currentPage - 1 > 1 ) { $ this -> links -> push ( $ this -> createPageLink ( $ url , $ currentPage - 1 , $ currentPage , $ idTemplate , $ classes , $ currentPageClass ) ) ; } if ( $ currentPage > 1 ) { $ this -> links -> push ( $ this -> createPageLink ( $ url , $ currentPage , $ currentPage , $ idTemplate , $ classes , $ currentPageClass ) ) ; } if ( $ currentPage + 1 < $ lastPage ) { $ this -> links -> push ( $ this -> createPageLink ( $ url , $ currentPage + 1 , $ currentPage , $ idTemplate , $ classes , $ currentPageClass ) ) ; } if ( $ currentPage + 10 < $ lastPage ) { $ this -> links -> push ( $ this -> createPageLink ( $ url , $ currentPage + 10 , $ currentPage , $ idTemplate , $ classes , $ currentPageClass ) ) ; } if ( $ currentPage + 2 < $ lastPage ) { $ lastBreak = new PageLink ( '...' ) ; $ lastBreak -> setDisabled ( true ) ; $ this -> links -> push ( $ lastBreak ) ; } if ( $ currentPage < $ lastPage ) { $ this -> links -> push ( $ this -> createPageLink ( $ url , $ lastPage , $ currentPage , $ idTemplate , $ classes , $ currentPageClass ) ) ; } return $ this ; }
Generates an array of page link objects using a url template and the current page number and stores them in this object
28,703
protected function createPageLink ( $ url , $ page , $ currentPage , $ idTemplate = null , $ classes = array ( ) , $ currentPageClass = '' ) { if ( $ page == $ currentPage ) { $ classes [ ] = $ currentPageClass ; $ disabled = true ; } else { $ disabled = false ; } $ pageUrl = str_replace ( '!page!' , ( string ) $ page , $ url ) ; if ( $ idTemplate ) { $ id = str_replace ( '!page!' , ( string ) $ page , $ idTemplate ) ; } else { $ id = null ; } return new PageLink ( ( string ) $ page , $ pageUrl , $ id , $ classes , $ disabled ) ; }
Helper function for the generate Page links that combines the parameters and creates a new page link
28,704
public function printLinks ( $ delimiter = null ) { if ( $ delimiter ) { $ temp = $ this -> delimiter ; $ this -> delimiter = $ delimiter ; $ return = $ this -> __toString ( ) ; $ this -> delimiter = $ temp ; return $ return ; } else { return $ this -> __toString ( ) ; } }
Prints the links that this manager contains seperated by some delimiter
28,705
public function toArray ( ) { $ return = array ( ) ; $ this -> links -> setIteratorMode ( \ SplDoublyLinkedList :: IT_MODE_FIFO ) ; for ( $ this -> links -> rewind ( ) ; $ this -> links -> valid ( ) ; $ this -> links -> next ( ) ) { $ return [ ] = $ this -> links -> current ( ) ; } return $ return ; }
Converts the data in the manager to an array using the FIFO iterator mode
28,706
public function addPageLink ( PageLink $ link , $ index = null ) { if ( $ index ) { $ this -> links -> add ( $ index , $ link ) ; } else { $ this -> links -> push ( $ link ) ; } return $ this -> links -> count ( ) ; }
Inserts a new page link into the list
28,707
public function removePageLink ( $ index = null ) { if ( $ index ) { $ return = $ this -> links -> offsetGet ( $ index ) ; $ this -> links -> offsetUnset ( $ index ) ; return $ return ; } else { return $ this -> links -> pop ( ) ; } }
Removes a page link from the list
28,708
public function isValid ( ) { if ( empty ( $ this -> token ) || empty ( $ this -> payerId ) || is_null ( $ this -> _paymentDetails ) ) { return false ; } $ valid = true ; foreach ( $ this -> _paymentDetails as $ detail ) { if ( empty ( $ detail ) ) { $ valid = false ; break ; } $ amt = $ detail -> getAmt ( ) ; if ( empty ( $ amt ) ) { $ valid = false ; break ; } } return $ valid ; }
Test the minimum required values for doExpressCheckoutPayment
28,709
public function authenticate ( IRequest $ request ) { $ tokenType = $ this -> tokenTypeResolver -> resolve ( $ request ) ; $ accessToken = $ this -> accessTokenStorage -> get ( $ tokenType -> getAccessToken ( ) ) ; if ( ! $ accessToken ) { throw new NotAuthenticatedException ; } return new Session ( $ accessToken ) ; }
Authenticates current request and returns session
28,710
public function redirect ( $ url , $ useUrl = true , $ httpCode = 302 ) { Atomik :: fireEvent ( 'Atomik::Redirect' , array ( & $ url , & $ useUrl , & $ httpCode ) ) ; if ( $ url === false ) { return ; } if ( $ useUrl ) { $ url = Atomik :: url ( $ url ) ; } if ( isset ( $ _SESSION ) ) { $ session = $ _SESSION ; session_regenerate_id ( true ) ; $ _SESSION = $ session ; session_write_close ( ) ; } header ( 'Location: ' . $ url , true , $ httpCode ) ; Atomik :: end ( true , false ) ; }
Redirects to another url
28,711
protected function _configureColumns ( ) { if ( empty ( $ this -> columns ) ) { $ this -> guessColumns ( ) ; } $ this -> _sourceColumns = $ this -> columns ; ; $ columnsByKey = [ ] ; foreach ( $ this -> columns as $ column ) { $ columnKey = $ this -> _getColumnKey ( $ column ) ; for ( $ j = 0 ; true ; $ j ++ ) { $ suffix = ( $ j ) ? '_' . $ j : '' ; $ columnKey .= $ suffix ; if ( ! array_key_exists ( $ columnKey , $ columnsByKey ) ) { break ; } } $ columnsByKey [ $ columnKey ] = $ column ; } $ this -> columns = $ columnsByKey ; }
Reconfigure columns with unique keys
28,712
protected function _getColumnKey ( $ column ) { if ( ! is_array ( $ column ) ) { $ matches = $ this -> _matchColumnString ( $ column ) ; $ columnKey = $ matches [ 1 ] ; } elseif ( ! empty ( $ column [ 'attribute' ] ) ) { $ columnKey = $ column [ 'attribute' ] ; } elseif ( ! empty ( $ column [ 'label' ] ) ) { $ columnKey = $ column [ 'label' ] ; } elseif ( ! empty ( $ column [ 'header' ] ) ) { $ columnKey = $ column [ 'header' ] ; } elseif ( ! empty ( $ column [ 'class' ] ) ) { $ columnKey = $ column [ 'class' ] ; } else { $ columnKey = null ; } return hash ( 'crc32' , $ columnKey ) ; }
Generate an unique column key
28,713
protected function _matchColumnString ( $ column ) { $ matches = [ ] ; if ( ! preg_match ( '/^([\w\.]+)(:(\w*))?(:(.*))?$/' , $ column , $ matches ) ) { throw new InvalidConfigException ( \ Yii :: t ( 'skeeks/cms' , "Invalid column configuration for '{column}'. The column must be specified in the format of 'attribute', 'attribute:format' or 'attribute:format: label'." , [ 'column' => $ column ] ) ) ; } return $ matches ; }
Finds the matches for a string column format
28,714
public function connectionTo ( $ key , $ database ) { Config :: set ( "database.connections.{$key}.database" , $ database ) ; $ this -> reconnect ( $ key , $ database ) ; }
Method that changes specific custom connection database with another .
28,715
protected function reconnect ( $ key , $ database ) { $ connections = DB :: getConnections ( ) ; $ connection = isset ( $ connections [ $ key ] ) ? $ connections [ $ key ] : '' ; if ( is_object ( $ connection ) && $ connection -> getDatabaseName ( ) != $ database ) { $ connection -> setDatabaseName ( $ database ) ; $ connection -> reconnect ( ) ; } }
Changes platform active connection database name and reconnect to it .
28,716
public function registerViewLoader ( ) { $ this -> app -> bind ( 'view.loader' , function ( $ app ) { $ filesystemLoader = new FilesystemLoader ( $ app [ 'files' ] ) ; $ vpageLoader = new VpageLoader ( ) ; $ chainLoader = new ChainLoader ( ) ; $ chainLoader -> addLoader ( $ vpageLoader ) ; $ chainLoader -> addLoader ( $ filesystemLoader ) ; return $ chainLoader ; } ) ; }
Register the view loader implementation .
28,717
public function authorize ( IRequest $ request , IUser $ user ) { $ grantType = $ this -> grantTypeResolver -> resolve ( $ request ) ; if ( ! $ grantType instanceof IAuthorizationGrantType ) { throw new UnsupportedResponseTypeException ; } return $ grantType -> authorize ( $ request , $ user ) ; }
Authorizes request using grant type with authorization
28,718
public function getActiveUsers ( ) { $ data = $ this -> call ( 'apps/' . $ this -> appId . '/activeusers' , [ ] , 'get' ) ; $ array = [ ] ; foreach ( $ data as $ msg ) { $ array [ ] = User :: fromResponse ( $ msg ) ; } return $ array ; }
Get all active users in application . User is active when his status is online .
28,719
public function getLeads ( $ filters = [ ] , $ prop = '$last_seen' , $ order = 'desc' , $ limit = 20 , $ offset = 0 ) { $ params = [ 'filters' => $ filters , 'sort_prop' => $ prop , 'sort_order' => $ order , 'limit' => $ limit , 'offset' => $ offset ] ; $ data = $ this -> call ( 'apps/' . $ this -> appId . '/users' , $ params , 'get' ) ; $ array = [ ] ; if ( $ data [ 'users' ] ) { foreach ( $ data [ 'users' ] as $ msg ) { $ array [ ] = User :: fromResponse ( $ msg ) ; } } return $ array ; }
Get all leads in application . Lead - a user who has known name email phone user_id or it was at least one dialogue .
28,720
public function getConversations ( $ userId = false , $ limit = 20 , $ offset = 0 , $ closed = null , $ assigned = null , $ tags = [ ] ) { $ params = [ 'count' => $ limit , 'after' => $ offset ] ; if ( $ userId ) { $ data = $ this -> call ( 'users/' . $ this -> appId . '/conversations' , $ params , 'get' ) ; } else { if ( $ closed !== null ) { $ params [ 'closed' ] = ( bool ) $ closed ; } if ( $ assigned !== null ) { $ params [ 'assigned' ] = ( int ) $ assigned ; } if ( $ tags ) { $ params [ 'tags' ] = implode ( ',' , $ tags ) ; } $ data = $ this -> call ( 'apps/' . $ this -> appId . '/conversations' , $ params , 'get' ) ; } $ array = [ ] ; if ( $ data ) { foreach ( $ data as $ msg ) { $ array [ ] = Conversation :: fromResponse ( $ msg ) ; } } return $ array ; }
Get all conversations in application .
28,721
public function getConversation ( $ id ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } return Conversation :: fromResponse ( $ this -> call ( 'conversations/' . $ id , [ ] , 'get' ) ) ; }
Get conversation by id .
28,722
public function getMessages ( $ id , $ limit = 20 , $ offset = 0 ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } $ params = [ 'count' => $ limit , 'after' => $ offset ] ; $ data = $ this -> call ( 'conversations/' . $ id . '/parts' , $ params , 'get' ) ; $ array = [ ] ; if ( $ data ) { foreach ( $ data as $ msg ) { $ array [ ] = Message :: fromResponse ( $ msg ) ; } } return $ array ; }
Get messages from conversation .
28,723
public function readMessages ( $ id ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } $ res = $ this -> call ( 'conversations/' . $ id . '/markread' , [ ] , 'post' ) ; if ( $ res ) { return true ; } return false ; }
Read all messages in conversation .
28,724
public function setTyping ( $ id , $ message , $ botName = null , $ fromUser = false , $ fromAdmin = 0 ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } $ params = [ 'body' => $ message ] ; if ( $ botName ) { $ params [ 'bot_name' ] = $ botName ; } $ fromUser = ( bool ) $ fromUser ; if ( $ fromUser ) { $ params [ 'from_user' ] = $ fromUser ; } $ fromAdmin = ( int ) $ fromAdmin ; if ( $ fromAdmin ) { $ params [ 'from_admin' ] = $ fromAdmin ; } $ res = $ this -> call ( 'conversations/' . $ id . '/settyping' , $ params , 'post' ) ; if ( $ res ) { return true ; } return false ; }
Set typing message in conversation .
28,725
public function addTag ( $ id , $ tag , $ fromAdminId = null , $ botName = 'Bot' , $ randomId = 0 ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } if ( ! $ tag ) { throw new InvalidArgumentException ; } $ tag = str_replace ( ',' , '' , $ tag ) ; $ params = [ 'action' => 'add' , 'tag' => $ tag ] ; $ fromAdminId = ( int ) $ fromAdminId ; if ( $ fromAdminId ) { $ params [ 'from_admin' ] = $ fromAdminId ; } else { $ params [ 'bot_name' ] = $ botName ; } $ randomId = ( int ) $ randomId ; if ( $ randomId ) { $ params [ 'random_id' ] = $ randomId ; } $ res = $ this -> call ( 'conversations/' . $ id . '/tag' , $ params , 'post' ) ; if ( $ res ) { return true ; } return false ; }
Add tag to dialogue .
28,726
public function closeConversation ( $ id , $ fromAdminId = null , $ botName = 'Bot' , $ randomId = 0 ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } $ params = [ ] ; $ fromAdminId = ( int ) $ fromAdminId ; if ( $ fromAdminId ) { $ params [ 'from_admin' ] = $ fromAdminId ; } else { $ params [ 'bot_name' ] = $ botName ; } $ randomId = ( int ) $ randomId ; if ( $ randomId ) { $ params [ 'random_id' ] = $ randomId ; } $ res = $ this -> call ( 'conversations/' . $ id . '/close' , $ params , 'post' ) ; if ( $ res ) { return true ; } return false ; }
Close the conversation .
28,727
public function setPresence ( $ id , $ presence , $ sessionId ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } if ( ! in_array ( $ presence , User :: getPresences ( ) ) ) { throw new InvalidArgumentException ; } if ( ! $ sessionId ) { throw new InvalidArgumentException ; } $ params = [ 'presence' => $ presence , 'session' => $ sessionId ] ; $ this -> call ( 'users/' . $ id . '/setpresence' , $ params , 'post' ) ; }
Set user status .
28,728
public function startConversation ( $ id , $ message ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } if ( ! $ message ) { throw new InvalidArgumentException ; } $ params = [ 'body' => $ message ] ; $ res = $ this -> call ( 'users/' . $ id . '/startconversation' , $ params , 'post' ) ; if ( $ res && isset ( $ res [ 'id' ] ) ) { return true ; } return false ; }
Start conversation with user .
28,729
public function trackEvent ( $ id , $ eventName , $ additionalParams = [ ] , $ isSystem = true ) { if ( $ this -> isEmptyId ( $ id ) ) { throw new InvalidArgumentException ; } if ( ! $ eventName ) { throw new InvalidArgumentException ; } $ params = [ 'event' => $ eventName , 'params' => json_encode ( $ additionalParams ) ] ; if ( ! $ isSystem ) { $ params [ 'by_user_id' ] = 'true' ; } $ res = $ this -> call ( 'users/' . $ id . '/events' , $ params , 'post' ) ; if ( $ res && isset ( $ res [ 'id' ] ) ) { return true ; } return false ; }
Tracking events which is performed by the user .
28,730
public function getEvents ( $ id , $ eventName = null , $ limit = 20 , $ offset = 0 ) { $ params = [ 'count' => $ limit , 'after' => $ offset ] ; if ( $ eventName ) { $ params [ 'filter_name' ] = $ eventName ; } $ data = $ this -> call ( 'users/' . $ id . '/events' , $ params , 'get' ) ; $ array = [ ] ; if ( $ data ) { foreach ( $ data as $ msg ) { $ array [ ] = Event :: fromResponse ( $ msg ) ; } } return $ array ; }
Receive events that the user makes a chronologically .
28,731
public function addLocation ( $ location ) { foreach ( $ this -> viewFinders as $ viewFinder ) { try { $ viewFinder -> addLocation ( $ location ) ; } catch ( \ Exception $ e ) { } } }
Add a location to the finder .
28,732
public function addNamespace ( $ namespace , $ hints ) { foreach ( $ this -> viewFinders as $ viewFinder ) { try { $ viewFinder -> addNamespace ( $ namespace , $ hints ) ; } catch ( \ Exception $ e ) { } } }
Add a namespace hint to the finder .
28,733
public function addExtension ( $ extension ) { foreach ( $ this -> viewFinders as $ viewFinder ) { try { $ viewFinder -> addExtension ( $ extension ) ; } catch ( \ Exception $ e ) { } } }
Add a valid view extension to the finder .
28,734
public function generate ( $ layer_name , $ primitive_name , FQCN $ qcn ) : array { $ generated_stubs = $ this -> generateDry ( $ layer_name , $ primitive_name , $ qcn ) ; foreach ( $ generated_stubs as $ target_path => $ stub_file ) { $ this -> writeStubs ( $ target_path , $ stub_file ) ; } return $ generated_stubs ; }
Generate command will generate files from stubs and put them to target folders
28,735
public function generateDry ( $ layer_name , $ primitive_name , FQCN $ qcn ) : array { $ primitive = $ this -> getPrimitiveByName ( $ primitive_name ) ; $ layer = $ this -> getLayerByName ( $ layer_name ) ; $ this -> updatePlaceholders ( [ "/*<BASE_TEST_NAMESPACE>*/" => $ layer -> getTestsFqcn ( ) -> getFqcn ( ) , "/*<BASE_SRC_NAMESPACE>*/" => $ layer -> getSrcFqcn ( ) -> getFqcn ( ) , "/*<LAYER>*/" => $ layer -> getName ( ) , "/*<PRIMITIVE>*/" => $ primitive_name , "/*<PSR4_NAMESPACE>*/" => $ qcn -> getFqcn ( ) , "/*<PSR4_NAMESPACE_BASE>*/" => $ qcn -> getBasePart ( ) , "/*<PSR4_NAMESPACE_LAST>*/" => $ qcn -> getLastPart ( ) , ] ) ; $ generated_stubs = $ this -> generateStubs ( $ primitive , $ layer , $ qcn ) ; return $ generated_stubs ; }
generateDry - prepare map of new final files to source stubs
28,736
private function generateStubs ( $ primitive , $ layer , $ qcn ) : array { $ generated_stubs = [ ] ; foreach ( $ primitive -> getSrcStubs ( ) as $ filename => $ stub ) { $ filename = $ this -> replacePlaceholdersInText ( $ filename ) ; if ( ! preg_match ( "#\\.php$#" , $ filename ) ) { $ filename .= ".php" ; } $ target_path = $ layer -> getSrcDir ( ) . DIRECTORY_SEPARATOR . $ qcn -> toPSR4Path ( ) . DIRECTORY_SEPARATOR . $ filename ; $ generated_stubs [ $ target_path ] = $ stub ; } foreach ( $ primitive -> getTestStubs ( ) as $ filename => $ stub ) { $ filename = $ this -> replacePlaceholdersInText ( $ filename ) ; if ( ! preg_match ( "#\\.php$#" , $ filename ) ) { $ filename .= ".php" ; } $ target_path = $ layer -> getTestsDir ( ) . DIRECTORY_SEPARATOR . $ qcn -> toPSR4Path ( ) . DIRECTORY_SEPARATOR . $ filename ; $ generated_stubs [ $ target_path ] = $ stub ; } return $ generated_stubs ; }
generateStubs for given primitive in given layer
28,737
private function writeStubs ( string $ target_path , string $ source_file ) : void { @ mkdir ( dirname ( $ target_path ) , 0775 , true ) ; $ this -> updatePlaceholders ( [ "/*<FILENAME>*/" => preg_replace ( "#\.php$#" , "" , basename ( $ target_path ) ) , ] ) ; $ content = $ this -> replacePlaceholdersInText ( file_get_contents ( $ source_file ) ) ; file_put_contents ( $ target_path , $ content ) ; }
writeStubs to final files
28,738
public function getList ( $ inputControlId ) { if ( array_key_exists ( $ inputControlId , $ this -> functionMap ) ) { return call_user_func ( array ( $ this , $ this -> functionMap [ $ inputControlId ] ) ) ; } elseif ( array_key_exists ( $ inputControlId , $ this -> ajaxFunctionMap ) ) { return array ( ) ; } else { return null ; } }
Returns the list of options for a given input control id or returns null if the option is not supported This is for non - ajax controls only
28,739
public function getAjaxList ( $ inputControlId , $ limit = 20 , $ page = 1 , $ search = null ) { if ( array_key_exists ( $ inputControlId , $ this -> ajaxFunctionMap ) ) { return call_user_func ( array ( $ this , $ this -> ajaxFunctionMap [ $ inputControlId ] ) , $ limit , $ page , $ search ) ; } else { return null ; } }
Returns the list of the options for a given ajax selector control id or returns null if that input control is not supported
28,740
public static function color ( $ fgcolor , $ style , $ bgcolor ) { $ code = array ( ) ; if ( $ fgcolor == 'reset' ) { return "\033[0m" ; } if ( isset ( static :: $ FGCOLOR [ $ fgcolor ] ) ) { $ code [ ] = static :: $ FGCOLOR [ $ fgcolor ] ; } if ( isset ( static :: $ STYLE [ $ style ] ) ) { $ code [ ] = static :: $ STYLE [ $ style ] ; } if ( isset ( static :: $ BGCOLOR [ $ bgcolor ] ) ) { $ code [ ] = static :: $ BGCOLOR [ $ bgcolor ] ; } if ( empty ( $ code ) ) { $ code [ ] = 0 ; } return "\033[" . implode ( ';' , $ code ) . 'm' ; }
Create ANSI - control codes for text foreground and background colors and styling .
28,741
public static function input ( $ prompt = null , $ raw = false ) { if ( isset ( $ prompt ) ) { static :: stdout ( $ prompt ) ; } return static :: stdin ( $ raw ) ; }
Asks the user for input . Ends when the user types a PHP_EOL . Optionally provide a prompt .
28,742
public static function stdout ( $ text , $ raw = false ) { if ( $ raw ) { return fwrite ( STDOUT , $ text ) ; } elseif ( extension_loaded ( 'posix' ) && posix_isatty ( STDOUT ) ) { return fwrite ( STDOUT , static :: colorize ( $ text ) ) ; } else { return fwrite ( STDOUT , static :: decolorize ( $ text ) ) ; } }
Prints text to STDOUT .
28,743
public static function stderr ( $ text , $ raw = false ) { if ( $ raw ) { return fwrite ( STDERR , $ text ) ; } elseif ( extension_loaded ( 'posix' ) && posix_isatty ( STDERR ) ) { return fwrite ( STDERR , static :: colorize ( $ text ) ) ; } else { return fwrite ( STDERR , static :: decolorize ( $ text ) ) ; } }
Prints text to STDERR .
28,744
public static function select ( $ text , $ options = array ( ) ) { top : static :: stdout ( "$text [" . implode ( ',' , array_keys ( $ options ) ) . ",?]: " ) ; $ input = static :: stdin ( ) ; if ( $ input === '?' ) { foreach ( $ options as $ key => $ value ) { echo " $key - $value\n" ; } echo " ? - Show help\n" ; goto top ; } elseif ( ! in_array ( $ input , array_keys ( $ options ) ) ) goto top ; return $ input ; }
Gives the user an option to choose from . Giving ? as an input will show a list of options to choose from and their explanations .
28,745
protected function parseDocument ( $ string ) { $ document = array ( ) ; while ( preg_match ( '(\\A(?P<header>[A-Za-z0-9-]+):\s+(?P<value>.*)$)Sm' , $ string , $ match ) ) { $ document [ $ match [ 'header' ] ] = trim ( $ match [ 'value' ] ) ; $ string = substr ( $ string , strlen ( $ match [ 0 ] ) + 1 ) ; } if ( strpos ( $ document [ 'Content-Type' ] , 'multipart/mixed' ) === 0 ) { $ body = fopen ( 'string://' , 'w' ) ; foreach ( $ document as $ key => $ value ) { fwrite ( $ body , "$key: $value\r\n" ) ; } fwrite ( $ body , $ string ) ; fseek ( $ body , 0 ) ; $ document [ 'body' ] = array ( ) ; $ parser = new phpillowToolMultipartParser ( $ body ) ; while ( ( $ part = $ parser -> getDocument ( ) ) !== false ) { $ document [ 'body' ] [ ] = $ part ; } } else { $ document [ 'body' ] = trim ( $ string ) ; } return $ document ; }
Parse a single document
28,746
public function getDocument ( ) { if ( feof ( $ this -> stream ) ) { return false ; } $ document = '' ; while ( ( ( $ line = fgets ( $ this -> stream ) ) !== false ) && ( trim ( $ line ) !== '--' . $ this -> options [ 'boundary' ] ) && ( trim ( $ line ) !== '--' . $ this -> options [ 'boundary' ] . '--' ) ) { $ document .= $ line ; } if ( trim ( $ document ) === '' ) { return false ; } return $ this -> parseDocument ( ltrim ( $ document ) ) ; }
Get document from stream
28,747
protected static function header ( EntityInterface $ entity ) : array { error_log ( "calculating headers: " ) ; error_log ( get_class ( $ entity ) ) ; $ first_hex = 11 ; if ( $ entity instanceof Node ) { if ( $ entity instanceof Obj ) $ first_hex = 5 ; elseif ( $ entity instanceof Actor ) $ first_hex = 4 ; elseif ( $ entity instanceof Graph ) $ first_hex = 3 ; elseif ( $ entity instanceof SubGraph ) $ first_hex = 2 ; else $ first_hex = 1 ; } elseif ( $ entity instanceof Edge ) { if ( $ entity instanceof ObjOut \ Mention ) $ first_hex = 10 ; elseif ( $ entity instanceof ActorOut \ Write ) $ first_hex = 8 ; elseif ( $ entity instanceof ActorOut \ Subscribe ) $ first_hex = 9 ; elseif ( $ entity instanceof ActorOut \ Read ) $ first_hex = 7 ; else $ first_hex = 6 ; } return [ $ first_hex , rand ( 0 , 15 ) ] ; }
Fetches the entity header .
28,748
public function setOption ( $ option , $ value ) { switch ( $ option ) { case 'keep-alive' : $ this -> options [ $ option ] = ( bool ) $ value ; break ; case 'http-log' : case 'password' : case 'username' : $ this -> options [ $ option ] = $ value ; break ; default : throw new phpillowOptionException ( $ option ) ; } }
Set option value
28,749
public function pin ( int $ pin , string $ type , bool $ invert = false ) : Pin { return new Pin ( $ pin , $ type , $ this -> ioAdapter , $ invert ) ; }
Configure a pin
28,750
public function clear ( ) { foreach ( GPIO :: PINS as $ pin ) { $ reset = new Pin ( $ pin , GPIO :: OUT , $ this -> ioAdapter ) ; $ reset -> setValue ( GPIO :: LOW ) ; } }
Reset all of the GPIO pins .
28,751
protected function initializeParticle ( ) : void { $ this -> addEdges ( "incoming" , ActorOut \ Read :: class , ActorOut \ Subscribe :: class , ObjOut \ Mention :: class ) ; $ this -> autoRegisterOutgoingEdges ( ) ; $ this -> initializeHandler ( ) ; $ this -> context ( ) -> emit ( "node.added" , [ $ this ] ) ; }
Initializes the particle .
28,752
protected function initializeHandler ( ) : void { $ this -> handler = new Handlers \ Gateway ( $ this ) ; Loaders \ IncomingEdgeLoader :: pack ( $ this ) -> deploy ( $ this -> handler -> cargo_in ) ; Loaders \ OutgoingEdgeLoader :: pack ( $ this ) -> deploy ( $ this -> handler -> cargo_out ) ; Loaders \ FieldsLoader :: pack ( $ this ) -> deploy ( $ this -> handler -> cargo_fields ) ; }
A helper method to set up edges and fields .
28,753
protected function autoRegisterOutgoingEdges ( ) : void { $ self_reflector = new \ ReflectionObject ( $ this ) ; if ( $ self_reflector -> isAnonymous ( ) ) { return ; } $ edge_dir = dirname ( $ self_reflector -> getFileName ( ) ) . DIRECTORY_SEPARATOR . $ self_reflector -> getShortName ( ) . "Out" ; if ( ! file_exists ( $ edge_dir ) ) { Logger :: info ( "Edge directory %s does not exist" , $ edge_dir ) ; return ; } $ locator = new \ Zend \ File \ ClassFileLocator ( $ edge_dir ) ; foreach ( $ locator as $ file ) { $ filename = str_replace ( $ edge_dir . DIRECTORY_SEPARATOR , '' , $ file -> getRealPath ( ) ) ; $ this -> addEdges ( "outgoing" , ... $ file -> getClasses ( ) ) ; } }
Auto - registers outgoing edge classes
28,754
protected function addEdges ( string $ direction , ... $ classes ) : self { if ( ! in_array ( $ direction , [ "incoming" , "outgoing" ] ) ) { return $ this ; } $ var = sprintf ( "%s_edges" , $ direction ) ; foreach ( $ classes as $ class ) { if ( in_array ( $ class , $ this -> $ var ) ) continue ; $ this -> $ var [ ] = $ class ; $ this -> emit ( "edge.registered" , [ $ direction , $ class ] ) ; $ this -> emit ( $ direction . "_edge.registered" , [ $ class ] ) ; } return $ this ; }
A helper method to register edges
28,755
public function toArray ( ) : array { $ array = parent :: toArray ( ) ; $ array [ "creator" ] = $ this -> creator_id ; $ array [ "registered_edges" ] = [ "in" => $ this -> incoming_edges , "out" => $ this -> outgoing_edges , ] ; if ( $ this instanceof Actor ) { $ array [ "notifications" ] = $ this -> notifications ( ) -> toArray ( ) ; } return $ array ; }
Converts the particle into array
28,756
public function notifySubscribers ( AbstractNotification $ notification ) : void { foreach ( $ this -> getSubscribers ( ) as $ subscriber ) { if ( $ subscriber instanceof Actor ) $ subscriber -> notify ( $ notification ) ; } }
Sends notification to subscriber particles
28,757
public function getBasePart ( ) : string { $ string = str_replace ( $ this -> getLastPart ( ) , "" , $ this -> getFqcn ( ) ) ; if ( isset ( $ string [ - 1 ] ) && $ string [ - 1 ] == "\\" ) { $ string = substr ( $ string , 0 , - 1 ) ; } return $ string ; }
getLastPart - return base namespace without trailing part
28,758
static function fromString ( string $ string ) : self { $ string = str_replace ( "/" , "\\" , $ string ) ; $ string = preg_replace ( "#(\\\\){2,}#" , "\\" , $ string ) ; if ( substr ( $ string , - 1 , 1 ) == "\\" ) { $ string = substr ( $ string , 0 , - 1 ) ; } return new self ( $ string ) ; }
fromString - will replace multiple ending slashes
28,759
public static function createFromEccKey ( PublicKeyInterface $ eccKey ) : self { $ math = EccFactory :: getAdapter ( ) ; $ pointSerializer = new UncompressedPointSerializer ( $ math ) ; $ point = $ eccKey -> getPoint ( ) ; $ hex = $ pointSerializer -> serialize ( $ point ) ; $ binary = new BinaryString ( hex2bin ( $ hex ) ) ; return new self ( $ binary ) ; }
Create a public key from a Mdanter Ecc Public Key .
28,760
public function getEccKey ( ) : PublicKeyInterface { $ math = EccFactory :: getAdapter ( ) ; $ generator = EccFactory :: getNistCurves ( ) -> generator256 ( ) ; $ pointSerializer = new UncompressedPointSerializer ( $ math ) ; $ point = $ pointSerializer -> unserialize ( $ generator -> getCurve ( ) , bin2hex ( $ this -> getRawKeyMaterial ( ) ) ) ; return $ generator -> getPublicKeyFrom ( $ point -> getX ( ) , $ point -> getY ( ) , $ generator -> getOrder ( ) ) ; }
Unserialize the raw key material into a Mdanter Ecc Public Key .
28,761
public static function tag ( $ time , $ options = [ ] ) { if ( $ time ) { if ( ! static :: $ isRegistered ) { TimeagoAsset :: register ( Yii :: $ app -> getView ( ) ) ; self :: $ isRegistered = true ; } Html :: addCssClass ( $ options , 'timeago' ) ; $ options [ 'datetime' ] = Yii :: $ app -> getFormatter ( ) -> asDatetime ( $ time , "php:c" ) ; return Html :: tag ( 'time' , Yii :: $ app -> getFormatter ( ) -> asDatetime ( $ time ) , $ options ) ; } }
Renders time tag .
28,762
public static function exists ( $ language , $ dirs = null ) { return Atomik :: findFile ( "$language.php" , $ dirs ? : self :: $ config [ 'dir' ] ) !== false ; }
Checks if a language is supported
28,763
public static function getDefinedLanguages ( $ dirs = null ) { $ dirs = $ dirs ? : self :: $ config [ 'dir' ] ; $ languages = array ( ) ; foreach ( array_filter ( Atomik :: path ( ( array ) $ dirs ) ) as $ dir ) { if ( is_dir ( $ dir ) ) { foreach ( new DirectoryIterator ( $ dir ) as $ file ) { $ filename = $ file -> getFilename ( ) ; if ( $ filename { 0 } == '.' || $ file -> isDir ( ) ) { continue ; } $ languages [ ] = substr ( $ filename , 0 , strrpos ( $ filename , '.' ) ) ; } } } return $ languages ; }
Gets defined languages
28,764
public static function set ( $ language = null ) { self :: $ messages = array ( ) ; $ language = $ language ? : self :: $ config [ 'language' ] ; $ filename = Atomik :: findFile ( "$language.php" , Atomik :: path ( self :: $ config [ 'dir' ] ) ) ; if ( $ filename === false ) { throw new AtomikException ( "Language '$language' does not exists" ) ; } $ messages = include $ filename ; if ( is_array ( $ messages ) ) { self :: $ messages = array_merge ( self :: $ messages , $ messages ) ; } Atomik :: set ( 'app.language' , $ language ) ; self :: $ config [ 'language' ] = $ language ; if ( isset ( $ _SESSION ) ) { $ _SESSION [ '__LANG' ] = $ language ; } }
Sets the language to use
28,765
public static function translate ( $ text ) { $ args = func_get_args ( ) ; unset ( $ args [ 0 ] ) ; if ( isset ( self :: $ messages [ $ text ] ) ) { $ text = self :: $ messages [ $ text ] ; } return vsprintf ( $ text , $ args ) ; }
Translate a text . Works the same way as sprintf .
28,766
public function createOptionList ( ) { if ( self :: GET_IC_FROM_CUSTOM == $ this -> getICFrom ) { $ optionList = $ this -> optionHandler -> getList ( $ this -> getId ( ) ) ; if ( null === $ optionList ) { throw new \ Exception ( "Input control " . $ this -> getId ( ) . " not defined with option default_input_options_source set to Custom" ) ; } } elseif ( self :: GET_IC_FROM_FALLBACK == $ this -> getICFrom ) { $ optionList = $ this -> optionHandler -> getList ( $ this -> getId ( ) ) ; if ( null === $ optionList ) { $ optionList = $ this -> getOptionListFromJasper ( ) ; } } elseif ( self :: GET_IC_FROM_JASPER == $ this -> getICFrom ) { $ optionList = $ this -> getOptionListFromJasper ( ) ; } else { throw new \ Exception ( self :: MESSAGE_INVALID_ICFROM . $ this -> getICFrom ) ; } return $ optionList ; }
Gets the list of options to display for this input control
28,767
protected function getOptionListFromJasper ( ) { $ optionList = array ( ) ; $ inputControlStateArray = JasperHelper :: convertInputControlState ( $ this -> state ) ; foreach ( $ inputControlStateArray [ "option" ] as $ key => $ option ) { $ optionList [ ] = new Option ( $ option [ "value" ] , $ option [ "label" ] , $ option [ "selected" ] ) ; } return $ optionList ; }
Gets a list of options for the input control from the jasper server
28,768
public function postReportCache ( $ requestId , $ options , $ executionDetails ) { $ rh = $ this -> em -> getRepository ( 'MesdJasperReportBundle:ReportHistory' ) -> findOneByRequestId ( $ requestId ) ; $ totalPagess = $ executionDetails -> xpath ( '//reportExecution/totalPages' ) ; if ( count ( $ totalPagess ) > 0 ) { $ totalPages = ( string ) $ totalPagess [ 0 ] ; if ( $ totalPages > 0 ) { $ status = 'cached' ; } else { $ status = 'empty' ; } } else { $ status = 'empty' ; } if ( $ rh ) { if ( isset ( $ options [ 'formats' ] ) ) { $ rh -> setFormats ( json_encode ( $ options [ 'formats' ] ) ) ; } $ rh -> setStatus ( $ status ) ; $ this -> em -> persist ( $ rh ) ; $ this -> em -> flush ( $ rh ) ; } }
Function that is invoked if given to the client once a report has been cached
28,769
public function displayCachedAssetAction ( $ asset , $ requestId ) { $ asset = $ this -> container -> get ( 'mesd.jasper.report.loader' ) -> getReportLoader ( ) -> getCachedAsset ( $ asset , $ requestId ) ; return new Response ( $ asset , 200 , array ( ) ) ; }
Renders an asset from a cached report
28,770
public function exportCachedReportAction ( $ requestId , $ format ) { $ export = $ this -> container -> get ( 'mesd.jasper.report.loader' ) -> getReportLoader ( ) -> getCachedReport ( $ requestId , $ format ) ; $ response = new Response ( ) ; if ( self :: FORMAT_PDF === $ format ) { $ response -> headers -> set ( 'Content-Type' , 'application/pdf' ) ; } $ response -> headers -> set ( 'Content-Disposition' , 'attachment;filename="' . $ export -> getUri ( ) . '.' . $ format . '"' ) ; $ response -> headers -> set ( 'Content-Transfer-Encoding' , 'binary' ) ; $ response -> headers -> set ( 'Pragma' , 'no-cache' ) ; $ response -> headers -> set ( 'Expires' , '0' ) ; $ response -> setContent ( $ export -> getOutput ( ) ) ; return $ response ; }
Serves report exports
28,771
public function ajaxOptionsAction ( Request $ request , $ inputId ) { $ limit = $ request -> query -> has ( 'limit' ) ? $ request -> query -> get ( 'limit' ) : 20 ; $ page = $ request -> query -> has ( 'page' ) ? $ request -> query -> get ( 'page' ) : 1 ; $ search = $ request -> query -> has ( 'search' ) ? urldecode ( $ request -> query -> get ( 'search' ) ) : null ; if ( $ this -> container -> get ( 'mesd.jasper.report.client' ) -> getOptionsHandler ( ) -> supportsAjaxOption ( $ inputId ) ) { $ options = $ this -> container -> get ( 'mesd.jasper.report.client' ) -> getOptionsHandler ( ) -> getAjaxList ( $ inputId , $ limit , $ page , $ search ) ; $ choices = array ( $ inputId => array ( ) ) ; foreach ( $ options as $ option ) { $ choices [ $ inputId ] [ ] = array ( 'value' => $ option -> getId ( ) , 'text' => $ option -> getLabel ( ) ) ; } } else { throw new \ Exception ( sprintf ( 'The control id "%s" does not support ajax options.' , $ inputId ) ) ; } return new JsonResponse ( $ choices ) ; }
Get the options for an ajax selector
28,772
public function isNonsingular ( ) { for ( $ j = 0 ; $ j < $ this -> n ; $ j ++ ) { if ( $ this -> LU [ $ j ] [ $ j ] == 0 ) { return false ; } } return true ; }
Is the matrix nonsingular?
28,773
public function pushNotification ( PushNotification $ notification , PushSubscription $ subscription , int $ ttl = 3600 ) : ResponseInterface { return $ this -> pushNotificationAsync ( $ notification , $ subscription , $ ttl ) -> wait ( ) ; }
Send a push notification .
28,774
public function pushNotificationAsync ( PushNotification $ notification , PushSubscription $ subscription , int $ ttl = 3600 ) : PromiseInterface { $ cipher = $ this -> cryptograph -> encrypt ( $ notification , $ subscription ) ; $ pushMessage = new Message ( $ cipher , $ subscription , $ ttl ) ; $ request = $ this -> pushService -> createRequest ( $ pushMessage , $ subscription ) ; $ promise = $ this -> httpClient -> sendAsync ( $ request ) ; return $ promise ; }
Send a push notification asynchronously .
28,775
public function html ( $ html , $ tag = null , $ dimensionize = false ) { if ( $ tag !== null ) { return $ this -> html ( array ( $ tag => $ html ) ) ; } if ( is_string ( $ html ) ) { return $ html ; } if ( $ dimensionize ) { $ html = Atomik :: dimensionizeArray ( $ html ) ; } $ output = '' ; foreach ( $ html as $ tag => $ value ) { if ( substr ( $ tag , 0 , 1 ) == '@' ) { continue ; } if ( ! is_string ( $ tag ) ) { if ( ! is_array ( $ value ) ) { $ output .= $ value ; continue ; } } $ attributes = array ( ) ; if ( is_array ( $ value ) ) { if ( isset ( $ value [ '@' ] ) ) { $ attributes = $ value [ '@' ] ; } else { foreach ( $ value as $ attrName => $ attrValue ) { if ( substr ( $ attrName , 0 , 1 ) == '@' ) { $ attributes [ substr ( $ attrName , 1 ) ] = $ attrValue ; } } } $ keys = array_keys ( $ value ) ; if ( ! is_string ( $ keys [ 0 ] ) && is_array ( $ value [ 0 ] ) ) { foreach ( $ value as $ item ) { $ output .= $ this -> html ( $ item , $ tag ) ; } break ; } else { $ value = $ this -> html ( $ value ) ; } } $ output .= sprintf ( "<%s %s>%s</%s>\n" , $ tag , Atomik :: htmlAttributes ( $ attributes ) , $ value , $ tag ) ; } return $ output ; }
Builds an html string from an array
28,776
public function createModel ( $ scenario = 'insert' ) { $ model = new $ this -> modelClass ( $ scenario ) ; if ( ! $ model instanceof File ) { throw new CException ( sprintf ( 'Model class "%s" must extend "File".' , $ this -> modelClass ) ) ; } return $ model ; }
Creates a file model .
28,777
public function deleteModel ( $ id ) { if ( ( $ model = $ this -> loadModel ( $ id ) ) === null ) { throw new CException ( sprintf ( 'Failed to locate file model with id "%d".' , $ id ) ) ; } $ filePath = $ model -> resolvePath ( ) ; if ( file_exists ( $ filePath ) && ! unlink ( $ filePath ) ) { throw new CException ( 'Failed to delete the file.' ) ; } if ( ! $ model -> delete ( ) ) { throw new CException ( 'Failed to delete the file model.' ) ; } return true ; }
Deletes a file with the given id .
28,778
public function sendFile ( $ file , $ terminate = true ) { Yii :: app ( ) -> request -> sendFile ( $ file -> resolveFilename ( ) , $ file -> getContents ( ) , $ file -> mimeType , $ terminate ) ; }
Sends the file associated with the given model to the user .
28,779
public function xSendFile ( $ file , $ options = array ( ) ) { Yii :: app ( ) -> request -> xSendFile ( $ file -> resolvePath ( ) , $ options ) ; }
Sends the file associated with the given model to the user using x - sendfile .
28,780
public function getBasePath ( $ absolute = false ) { $ path = array ( ) ; if ( $ absolute ) { if ( ( $ basePath = Yii :: getPathOfAlias ( $ this -> basePath ) ) === false && is_dir ( $ this -> basePath ) ) { $ basePath = realpath ( $ this -> basePath ) ; } $ path [ ] = $ basePath ; } $ path [ ] = $ this -> fileDir ; return implode ( '/' , $ path ) ; }
Returns the path to the files folder .
28,781
public function getBaseUrl ( $ absolute = false ) { $ url = array ( ) ; if ( $ absolute ) { $ url [ ] = $ this -> baseUrl !== null ? rtrim ( $ this -> baseUrl , '/' ) : Yii :: app ( ) -> request -> baseUrl ; } $ url [ ] = $ this -> fileDir ; return rtrim ( implode ( '/' , $ url ) , '/' ) ; }
Returns the url to the files folder .
28,782
public static function addQueryString ( $ path , $ queryString = null ) { if ( null === $ queryString ) { return $ path ; } return sprintf ( "%s%s%s" , $ path , preg_match ( "#\?#" , $ path ) ? ( preg_match ( "#\?$#" , $ path ) ? '' : '&' ) : '?' , is_array ( $ queryString ) ? http_build_query ( $ queryString ) : $ queryString ) ; }
Add query string
28,783
protected function send ( $ method , $ path , array $ headers = array ( ) , $ queryString = null , array $ links = null , $ noCache = false , $ absolutePath = false ) { $ headers = $ this -> initHeaders ( $ headers ) ; $ transport = HttpTransportFactory :: build ( 'curl' , $ this -> getCacher ( ) , $ this -> getLogger ( ) ) ; if ( ! $ absolutePath ) { $ path = $ this -> getApiEndpointPath ( $ path ) ; } $ transport -> setMethod ( $ method ) -> setPath ( $ path ) -> setHeaders ( $ headers ) ; if ( null !== $ queryString ) { $ transport -> setQueryString ( $ queryString ) ; } if ( null !== $ links ) { $ transport -> setLinks ( $ links ) ; } try { $ response = $ transport -> send ( ) ; } catch ( ApiHttpResponseException $ exception ) { if ( 401 === $ exception -> getStatusCode ( ) && $ this -> container -> has ( 'da_oauth_client.authorization_refresher.oauth' ) ) { $ oauthRefresher = $ this -> container -> get ( 'da_oauth_client.authorization_refresher.oauth' ) ; $ oauthRefresher -> refresh ( ) ; $ response = $ transport -> send ( $ noCache ) ; } else { throw $ exception ; } } return $ response ; }
Send a request to an API .
28,784
private function parseType ( & $ parts ) { if ( isset ( $ parts [ 0 ] ) && ( strlen ( $ parts [ 0 ] ) > 0 ) && ( $ parts [ 0 ] [ 0 ] !== '$' ) && substr ( $ parts [ 0 ] , 0 , 4 ) !== '...$' ) { $ this -> type = array_shift ( $ parts ) ; array_shift ( $ parts ) ; } }
Parses the type from the extracted parts
28,785
private function parseVariable ( & $ parts ) { if ( isset ( $ parts [ 0 ] ) && ( strlen ( $ parts [ 0 ] ) > 0 ) && ( $ parts [ 0 ] [ 0 ] == '$' || substr ( $ parts [ 0 ] , 0 , 4 ) === '...$' ) ) { $ this -> variable = array_shift ( $ parts ) ; array_shift ( $ parts ) ; if ( substr ( $ this -> variable , 0 , 3 ) === '...' ) { $ this -> isVariadic = true ; $ this -> variable = substr ( $ this -> variable , 3 ) ; } } }
Parses the variable from the extracted parts
28,786
protected static function getFormativeTrim ( Framework \ ParticleInterface $ particle ) : int { $ trim = 2 ; if ( defined ( get_class ( $ particle ) . "::FORMATIVE_TRIM_CUT" ) ) $ trim = $ particle :: FORMATIVE_TRIM_CUT ; return $ trim ; }
Calculates how many arguments in constructor to skip
28,787
public function insert ( $ tableName , array $ data ) { $ query = sprintf ( "INSERT INTO $tableName (%s) VALUES (%s)" , implode ( ', ' , array_keys ( $ data ) ) , implode ( ', ' , array_fill ( 0 , count ( $ data ) , '?' ) ) ) ; $ stmt = $ this -> prepare ( $ query ) ; $ stmt -> execute ( array_values ( $ data ) ) ; return $ stmt ; }
Inserts some data into the specified table
28,788
public function delete ( $ tableName , $ where = null ) { list ( $ where , $ params ) = $ this -> _buildWhere ( $ where ) ; $ query = "DELETE FROM $tableName $where" ; $ stmt = $ this -> prepare ( $ query ) ; $ stmt -> execute ( $ params ) ; return $ stmt ; }
Deletes row from a table
28,789
protected function _buildWhere ( $ where ) { if ( empty ( $ where ) ) { return array ( '' , array ( ) ) ; } if ( is_string ( $ where ) ) { return array ( "WHERE $where" , array ( ) ) ; } $ conditions = array ( ) ; $ values = array ( ) ; foreach ( $ where as $ key => $ value ) { if ( is_array ( $ value ) ) { $ conditions [ ] = "$key IN(" . implode ( ', ' , array_fill ( 0 , count ( $ value ) , '?' ) ) . ')' ; $ values = array_merge ( $ values , $ value ) ; } else { $ conditions [ ] = "$key = ?" ; $ values [ ] = $ value ; } } return array ( 'WHERE ' . implode ( $ conditions , ' AND ' ) , $ values ) ; }
Builds a condition string
28,790
public static function fetchDocument ( $ name , $ id ) { if ( ! isset ( self :: $ documents [ $ name ] ) ) { throw new phpillowNoSuchPropertyException ( $ name ) ; } $ className = self :: $ documents [ $ name ] ; $ document = new $ className ( ) ; return $ document -> fetchById ( $ id ) ; }
Fetch document by ID
28,791
public static function deleteDocument ( $ name , $ id ) { if ( ! isset ( self :: $ documents [ $ name ] ) ) { throw new phpillowNoSuchPropertyException ( $ name ) ; } $ db = phpillowConnection :: getInstance ( ) ; $ revision = $ db -> get ( $ db -> getDatabase ( ) . $ id ) ; $ db -> delete ( $ db -> getDatabase ( ) . $ id . '?rev=' . $ revision -> _rev ) ; }
Delete document by ID
28,792
public function resolve ( $ template ) { foreach ( $ this -> queue as $ resolver ) { $ resource = $ resolver -> resolve ( $ template ) ; if ( false !== $ resource ) { return $ resource ; } } return false ; }
Resolve a template name to a resource the renderer can consume .
28,793
public function attach ( ResolverInterface $ resolver , $ priority = 1 ) { $ this -> queue -> insert ( $ resolver , $ priority ) ; return $ this ; }
Attach a resolver
28,794
public function fetchByType ( $ type ) { if ( ! $ this -> hasType ( $ type ) ) { throw new Exception \ ResolverTypeNotFoundException ( ) ; } $ resolvers = new self ( ) ; foreach ( $ this as $ resolver ) { if ( $ resolver instanceof $ type ) { $ resolvers -> attach ( $ resolver ) ; } } if ( 1 === count ( $ resolvers ) ) { return $ resolvers -> queue -> extract ( ) ; } return $ resolvers ; }
Fetch one or more resolvers that match the given type .
28,795
public static function parse ( array $ headers , $ body , $ raw = false ) { $ response = $ raw === true ? $ body : json_decode ( $ body , true ) ; switch ( $ headers [ 'status' ] ) { case 200 : if ( $ raw === true ) { return new phpillowDataResponse ( $ headers [ 'content-type' ] , $ response ) ; } elseif ( $ body [ 0 ] === '[' ) { return new phpillowArrayResponse ( $ response ) ; } elseif ( isset ( $ response [ '_id' ] ) ) { return new phpillowResponse ( $ response ) ; } elseif ( isset ( $ response [ 'rows' ] ) ) { return new phpillowResultSetResponse ( $ response ) ; } case 201 : case 202 : return new phpillowStatusResponse ( $ response ) ; case 404 : throw new phpillowResponseNotFoundErrorException ( $ response ) ; case 409 : case 412 : throw new phpillowResponseConflictErrorException ( $ response ) ; default : throw new phpillowResponseErrorException ( $ headers [ 'status' ] , $ response ) ; } }
Parse a server response
28,796
public function getValue ( $ key , $ view ) { if ( is_scalar ( $ view ) ) { return '' ; } if ( strpos ( $ key , '.' ) ) { return $ this -> getDotValue ( $ key , $ view ) ; } if ( is_object ( $ view ) ) { if ( method_exists ( $ view , $ key ) ) { return call_user_func ( [ $ view , $ key ] ) ; } elseif ( isset ( $ view -> $ key ) ) { return $ view -> $ key ; } return '' ; } if ( isset ( $ view [ $ key ] ) ) { if ( is_callable ( $ view [ $ key ] ) && $ this -> isValidCallback ( $ view [ $ key ] ) ) { return call_user_func ( $ view [ $ key ] ) ; } return $ view [ $ key ] ; } return '' ; }
Get a named value from the view
28,797
private function getDotValue ( $ key , $ view ) { list ( $ first , $ second ) = explode ( '.' , $ key , 2 ) ; $ value = $ this -> getValue ( $ first , $ view ) ; if ( is_scalar ( $ value ) ) { return '' ; } return $ this -> getValue ( $ second , $ value ) ; }
De - reference a dot value
28,798
private function registerPragma ( array $ definition ) { $ pragmas = $ this -> mustache -> getPragmas ( ) ; $ name = $ definition [ 'pragma' ] ; if ( ! $ pragmas -> has ( $ name ) ) { throw new Exception \ UnregisteredPragmaException ( sprintf ( 'No handler for pragma "%s" registered; cannot proceed rendering' , $ name ) ) ; } $ this -> invokedPragmas [ $ name ] = $ definition [ 'options' ] ; }
Register a pragma for the current rendering session
28,799
private function isValidCallback ( $ callback ) { if ( is_string ( $ callback ) ) { return false ; } if ( is_array ( $ callback ) ) { $ target = array_shift ( $ callback ) ; if ( ! is_object ( $ target ) ) { return false ; } } return true ; }
Is the callback provided valid?