idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
56,700
public function processStream ( $ event ) { if ( $ event -> message -> isCtlFrame ( ) ) { if ( $ event -> message -> isCloseFrame ( ) ) { return $ this -> processClose ( $ event ) ; } else if ( $ event -> message -> isPingFrame ( ) ) { return $ this -> processPing ( $ event ) ; } else if ( $ event -> message -> isPongFrame ( ) ) { return $ this -> processPong ( $ event ) ; } } else { return $ this -> processData ( $ event ) ; } }
process websocket stream request
56,701
public function processClose ( $ event ) { $ response = new Response ( ) ; $ response -> opcode = Request :: OPCODE_CLOSE ; return $ event -> sender -> close ( $ response ) ; }
process close request
56,702
public function processPing ( $ event ) { $ res = new Response ( ) ; $ res -> fin = 1 ; $ res -> opcode = Request :: OPCODE_PONG ; $ res -> mask = 0 ; $ res -> payload_len = 0 ; $ event -> sender -> send ( $ res ) ; }
process ping request send pong response to client .
56,703
public function addItem ( $ object , ? string $ key = null ) : void { $ this -> checkCallback ( ) ; if ( null !== $ key ) { if ( isset ( $ this -> members [ $ key ] ) ) { throw new CollectionException ( 'Unable to add to collection - key ' . $ key . ' already used.' ) ; } else { $ this -> members [ $ key ] = $ object ; } } else { $ this -> members [ ] = $ object ; } }
Adds a new member to the collection
56,704
public function addItemAfter ( mixed $ object , string $ previous_key , ? string $ key = null ) : void { if ( ! isset ( $ this -> members [ $ previous_key ] ) ) { $ this -> addItem ( $ object , $ key ) ; return ; } $ position = array_search ( $ previous_key , array_keys ( $ this -> members ) ) ; $ this -> array_insert ( $ object , $ key , $ position + 1 ) ; }
Add the specified object after the indicated key .
56,705
public function addItemBefore ( mixed $ object , string $ latter_key , ? string $ key = null ) : void { if ( ! isset ( $ this -> members [ $ latter_key ] ) ) { $ this -> addItem ( $ object , $ key ) ; return ; } $ position = array_search ( $ latter_key , array_keys ( $ this -> members ) ) ; $ this -> array_insert ( $ object , $ key , $ position ) ; }
Add the object before the specified item .
56,706
private function array_insert ( mixed $ object , string $ key , int $ position ) : void { if ( 0 == count ( $ this -> members ) ) { $ this -> members [ $ key ] = $ object ; } elseif ( $ position == count ( $ this -> members ) ) { $ this -> members [ $ key ] = $ object ; } else { $ this -> members = array_slice ( $ this -> members , 0 , $ position , true ) + array ( $ key => $ object ) + array_slice ( $ this -> members , $ position , null , true ) ; } }
Add the object at a designated position in the array .
56,707
public function removeItem ( string $ key ) : void { $ this -> checkCallback ( ) ; if ( isset ( $ this -> members [ $ key ] ) ) { unset ( $ this -> members [ $ key ] ) ; } else { throw new CollectionException ( 'Unable to remove from collection - key ' . $ key . ' not found.' ) ; } }
\ Remove the item specified by the key from the collection
56,708
public function getItem ( string $ key ) { $ this -> checkCallback ( ) ; if ( isset ( $ this -> members [ $ key ] ) ) { return $ this -> members [ $ key ] ; } else { throw new CollectionException ( 'Unable to retrieve item from collection - key ' . $ key . ' not found.' ) ; } }
Returns the item represented by the key
56,709
public function exists ( string $ key ) : bool { $ this -> checkCallback ( ) ; return isset ( $ this -> members [ $ key ] ) ; }
Checks if the key is in use
56,710
private function checkCallback ( ) : void { if ( isset ( $ this -> onload ) && ! $ this -> is_loaded ) { $ this -> is_loaded = true ; call_user_func ( $ this -> onload , $ this ) ; } }
Call the specified callback if the collection is not loaded .
56,711
public static function generate ( $ options = array ( ) ) { $ sentencesToDisplay = isset ( $ options [ 'sentences' ] ) ? $ options [ 'sentences' ] : rand ( 1 , 10 ) ; $ author = isset ( $ options [ 'author' ] ) ? $ options [ 'author' ] : array_rand ( self :: $ authors , 1 ) ; $ path = __DIR__ . '/data/' . $ author . '.txt' ; if ( file_exists ( $ path ) ) { $ text = file_get_contents ( $ path ) ; $ chars_in_text = strlen ( $ text ) ; $ length = 10000 ; $ start = rand ( 0 , $ chars_in_text - $ length ) ; $ subsection = substr ( $ text , $ start , $ length ) ; return self :: getSentences ( $ subsection , $ sentencesToDisplay ) ; } }
Main generator method .
56,712
protected static function getSentences ( $ body , $ sentencesToDisplay = 2 ) { $ sentences = preg_split ( '/(\.|\?|\!)(\s)/' , $ body ) ; array_shift ( $ sentences ) ; if ( count ( $ sentences ) <= $ sentencesToDisplay ) { return $ body ; } else { $ results = array_slice ( $ sentences , 0 , $ sentencesToDisplay ) ; return implode ( '. ' , $ results ) . '.' ; } }
Returns the first N sentences from a string of text .
56,713
protected function injectFormCell ( BlockView $ view , BlockInterface $ block ) { $ section = BlockViewUtil :: getParent ( $ view , 'panel_section' ) ; if ( null !== $ section && $ section -> vars [ 'rendered' ] && $ view -> vars [ 'rendered' ] && null !== $ formPath = $ block -> getConfig ( ) -> getAttribute ( 'form_name' ) ) { $ parentForm = BlockFormUtil :: getParentFormView ( $ view ) ; if ( null !== $ parentForm ) { $ formNames = explode ( '.' , $ formPath ) ; $ formCell = $ parentForm ; foreach ( $ formNames as $ formName ) { $ formCell = $ formCell -> children [ $ formName ] ; } if ( null !== $ formCell && $ formCell !== $ parentForm ) { $ view -> vars [ 'form_cell' ] = $ formCell ; } } } }
Inject the form of panel cell in view .
56,714
protected function obtainServers ( ) { $ this -> servers = $ this -> fetchServers ( ) ; $ this -> server_names = collect ( $ this -> servers ) -> pluck ( 'name' ) -> toArray ( ) ; if ( empty ( $ this -> server_names ) ) { $ this -> error ( 'No valid servers assigned to user. Skipping SSH key installation on server...' ) ; die ( ) ; } }
Obtain servers .
56,715
protected function obtainServer ( ) { if ( ! $ this -> server ) { if ( $ this -> argument ( 'server_name' ) ) { $ this -> server = $ this -> getForgeIdServer ( $ this -> servers , $ this -> argument ( 'server_name' ) ) ; if ( ! $ this -> server ) { $ this -> error ( 'No server name found on servers assigned to user!' ) ; die ( ) ; } $ this -> server_name = $ this -> argument ( 'server_name' ) ; } else { if ( fp_env ( 'ACACHA_FORGE_SERVER' ) ) { $ this -> server = fp_env ( 'ACACHA_FORGE_SERVER' ) ; if ( fp_env ( 'ACACHA_FORGE_SERVER_NAME' ) ) { $ this -> server_name = fp_env ( 'ACACHA_FORGE_SERVER_NAME' ) ; } else { $ this -> server_name = $ this -> getForgeName ( $ this -> servers , $ this -> server ) ; } } else { $ this -> server_name = $ this -> choice ( 'Forge server?' , $ this -> server_names , 0 ) ; $ this -> server = $ this -> getForgeIdServer ( $ this -> servers , $ this -> server_name ) ; } } } $ this -> checkServer ( $ this -> server ) ; $ this -> checkServerName ( $ this -> server_name ) ; }
Obtain server .
56,716
protected function installSSHKeyOnServer ( ) { $ this -> info ( 'Adding SSH key to Laravel Forge server' ) ; $ this -> url = $ this -> endPointAPIURL ( ) ; $ response = $ this -> postKeyToLaravelForgeServer ( $ keyName = $ this -> getUniqueKeyNameFromEmail ( ) ) ; $ result = json_decode ( $ contents = $ response -> getBody ( ) -> getContents ( ) ) ; if ( ! isset ( $ result -> status ) ) { $ this -> error ( "An error has been succeded: $contents" ) ; die ( ) ; } if ( $ result -> status == 'installed' ) { $ this -> info ( "The SSH Key ($keyName) has been correctly installed in Laravel Forge Server " . $ this -> server_name . ' (' . $ this -> server . ')' ) ; } }
Install ssh key on server .
56,717
protected function postKeyToLaravelForgeServer ( $ keyName = null ) { $ keyName ? $ keyName : $ this -> getUniqueKeyNameFromEmail ( ) ; return $ this -> http -> post ( $ this -> url , [ 'form_params' => [ 'name' => $ keyName , 'key' => file_get_contents ( $ _SERVER [ 'HOME' ] . self :: SSH_ID_RSA_PUB ) ] , 'headers' => [ 'X-Requested-With' => 'XMLHttpRequest' , 'Authorization' => 'Bearer ' . fp_env ( 'ACACHA_FORGE_ACCESS_TOKEN' ) ] ] ) ; }
Post key to Laravel Forge Server .
56,718
protected function appendSSHConfig ( ) { $ ssh_config_file = $ this -> sshConfigFile ( ) ; $ hostname = $ this -> hostNameForConfigFile ( ) ; $ host_string = "Host " . $ hostname ; if ( strpos ( file_get_contents ( $ ssh_config_file ) , $ host_string ) !== false ) { $ this -> info ( "SSH config for host: $host_string already exists" ) ; return ; } $ this -> info ( "Adding server config to SSH config file $ssh_config_file" ) ; if ( ! File :: exists ( $ ssh_config_file ) ) { touch ( $ ssh_config_file ) ; } $ ip_address = $ this -> ip_address ( ) ; $ config_string = "\n$host_string\n Hostname $ip_address \n User forge\n IdentityFile /home/sergi/.ssh/id_rsa\n Port 22\n StrictHostKeyChecking no\n" ; File :: append ( $ ssh_config_file , $ config_string ) ; $ this -> info ( 'The following config has been added:' . $ config_string ) ; }
Append ssh config .
56,719
protected function ip_address ( ) { if ( fp_env ( 'ACACHA_FORGE_IP_ADDRESS' ) ) { $ ip_address = fp_env ( 'ACACHA_FORGE_IP_ADDRESS' ) ; } else { $ ip_address = $ this -> argument ( 'ip' ) ? $ this -> argument ( 'ip' ) : $ this -> ask ( 'IP Address?' ) ; } $ this -> validateIpAddress ( $ ip_address ) ; return $ ip_address ; }
IP address .
56,720
protected function validateIpAddress ( $ ip_address ) { if ( ! filter_var ( $ ip_address , FILTER_VALIDATE_IP ) ) { $ this -> error ( "$ip_address is not a valid ip address! Exiting!" ) ; die ( ) ; } if ( ! $ this -> checkIp ( $ ip_address , $ this -> servers ) ) { $ this -> error ( "$ip_address doesn't match any of your IP addreses Forge Servers" ) ; die ( ) ; } }
Validate ip address .
56,721
protected function createSSHKeys ( ) { $ email = $ this -> argument ( 'email' ) ? $ this -> argument ( 'email' ) : $ this -> getEmail ( ) ; $ this -> info ( "Running ssh-keygen -t rsa -b 4096 -C '$email'" ) ; passthru ( 'ssh-keygen -t rsa -b 4096 -C "' . $ email . '"' ) ; }
Create SSH Keys .
56,722
public function setTemplateDirectory ( $ directory ) { if ( $ directory == null ) { $ this -> templateDirectory = realpath ( find_tse_template ( $ this -> templateName ) ) ; $ this -> loadPackageTemplate ( $ this -> templateDirectory ) ; return ; } $ this -> templateDirectory = realpath ( $ directory ) ; $ this -> loadPackageTemplate ( realpath ( $ directory ) ) ; }
Sets the template directory .
56,723
private function getTemplateDirectory ( ) { $ templateDirectory = realpath ( $ this -> templateDirectory . '/_template' ) ; if ( $ this -> files -> exists ( $ templateDirectory ) && $ this -> files -> isDirectory ( $ templateDirectory ) ) { $ this -> generator -> setInsideTemplateDirectory ( true ) ; return $ templateDirectory ; } return $ this -> templateDirectory ; }
This method will return the path that the engine should use when retrieving template content . If the developer has created a directory _template we will use that dir instead .
56,724
private function getCommonTemplateDirectory ( ) { $ commonDirectory = realpath ( $ this -> templateDirectory . '/_newup/common' ) ; if ( $ this -> files -> exists ( $ commonDirectory ) && $ this -> files -> isDirectory ( $ commonDirectory ) ) { return $ commonDirectory ; } return null ; }
Returns the common template directory .
56,725
public function build ( ) { $ output = Application :: getOutput ( ) ; $ input = Application :: getInput ( ) ; $ this -> package -> setRendererInstance ( $ this -> generator -> getRenderer ( ) ) ; $ this -> package -> setApplication ( app ( Application :: class ) ) ; $ this -> package -> setOutputInstance ( $ output ) ; $ this -> package -> setInputInstance ( $ input ) ; $ this -> package -> builderLoaded ( ) ; if ( $ this -> getCommonTemplateDirectory ( ) !== null ) { $ this -> generator -> getRenderer ( ) -> addPath ( $ this -> getCommonTemplateDirectory ( ) ) ; } $ this -> generator -> setVerbatimExcludePatterns ( $ this -> package -> getVerbatimExcludePatterns ( ) ) ; $ this -> generator -> setVerbatimPatterns ( $ this -> package -> getVerbatimPatterns ( ) ) ; foreach ( $ this -> package -> getTransformPaths ( ) as $ pathKey => $ processPath ) { $ this -> generator -> getPathManager ( ) -> getCollector ( ) -> addFileNames ( [ $ this -> normalizePath ( $ pathKey ) => $ this -> normalizePath ( $ processPath ) ] ) ; } foreach ( $ this -> package -> getIgnoredPaths ( ) as $ ignoredPath ) { $ this -> generator -> getPathManager ( ) -> getGenerator ( ) -> addIgnoredPath ( $ this -> normalizePath ( $ ignoredPath ) ) ; } foreach ( $ this -> package -> getPathsToRemove ( ) as $ pathToRemove ) { $ this -> generator -> getPathManager ( ) -> getGenerator ( ) -> addAutomaticallyRemovedPath ( $ this -> normalizePath ( $ pathToRemove ) ) ; } $ this -> generator -> addPaths ( ( array ) $ this -> getTemplateDirectory ( ) ) ; $ this -> generator -> generateContent ( $ this -> outputDirectory ) ; }
Builds the package template .
56,726
private function loadPackageTemplate ( $ directory ) { $ namespacedPackageClass = $ this -> packageLoader -> loadPackage ( realpath ( $ directory ) ) ; $ this -> autoLoaderManager -> mergePackageLoader ( realpath ( $ directory ) ) ; $ this -> package = app ( $ namespacedPackageClass ) ; }
This method will load the package template instance .
56,727
public function setOptions ( $ options ) { $ this -> package -> setParsedOptions ( $ options ) ; $ this -> inputCollector -> setOptions ( $ options ) ; }
Sets the command options with their values .
56,728
public function setArguments ( $ arguments ) { $ this -> package -> setParsedArguments ( $ arguments ) ; $ this -> inputCollector -> setArguments ( $ arguments ) ; }
Sets the command arguments with their values .
56,729
public function addEventListener ( callable $ listener ) : void { $ dispatcher = type_check ( $ this -> getEventDispatcher ( ) , 'Jasny\EventDispatcher\EventDispatcher' , new LogicException ( 'Unsupported event dispatcher. Please overload the addEventListener method.' ) ) ; $ provider = type_check ( $ dispatcher -> getListenerProvider ( ) , 'Jasny\EventDispatcher\ListenerProvider' , new UnexpectedValueException ( 'Unsupported listener provider; expected %2s, got %1s' ) ) ; $ newProvider = $ provider -> withListener ( $ listener ) ; $ newDispatcher = $ dispatcher -> withListenerProvider ( $ newProvider ) ; $ this -> setEventDispatcher ( $ newDispatcher ) ; }
Add an event listener to the entity s event dispatcher .
56,730
public function setProtocol ( $ protocol ) { switch ( $ protocol ) { case self :: PROTOCOL_HTTPS : $ this -> _protocol = "https" ; break ; case self :: PROTOCOL_HTTP : $ this -> _protocol = "http" ; break ; default : throw new ChaincoinException ( "Invalid Protocol" ) ; } return $ this ; }
Set the protocol used to connect to the JSON - RPC server .
56,731
public function setCertificate ( $ filePath ) { if ( ! file_exists ( realpath ( $ filePath ) ) ) { throw new ChaincoinException ( "Invalid Certificate Path" ) ; } $ this -> _cert = realpath ( $ filePath ) ; $ this -> setProtocol ( self :: PROTOCOL_HTTPS ) ; return $ this ; }
Set the certificate to be used to confirm a HTTPS connection .
56,732
public function callMethod ( $ methodName , array $ parameters = array ( ) ) { $ this -> _status = null ; $ this -> _response = null ; $ this -> _rawResponse = null ; $ this -> _error = null ; $ parameters = array_values ( $ parameters ) ; $ this -> _id ++ ; $ input = json_encode ( array ( 'method' => $ methodName , 'params' => $ parameters , 'id' => $ this -> _id ) ) ; $ curlResource = curl_init ( "{$this->_protocol}://{$this->_user}:{$this->_password}@{$this->_host}:{$this->_port}" ) ; $ curlOptions = array ( CURLOPT_RETURNTRANSFER => true , CURLOPT_FOLLOWLOCATION => true , CURLOPT_HTTPHEADER => array ( "Content-type: application/json" ) , CURLOPT_POST => true , CURLOPT_POSTFIELDS => $ input , ) ; if ( $ this -> _protocol == 'https' ) { if ( $ this -> _cert != null ) { $ curlOptions [ CURLOPT_CAINFO ] = $ this -> _cert ; $ curlOptions [ CURLOPT_CAPATH ] = dirname ( $ this -> _cert ) ; $ curlOptions [ CURLOPT_SSL_VERIFYPEER ] = true ; $ curlOptions [ CURLOPT_SSL_VERIFYHOST ] = true ; } else { $ curlOptions [ CURLOPT_SSL_VERIFYPEER ] = false ; $ curlOptions [ CURLOPT_SSL_VERIFYHOST ] = false ; } } curl_setopt_array ( $ curlResource , $ curlOptions ) ; $ this -> _rawResponse = curl_exec ( $ curlResource ) ; $ this -> _response = json_decode ( $ this -> _rawResponse , $ this -> getOption ( self :: OPTION_RESPONSE_FORMAT , self :: RESPONSE_ASSOC_ARRAY ) == self :: RESPONSE_ASSOC_ARRAY ) ; $ this -> _status = curl_getinfo ( $ curlResource , CURLINFO_HTTP_CODE ) ; $ curlError = curl_error ( $ curlResource ) ; curl_close ( $ curlResource ) ; if ( $ curlError ) { $ this -> _error = $ curlError ; return false ; } if ( $ this -> _response [ 'error' ] ) { $ this -> _error = $ this -> _response [ 'error' ] [ 'message' ] ; $ this -> _errorCode = $ this -> _response [ 'error' ] [ 'code' ] ; } else if ( $ this -> _status != 200 ) { switch ( $ this -> _status ) { case 400 : $ this -> _error = "HTTP_BAD_REQUEST" ; break ; case 401 : $ this -> _error = "HTTP_UNAUTHORIZED" ; break ; case 403 : $ this -> _error = "HTTP_FORBIDDEN" ; break ; case 404 : $ this -> _error = "HTTP_NOT_FOUND" ; break ; default : throw new ChaincoinException ( "An unexpected http response code was encountered!" ) ; } } if ( $ this -> _error ) { return false ; } return $ this -> _response [ 'result' ] ; }
Call a method and return the response as an associative array .
56,733
public function connect ( MysqlConnection $ connection ) { try { if ( ! $ connection -> isConnected ( ) ) { throw new DatabaseException ( __METHOD__ . "\nConnection failure no ressource given" , self :: NO_RESSOURCE , self :: SEVERITY_LOG , __FILE__ , __LINE__ ) ; } if ( $ this -> _get_detail === true ) { $ this -> db_detail = $ this -> getDatabaseDetail ( $ this ) ; } } catch ( DatabaseException $ ed ) { throw $ ed ; } if ( ! $ this -> db ) { $ this -> db = $ connection ; } return true ; }
connects to the db based on the mysql Connection
56,734
public function fetchAssocList ( \ PDOStatement $ res , $ assign_by = null ) { $ result = array ( ) ; try { while ( $ row = $ res -> fetch ( \ PDO :: FETCH_ASSOC ) ) { if ( ! empty ( $ assign_by ) && ! is_array ( $ assign_by ) ) { $ result [ $ row [ $ assign_by ] ] = ( array ) $ row ; } elseif ( ! empty ( $ assign_by ) && is_array ( $ assign_by ) ) { $ key = array ( ) ; foreach ( $ assign_by as $ key_w ) { if ( isset ( $ row [ $ key_w ] ) ) { $ key [ ] = $ row [ $ key_w ] ; } } if ( empty ( $ key ) ) { $ result [ ] = ( object ) $ row ; } else { $ key = implode ( '-' , $ key ) ; $ result [ $ key ] = ( object ) $ row ; } } else { $ result [ ] = ( array ) $ row ; } } } catch ( DatabaseException $ e ) { throw $ e ; } return $ result ; }
fetches an array list of associative arrays which can be assigned to a specific key from the row as well
56,735
public function fetchNumericList ( \ PDOStatement $ res ) { $ result = new \ SplFixedArray ( $ res -> rowCount ( ) ) ; try { while ( $ row = $ res -> fetch ( \ PDO :: FETCH_NUM ) ) { $ result [ ] = ( array ) $ row ; } } catch ( DatabaseException $ e ) { throw $ e ; } return $ result ; }
fetches an array list of numeric arrays
56,736
public function fetchObjectList ( \ PDOStatement $ res , $ assign_by = null ) { try { $ result = [ ] ; while ( $ row = $ res -> fetch ( \ PDO :: FETCH_OBJ ) ) { if ( ! empty ( $ assign_by ) && ! is_array ( $ assign_by ) ) { $ result [ $ row -> $ assign_by ] = ( object ) $ row ; } elseif ( ! empty ( $ assign_by ) && is_array ( $ assign_by ) ) { $ key = array ( ) ; foreach ( $ assign_by as $ key_w ) { if ( property_exists ( $ row , $ key_w ) ) { $ key [ ] = $ row -> $ key_w ; } } if ( empty ( $ key ) ) { $ result [ ] = ( object ) $ row ; } else { $ key = implode ( '-' , $ key ) ; $ result [ $ key ] = ( object ) $ row ; } } else { $ result [ ] = ( object ) $ row ; } } } catch ( DatabaseException $ e ) { throw $ e ; } return $ result ; }
fetches an object list of associative arrays which can be assigned to a specific key from the row as well
56,737
public function getDatabaseDetail ( MySQL $ db = null ) { if ( empty ( $ db ) || empty ( $ db -> db ) ) { $ db = $ this ; } return new MysqlDetail ( $ db ) ; }
wrapper for the db_detail object the parameter should be a valid db object
56,738
public function selectDb ( $ dbname , \ PDO $ db ) { if ( empty ( $ db ) || empty ( $ dbname ) ) return false ; try { if ( ! $ db -> query ( "USE `$dbname`" ) ) { $ this -> error = ( string ) $ db -> errorInfo ( ) ; $ this -> errorno = ( int ) $ db -> errorCode ( ) ; throw new DatabaseException ( __METHOD__ . "\nsql_error: $this->error\nsql_errorno:$this->errorno" , self :: ERR_EXEC , self :: SEVERITY_LOG , __FILE__ , __LINE__ ) ; } } catch ( DatabaseException $ e ) { throw $ e ; } return true ; }
selects a db
56,739
public function setCharset ( $ charset = 'UTF8' , \ PDO $ db ) { try { if ( empty ( $ charset ) || ! $ db ) { throw new DatabaseException ( __METHOD__ . "\ncharset:$charset\nressource:" . print_r ( $ this -> db , true ) , self :: ERR_EXEC , self :: SEVERITY_LOG , __FILE__ , __LINE__ ) ; } $ this -> mysqli_client_encoding = ( string ) $ charset ; if ( $ this -> db_detail ) { $ this -> db_detail -> character_set_client = ( string ) $ charset ; } } catch ( DatabaseException $ e ) { throw $ e ; } $ db -> exec ( "set names $charset" ) ; return true ; }
sets a different charset
56,740
public function setLoggerInstance ( LoggerInterface $ LogInterface = null ) { $ this -> oLog = $ LogInterface ?? new \ Psr \ Log \ NullLogger ( ) ; return $ this ; }
Setting Logger instance
56,741
public function setDefaultRepositoryClassName ( $ className ) { $ reflectionClass = new \ ReflectionClass ( $ className ) ; if ( ! $ reflectionClass -> implementsInterface ( ObjectRepository :: class ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid repository class "%s". It must be a Doctrine\Common\Persistence\ObjectRepository.' , $ className ) ) ; } $ this -> repositoryClassName = $ className ; }
Set default repository class name .
56,742
public function cron_callback ( $ hash ) { $ notifications = $ this -> storage -> get_notifications ( $ hash ) ; if ( empty ( $ notifications ) ) { return ; } $ strategy = $ this -> storage -> get_notifications_strategy ( $ hash ) ; $ rate = $ strategy -> get_suggested_rate ( ) ; if ( count ( $ notifications ) > $ rate ) { $ to_process = array_slice ( $ notifications , 0 , $ rate , true ) ; } else { $ to_process = $ notifications ; } foreach ( $ to_process as $ key => $ notification ) { if ( $ notification -> was_sent ( ) ) { unset ( $ notifications [ $ key ] ) ; continue ; } try { $ notification -> set_strategy ( $ strategy ) ; if ( $ notification -> send ( ) ) { unset ( $ notifications [ $ key ] ) ; } } catch ( \ Exception $ e ) { } } if ( empty ( $ notifications ) ) { $ this -> storage -> clear_notifications ( $ hash ) ; } else { $ this -> storage -> store_notifications ( $ hash , $ notifications ) ; wp_schedule_single_event ( self :: get_next_event_time ( ) , self :: CRON_ACTION , array ( $ hash , uniqid ( ) ) ) ; } }
Callback function given to WP Cron .
56,743
public function qb ( array $ definition , bool $ autoexec = false ) { $ builder = new QueryBuilder ( $ definition ) ; $ this -> sql = $ builder -> build ( ) ; $ this -> params = $ builder -> getParams ( ) ; return $ this -> query ( $ autoexec ) ; }
Run QueryBuilder as definition parser to create a sql query
56,744
public function sql ( string $ sql , array $ params = [ ] , bool $ autoexec = false ) { $ this -> sql = $ sql ; $ this -> params = $ params ; return $ this -> query ( $ autoexec ) ; }
Run query by sql string
56,745
private function query ( bool $ autoexec = false ) { $ this -> stmt = null ; $ this -> stmt = $ this -> dbh -> prepare ( str_replace ( '{db_prefix}' , $ this -> prefix , $ this -> sql ) ) ; if ( ! empty ( $ this -> params ) ) { foreach ( $ this -> params as $ parameter => $ value ) { $ this -> stmt -> bindValue ( $ parameter , $ value ) ; } } if ( $ autoexec === true ) { return $ this -> execute ( ) ; } else { return $ this -> stmt ; } }
This is the db query method
56,746
public function bindValue ( string $ param , $ value , int $ type = null ) { if ( is_null ( $ type ) ) { switch ( true ) { case is_int ( $ value ) : $ type = \ PDO :: PARAM_INT ; break ; case is_bool ( $ value ) : $ type = \ PDO :: PARAM_BOOL ; break ; case is_null ( $ value ) : $ type = \ PDO :: PARAM_NULL ; break ; default : $ type = \ PDO :: PARAM_STR ; } } if ( is_array ( $ value ) ) { $ value = implode ( ', ' , $ value ) ; } $ this -> stmt -> bindValue ( $ param , $ value , $ type ) ; }
Bind parameter by value to PDO statement
56,747
public function all ( ) : array { $ this -> execute ( ) ; $ data = $ this -> stmt -> fetchAll ( \ PDO :: FETCH_CLASS , '\Core\Data\DataObject' ) ; if ( ! empty ( $ data ) ) { $ data = $ this -> executeCallbackAndSchemeHandler ( $ data ) ; } return $ data ; }
Executes statement and returns result as an array of DataObjects
56,748
public function single ( ) { $ this -> execute ( ) ; $ data = $ this -> stmt -> fetchObject ( '\Core\Data\DataObject' ) ; if ( ! empty ( $ data ) ) { $ data = $ this -> executeCallbackAndSchemeHandler ( $ data ) ; } return $ data ; }
Executes statement and returns result as DataObject
56,749
public function column ( int $ column = 0 ) : array { $ this -> execute ( ) ; return $ this -> stmt -> fetchAll ( \ PDO :: FETCH_COLUMN , $ column ) ; }
Executes statement and returns all rows of specific column
56,750
public function find ( string $ table , string $ key_field , $ value ) { $ this -> qb ( [ 'table' => $ table , 'filter' => $ key_field . '=:' . $ key_field , 'params' => [ ':' . $ key_field => $ value ] ] ) ; return $ this -> single ( ) ; }
Finds one row by using one field and a value as filter
56,751
public function delete ( $ table , $ filter = '' , array $ params = [ ] ) : bool { $ query = [ 'table' => $ table , 'method' => 'DELETE' ] ; if ( $ filter ) { $ query [ 'filter' ] = $ filter ; if ( $ params ) { $ query [ 'params' ] = $ params ; } } $ this -> qb ( $ query , true ) ; return true ; }
Shorthand delete method .
56,752
public function debugSql ( string $ sql , array $ params = [ ] ) : string { if ( $ params ) { $ indexed = $ params == array_values ( $ params ) ; foreach ( $ params as $ k => $ v ) { if ( is_object ( $ v ) ) { if ( $ v instanceof \ DateTime ) { $ v = $ v -> format ( 'Y-m-d H:i:s' ) ; } else { continue ; } } elseif ( is_string ( $ v ) ) { $ v = "'$v'" ; } elseif ( $ v === null ) { $ v = 'NULL' ; } elseif ( is_array ( $ v ) ) { $ v = implode ( ',' , $ v ) ; } if ( $ indexed ) { $ sql = preg_replace ( '/\?/' , $ v , $ sql , 1 ) ; } else { $ sql = str_replace ( $ k , $ v , $ sql ) ; } } } $ sql = str_replace ( '{db_prefix}' , $ this -> prefix , $ sql ) ; return $ sql ; }
Returns interpolated sql string with parameters
56,753
public function setScheme ( array $ scheme ) { $ scheme_handler = new SchemeHandler ( ) ; $ scheme_handler -> setScheme ( $ scheme ) ; $ this -> injectSchemeHandler ( $ scheme_handler ) ; }
Adds a scheme array based SchemeHandler object to the connector
56,754
public function add ( $ data ) { if ( is_array ( $ data ) ) { $ this -> listeners = array_merge ( $ this -> listeners , $ data ) ; } elseif ( $ data instanceof \ Symfony \ Component \ EventDispatcher \ EventlistenerInterface ) { if ( ! in_array ( get_class ( $ data ) , $ this -> loaded ) ) { $ this -> emitter -> addListener ( $ data ) ; $ this -> loaded [ ] = get_class ( $ data ) ; } } else { if ( is_string ( $ data ) ) { $ this -> listeners [ ] = $ data ; } } }
Adds to the listeners array .
56,755
protected function processTags ( PHP_CodeSniffer_File $ file , $ stackPtr , $ commentStart ) { $ tokens = $ file -> getTokens ( ) ; $ type = strtolower ( $ tokens [ $ stackPtr ] [ 'content' ] ) ; $ firstComment = $ tokens [ $ commentStart + 5 ] [ 'content' ] ; if ( $ type === 'class' ) { if ( substr ( $ firstComment , 0 , 5 ) != 'Class' ) { $ file -> addError ( 'First line should have form: "Class ClassName"' , $ commentStart + 5 ) ; } } elseif ( $ type == 'interface' ) { if ( substr ( $ firstComment , 0 , 9 ) != 'Interface' ) { $ file -> addError ( 'First line should have form: "Interface ClassName"' , $ commentStart + 5 ) ; } } elseif ( $ type == 'trait' ) { if ( substr ( $ firstComment , 0 , 5 ) != 'Trait' ) { $ file -> addError ( 'First line should have form: "Trait ClassName"' , $ commentStart + 5 ) ; } } parent :: processTags ( $ file , $ stackPtr , $ commentStart ) ; }
Process tags inside the comment block .
56,756
protected function process ( array $ data ) { $ config = array ( ) ; foreach ( $ data as $ section => $ value ) { if ( Arrays :: isArray ( $ value ) ) { if ( strpos ( $ section , $ this -> nestSeparator ) !== false ) { $ sections = explode ( $ this -> nestSeparator , $ section ) ; $ config = array_merge_recursive ( $ config , $ this -> buildNestedSection ( $ sections , $ value ) ) ; } else { $ config [ $ section ] = $ this -> processSection ( $ value ) ; } } else { $ this -> processKey ( $ section , $ value , $ config ) ; } } return $ config ; }
Process data from the parsed ini file .
56,757
private function buildNestedSection ( $ sections , $ value ) { if ( count ( $ sections ) == 0 ) { return $ this -> processSection ( $ value ) ; } $ nestedSection = array ( ) ; $ first = array_shift ( $ sections ) ; $ nestedSection [ $ first ] = $ this -> buildNestedSection ( $ sections , $ value ) ; return $ nestedSection ; }
Process a nested section
56,758
protected function processSection ( array $ section ) { $ config = array ( ) ; foreach ( $ section as $ key => $ value ) { $ this -> processKey ( $ key , $ value , $ config ) ; } return $ config ; }
Process a section .
56,759
public static function saveToFile ( $ data , $ file ) { $ file = Yii :: getAlias ( $ file ) ; file_put_contents ( $ file , "<?php\nreturn " . VarDumper :: export ( $ data ) . ";\n" , LOCK_EX ) ; self :: invalidateScriptCache ( $ file ) ; }
Saves the authorization data to a PHP script file .
56,760
public function compilePattern ( $ key ) { $ items = $ this -> patterns [ $ key ] ; if ( is_array ( $ items ) ) { $ items = implode ( null , $ items ) ; } return String :: insert ( $ items , $ this -> regexInject ) ; }
A helper method to help compile patterns
56,761
public function isClassFromFile ( $ className , $ file ) { $ realFile = $ this -> getFileDeclaringClass ( $ className ) ; if ( $ file === $ realFile ) { return true ; } return $ realFile ; }
Check if a class originates from the passed file .
56,762
public function add ( $ loader , $ name = null ) { if ( empty ( $ name ) ) { $ name = 'loader.' . count ( $ this -> loaders ) ; } $ this -> loaders [ $ name ] = $ loader ; }
Register a class loader .
56,763
public function register ( $ prepend = false ) { spl_autoload_call ( 'PhpCodeQuality\AutoloadValidation\Exception\ClassNotFoundException' ) ; spl_autoload_call ( 'PhpCodeQuality\AutoloadValidation\Exception\ParentClassNotFoundException' ) ; $ this -> previousLoaders = spl_autoload_functions ( ) ; foreach ( $ this -> previousLoaders as $ previousLoader ) { spl_autoload_unregister ( $ previousLoader ) ; } spl_autoload_register ( array ( $ this , 'loadClass' ) , true , $ prepend ) ; }
Register this instance as an auto loader .
56,764
public function unregister ( ) { foreach ( array_reverse ( $ this -> previousLoaders ) as $ previousLoader ) { spl_autoload_register ( $ previousLoader , true ) ; } spl_autoload_unregister ( array ( $ this , 'loadClass' ) ) ; }
Unregister this instance as an auto loader .
56,765
private static function findDeclarations ( $ filePath ) { $ gathered = array ( ) ; $ gatheringNamespace = false ; $ namespace = null ; $ tokens = token_get_all ( file_get_contents ( $ filePath ) ) ; foreach ( $ tokens as $ index => $ token ) { if ( $ gatheringNamespace ) { if ( isset ( $ token [ 1 ] ) ) $ namespace .= $ token [ 1 ] ; if ( $ token == ";" ) { $ namespace = trim ( $ namespace , " ;\\" ) ; $ namespace = $ namespace . '\\' ; $ gatheringNamespace = false ; } } if ( $ namespace === null && $ token [ 0 ] === T_NAMESPACE ) { $ gatheringNamespace = true ; } if ( isset ( $ tokens [ $ index - 2 ] ) && in_array ( $ tokens [ $ index - 2 ] [ 0 ] , self :: $ autoloadableTokens , true ) ) { if ( $ tokens [ $ index - 1 ] [ 0 ] === T_WHITESPACE && $ token [ 0 ] === T_STRING ) { $ gathered [ ] = $ namespace . $ token [ 1 ] ; } } } return $ gathered ; }
Go through the file and return an array of autoloadable tokens present .
56,766
public function flush ( ) { foreach ( $ this -> buffer as $ data ) { $ this -> output -> write ( $ data [ 'messages' ] , $ data [ 'newline' ] , $ data [ 'options' ] ) ; } $ this -> buffer = [ ] ; }
Flushes the buffer .
56,767
public function make ( IPost $ post ) { $ post -> setResponse ( $ this -> response -> view ( \ OogleeBConfig :: get ( 'config.post_view.view' ) , compact ( 'post' ) ) ) ; }
Make the post response .
56,768
public static function create ( $ filename , $ open_mode = 'r' , $ use_include_path = false , $ context = null ) { return new static ( $ filename , $ open_mode , $ use_include_path , $ context ) ; }
Creates a new file object .
56,769
public static function createTempPath ( $ prefix = 'php-' ) { $ temp = tempnam ( sys_get_temp_dir ( ) , $ prefix ) ; if ( false === $ temp ) { throw new FileException ( 'A new temporary file could not be created.' ) ; } return $ temp ; }
Creates a new temporary file and returns its path .
56,770
public static function createTempPathNamed ( $ name ) { $ dir = static :: createTempPath ( ) ; if ( ! unlink ( $ dir ) ) { throw new FileException ( 'The temporary file could not be deleted.' ) ; } if ( ! mkdir ( $ dir ) ) { throw new FileException ( 'A new temporary directory could not be created.' ) ; } $ path = $ dir . DIRECTORY_SEPARATOR . $ name ; if ( ! touch ( $ path ) ) { throw new FileException ( 'A new temporary file could not be created.' ) ; } return $ path ; }
Creates a new named temporary file and returns its path .
56,771
public function seed ( $ className , $ params ) { $ blueprint = new Blueprint ( ) ; $ consequence = $ params ; $ class = $ className ; if ( is_array ( $ params ) ) { if ( empty ( $ params [ 'do' ] ) ) { throw new \ InvalidArgumentException ( 'Fixture template not supplied.' ) ; } if ( ! empty ( $ params [ 'class' ] ) ) { $ class = $ params [ 'class' ] ; } $ consequence = $ params [ 'do' ] ; } $ consequence ( $ blueprint ) ; $ factory = new Factory ( $ class , $ blueprint ) ; $ this -> repository -> add ( $ className , $ factory ) ; }
Lets you define a blueprint for your class
56,772
public function retrieve ( $ className , $ attributeOverrides = array ( ) ) { $ factory = $ this -> getFactory ( $ className ) ; return $ factory -> make ( $ attributeOverrides ) ; }
Creates an instance of your class using your blueprint
56,773
public function retrieveList ( $ className , $ count , $ attributeOverrides = array ( ) ) { $ list = array ( ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ list [ ] = $ this -> retrieve ( $ className , $ attributeOverrides ) ; } return $ list ; }
Returns an array containing specified amount of model instances
56,774
public function savedList ( $ className , $ count , $ attributeOverrides = array ( ) ) { $ list = array ( ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ list [ ] = $ this -> saved ( $ className , $ attributeOverrides ) ; } return $ list ; }
Returns an array containing specified amount of persisted model instances
56,775
public function userCan ( $ permission , $ object , $ user = null ) { if ( is_null ( $ user ) ) { $ user = app ( 'auth' ) -> user ( ) ; } $ adminGroups = $ this -> groupProvider ( ) -> findAdminGroups ( ) ; if ( $ adminGroups -> count ( ) > 0 && $ user -> inGroup ( $ adminGroups ) ) return true ; $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; if ( ! $ permObject ) return false ; $ uop = $ this -> userObjectPermission -> findPermission ( $ user , $ object , $ permObject ) ; if ( $ uop ) return true ; $ gop = $ this -> groupObjectPermission -> findPermissions ( $ object , $ permObject ) ; if ( count ( $ gop ) == 0 ) return false ; $ groups = array ( ) ; foreach ( $ gop as $ onePermission ) { $ groups [ ] = $ onePermission -> getGroup ( ) ; } return $ user -> inGroup ( $ groups ) ; }
Determines whether or not a user has some permission on a given object
56,776
public function allowUser ( $ permissions , $ object , $ user = null ) { if ( is_null ( $ user ) ) { $ user = app ( 'auth' ) -> user ( ) ; } if ( ! is_array ( $ permissions ) ) { $ permissions = array ( $ permissions ) ; } foreach ( $ permissions as $ permission ) { $ this -> allowSinglePermission ( $ permission , $ object , $ user ) ; } }
Give a user permissions to a specific object
56,777
protected function allowSinglePermission ( $ permission , $ object , $ user ) { $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; if ( ! $ permObject ) { $ listOfPermissions = $ object -> getPermissions ( ) ; if ( ! isset ( $ listOfPermissions [ $ permission ] ) ) { throw new \ Exception ( "Permission " . $ permission . " doesn't exist on the " . get_class ( $ object ) . " object." ) ; } $ permObject = $ this -> permission -> create ( array ( 'name' => $ listOfPermissions [ $ permission ] , 'object_type' => get_class ( $ object ) , 'codename' => $ permission , ) ) ; } $ uop = $ this -> userObjectPermission -> findPermission ( $ user , $ object , $ permObject ) ; if ( ! $ uop ) { $ uop = $ this -> userObjectPermission -> create ( array ( 'user_id' => $ user -> id , 'object_type' => get_class ( $ object ) , 'object_id' => $ object -> id , 'permission_id' => $ permObject -> id , ) ) ; } }
Give a user some permission to a specific object
56,778
public function disallowUser ( $ permissions , $ object , $ user = null ) { if ( is_null ( $ user ) ) { $ user = app ( 'auth' ) -> user ( ) ; } if ( ! is_array ( $ permissions ) ) { $ permissions = array ( $ permissions ) ; } foreach ( $ permissions as $ permission ) { $ this -> disallowSinglePermission ( $ permission , $ object , $ user ) ; } }
Remove a user s permissions to a specific object
56,779
protected function disallowSinglePermission ( $ permission , $ object , $ user ) { $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; $ uop = $ this -> userObjectPermission -> findPermission ( $ user , $ object , $ permObject ) ; if ( $ uop ) { $ this -> userObjectPermission -> delete ( $ uop ) ; } }
Remove a user s permission to a specific object
56,780
public function allowGroup ( $ permissions , $ object , $ group ) { if ( ! is_array ( $ permissions ) ) { $ permissions = array ( $ permissions ) ; } foreach ( $ permissions as $ permission ) { $ this -> allowSingleGroupPermission ( $ permission , $ object , $ group ) ; } }
Give a group permissions to a specific object
56,781
protected function allowSingleGroupPermission ( $ permission , $ object , $ group ) { $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; if ( ! $ permObject ) { $ listOfPermissions = $ object -> getPermissions ( ) ; if ( ! isset ( $ listOfPermissions [ $ permission ] ) ) { throw new \ Exception ( "Permission " . $ permission . " doesn't exist on the " . get_class ( $ object ) . " object." ) ; } $ permObject = $ this -> permission -> create ( array ( 'name' => $ listOfPermissions [ $ permission ] , 'object_type' => get_class ( $ object ) , 'codename' => $ permission , ) ) ; } $ gop = $ this -> groupObjectPermission -> findPermission ( $ group , $ object , $ permObject ) ; if ( ! $ gop ) { $ gop = $ this -> groupObjectPermission -> create ( array ( 'group_id' => $ group -> id , 'object_type' => get_class ( $ object ) , 'object_id' => $ object -> id , 'permission_id' => $ permObject -> id , ) ) ; } }
Give a group some permission to a specific object
56,782
public function disallowGroup ( $ permissions , $ object , $ group ) { if ( ! is_array ( $ permissions ) ) { $ permissions = array ( $ permissions ) ; } foreach ( $ permissions as $ permission ) { $ this -> disallowSingleGroupPermission ( $ permission , $ object , $ group ) ; } }
Remove a group s permissions to a specific object
56,783
protected function disallowSingleGroupPermission ( $ permission , $ object , $ group ) { $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; if ( $ permObject ) { $ gop = $ this -> groupObjectPermission -> findPermission ( $ group , $ object , $ permObject ) ; if ( $ gop ) { $ this -> groupObjectPermission -> delete ( $ gop ) ; } } }
Remove a group s specific permission to a specific object
56,784
public function getPermissions ( User \ UserInterface $ user = null , $ object = null , $ permission = null ) { if ( is_null ( $ user ) ) { $ user = app ( 'auth' ) -> user ( ) ; } if ( is_null ( $ object ) && is_null ( $ permission ) ) { return $ this -> getPermissionsByUser ( $ user ) ; } $ permObject = null ; if ( ! is_null ( $ object ) && ! is_null ( $ permission ) ) { $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; } $ userPerms = $ this -> userObjectPermission -> findAnyPermission ( $ user , $ object , $ permObject ) ; $ groupPerms = $ this -> groupObjectPermission -> findAnyPermission ( $ user -> getGroups ( ) , $ object , $ permObject ) ; return $ userPerms -> merge ( $ groupPerms ) ; }
Returns permissions for a given user
56,785
protected function getPermissionsByUser ( User \ UserInterface $ user ) { $ userPerms = $ this -> userObjectPermission -> findByUser ( $ user ) ; $ groupPerms = $ this -> groupObjectPermission -> findByGroups ( $ user -> getGroups ( ) ) ; return $ userPerms -> merge ( $ groupPerms ) ; }
Returns all permissions for a given user
56,786
public function getUsers ( $ permission , $ object ) { $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; if ( ! $ permObject ) return array ( ) ; return $ this -> userObjectPermission -> findByObject ( $ permObject , $ object ) ; }
Returns users who have a given permission on an object
56,787
public function getGroups ( $ permission , $ object ) { $ permObject = $ this -> permission -> findByPermissionAndObject ( $ permission , $ object ) ; if ( ! $ permObject ) return array ( ) ; return $ this -> groupObjectPermission -> findByObject ( $ permObject , $ object ) ; }
Returns groups who have a given permission on an object
56,788
protected function parse ( ) { $ this -> checkFormat ( ) ; $ this -> parsePalmDb ( ) ; $ this -> parsePalmDoc ( ) ; $ this -> parseMobiHeader ( ) ; $ this -> parseExth ( ) ; }
Parse the file data .
56,789
protected function parsePalmDb ( ) { $ file = $ this -> file ; $ file -> fseek ( $ this -> palmDbHeaderStart ) ; $ content = $ file -> fread ( 2 ) ; $ records = hexdec ( bin2hex ( $ content ) ) ; $ this -> palmDbHeader = new PalmDbHeader ( ) ; for ( $ i = 0 ; $ i < $ records ; ++ $ i ) { $ this -> palmDbHeader -> addRecord ( new PalmRecord ( $ this -> readData ( $ file , 4 ) , $ this -> readData ( $ file , 1 ) , $ this -> readData ( $ file , 3 ) ) ) ; } }
Parse the PalmDb records from the file .
56,790
protected function parsePalmDoc ( ) { if ( ! $ this -> palmDbHeader ) { return ; } $ file = $ this -> file ; $ firstPalmDbRecord = $ this -> palmDbHeader -> getIterator ( ) -> offsetGet ( 0 ) ; $ offset = $ firstPalmDbRecord -> getOffset ( ) ; $ this -> palmDocHeaderStart = $ offset ; $ file -> fseek ( $ offset ) ; $ this -> palmDocHeader = new PalmDocHeader ( $ this -> readData ( $ file , 2 ) , $ this -> readData ( $ file , 4 , $ offset + 4 ) , $ this -> readData ( $ file , 2 ) , $ this -> readData ( $ file , 2 ) , $ this -> readData ( $ file , 2 ) ) ; }
Parse the PalmDoc header from the file .
56,791
protected function parseMobiHeader ( ) { if ( ! $ this -> palmDocHeader ) { return ; } $ file = $ this -> file ; $ this -> mobiHeaderStart = $ file -> ftell ( ) + 2 ; $ file -> fseek ( $ this -> mobiHeaderStart ) ; if ( $ file -> fread ( 4 ) === 'MOBI' ) { $ this -> mobiHeader = new MobiHeader ( $ this -> readData ( $ file , 4 ) , $ this -> readData ( $ file , 4 ) , $ this -> readData ( $ file , 4 ) , $ this -> readData ( $ file , 4 ) , $ this -> readData ( $ file , 4 ) ) ; } $ file -> fseek ( $ this -> mobiHeaderStart + 68 ) ; $ data = $ file -> fread ( 8 ) ; $ title = unpack ( 'N*' , $ data ) ; $ file -> fseek ( $ this -> mobiHeaderStart + ( $ title [ 1 ] - 16 ) ) ; $ this -> title = $ file -> fread ( $ title [ 2 ] ) ; }
Parse the MOBI header from the file .
56,792
protected function parseExth ( ) { if ( ! $ this -> mobiHeader ) { return ; } $ file = $ this -> file ; $ file -> fseek ( $ this -> mobiHeaderStart + $ this -> mobiHeader -> getLength ( ) + 4 ) ; $ this -> exthHeader = new ExthHeader ( $ this -> readData ( $ file , 4 ) ) ; $ records = $ this -> readData ( $ file , 4 ) ; for ( $ i = 0 ; $ i < $ records ; ++ $ i ) { $ type = $ this -> readData ( $ file , 4 ) ; $ length = $ this -> readData ( $ file , 4 ) ; $ data = $ length > 0 ? $ file -> fread ( $ length - 8 ) : '' ; $ this -> exthHeader -> addRecord ( new ExthRecord ( $ type , $ length , $ data ) ) ; } }
Parse EXTH header from the file .
56,793
public static function validateString ( $ string ) { if ( is_string ( $ string ) || ( is_object ( $ string ) && method_exists ( $ string , '__toString' ) ) ) { return ( string ) $ string ; } throw new \ InvalidArgumentException ( 'Expected data must either be a string or stringable' ) ; }
Validate and return a string .
56,794
public function findHeaders ( $ name ) { return array_filter ( $ this -> getHeaders ( ) , function ( $ header ) use ( $ name ) { return StringType :: startsWith ( $ header , "$name:" ) ; } ) ; }
Find all headers matching the specified name .
56,795
public function addMethod ( $ name , Closure $ closure ) { if ( method_exists ( $ this , $ name ) ) { throw new Exception ( 'Overriding core methods not allowed.' ) ; } $ this -> methods [ $ name ] = $ closure ; }
Add a method to the container
56,796
public function register ( ServiceProviderInterface $ provider ) { $ provider -> register ( $ this ) ; $ this -> providers [ get_class ( $ provider ) ] = $ provider ; }
Register a Service Provider
56,797
public function run ( $ method = null , $ path = null ) { $ method = $ method ? : $ this -> request -> getMethod ( ) ; $ path = $ path ? : $ this -> request -> currentPath ( ) ; $ this -> dispatchRouter ( $ method , $ path ) -> send ( ) ; }
Run the application and dispatch the router
56,798
public function getArray ( ) { $ config = @ include $ this -> location ; if ( ! is_array ( $ config ) ) { throw new \ Exception ( 'Config not found' ) ; } $ this -> config = $ config ; return $ config ; }
Get the array from the given location in construct
56,799
private function setLocale ( ) { $ plugin_i18n = new AppIntegrationI18n ( ) ; $ plugin_i18n -> set_domain ( $ this -> get_plugin_name ( ) ) ; $ this -> loader -> add_action ( 'plugins_loaded' , $ plugin_i18n , 'load_plugin_textdomain' ) ; }
Define the locale for this plugin for internationalization .