idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
11,900
|
public function consume ( $ queue , $ prefetchCount = null , $ prefetchSize = null , $ consumerId = null ) : Observable { return $ this -> channel ( ) -> do ( function ( Channel $ channel ) use ( $ prefetchCount , $ prefetchSize ) { $ channel -> qos ( $ prefetchSize , $ prefetchCount ) ; } ) -> flatMap ( function ( Channel $ channel ) use ( $ queue , $ consumerId ) { return $ this -> queue ( $ queue , $ channel ) -> consume ( $ consumerId ) ; } ) ; }
|
Consume given queue at .
|
11,901
|
public function insertBatch ( string $ from , array $ dataSet , array $ options = [ ] ) { list ( $ statement , $ bindings ) = $ this -> compileInsert ( $ from , $ dataSet , $ options [ 'columns' ] ?? [ ] , true ) ; if ( isset ( $ options [ 'returnSql' ] ) ) { return [ $ statement , $ bindings ] ; } return $ this -> fetchAffected ( $ statement , $ bindings ) ; }
|
Run a statement for insert multi row
|
11,902
|
public function update ( string $ from , $ wheres , array $ values , array $ options = [ ] ) { list ( $ where , $ bindings ) = DBHelper :: handleConditions ( $ wheres , $ this ) ; $ options [ 'update' ] = $ this -> qn ( $ from ) ; $ options [ 'where' ] = $ where ; $ statement = $ this -> compileUpdate ( $ values , $ bindings , $ options ) ; if ( isset ( $ options [ 'returnSql' ] ) ) { return [ $ statement , $ bindings ] ; } return $ this -> fetchAffected ( $ statement , $ bindings ) ; }
|
Run a update statement
|
11,903
|
public function authenticatedUser ( $ token = null ) { $ token = $ this -> getToken ( $ token ) ; $ user = $ this -> client -> get ( 'https://api.twitch.tv/kraken/user?oauth_token=' . $ token ) ; return $ user -> json ( ) ; }
|
Returns a user object .
|
11,904
|
public static function errorHandler ( $ code , $ message , $ file , $ line ) { if ( error_reporting ( ) === 0 ) { return false ; } throw new \ sb \ Exception ( $ code , $ message , $ file , $ line ) ; }
|
Converts errors into exceptions
|
11,905
|
public static function exceptionHandler ( $ e ) { $ message = 'Code: ' . $ e -> getCode ( ) . "\n" . 'Path: ' . \ sb \ Gateway :: $ request -> path . "\n" . 'Message: ' . $ e -> getMessage ( ) . "\n" . 'Location: ' . $ e -> getFile ( ) . "\n" . 'Line: ' . $ e -> getLine ( ) . "\n" ; if ( isset ( \ sb \ Gateway :: $ request ) ) { $ message .= 'Request: ' . \ sb \ Gateway :: $ request -> request . "\n" ; if ( isset ( \ sb \ Gateway :: $ request -> method ) ) { $ message .= 'Method: ' . \ sb \ Gateway :: $ request -> method . "\n" ; } if ( count ( \ sb \ Gateway :: $ request -> get ) ) { $ message .= 'Get: ' . http_build_query ( \ sb \ Gateway :: $ request -> get ) . "\n" ; } } if ( self :: $ show_trace ) { $ message .= "Trace: \n\t" . str_replace ( "\n" , "\n\t" , \ print_r ( $ e -> getTrace ( ) , 1 ) ) ; } if ( \ method_exists ( "\App" , "exception_handler" ) ) { if ( \ App :: exceptionHandler ( $ e , $ message ) === false ) { return false ; } } if ( \ ini_get ( "display_errors" ) == true ) { if ( \ sb \ Gateway :: $ command_line ) { \ file_put_contents ( 'php://stderr' , "\n" . $ message . "\n" ) ; } else { echo '<pre style="background-color:red;padding:10px;color:#FFF;">' . $ message . '</pre>' ; } } if ( ! isset ( \ App :: $ logger ) ) { \ App :: $ logger = new \ sb \ Logger \ FileSystem ( ) ; } \ App :: $ logger -> exceptions ( $ message ) ; }
|
Handles acceptions and turns them into strings
|
11,906
|
public static function shutdown ( ) { if ( \ is_null ( $ e = \ error_get_last ( ) ) === false ) { self :: exceptionHandler ( new \ sb \ Exception ( $ e [ 'type' ] , $ e [ 'message' ] , $ e [ 'file' ] , $ e [ 'line' ] ) ) ; } }
|
Shutdown function catches additional parse errors
|
11,907
|
public static function init ( $ error_reporting_level = E_ALL , $ display_errors = true , $ show_trace = true ) { \ error_reporting ( $ error_reporting_level ) ; \ ini_set ( "display_errors" , $ display_errors ? true : false ) ; self :: $ show_trace = $ show_trace ? true : false ; \ set_error_handler ( '\sb\Application\Debugger::errorHandler' ) ; \ set_exception_handler ( '\sb\Application\Debugger::exceptionHandler' ) ; \ register_shutdown_function ( '\sb\Application\Debugger::shutdown' ) ; }
|
Sets up debugger
|
11,908
|
public static function availableTypes ( ) { return [ self :: VALUE_INT , self :: VALUE_STRING , self :: VALUE_BOOL , self :: VALUE_FLOAT , self :: VALUE_DEFAULT , self :: VALUE_NON_EXISTS , self :: VALUE_EMPTY , self :: VALUE_ARRAY , ] ; }
|
Get Available Value Types
|
11,909
|
public static function availableDefaultValues ( ) { return [ self :: DEFAULT_NULL , self :: DEFAULT_OUT_OF_BOUNDS , self :: DEFAULT_NOT_DERIVABLE , self :: DEFAULT_NOT_GIVEN , self :: DEFAULT_NOT_ASKED , self :: DEFAULT_NOT_PERMITTED , ] ; }
|
Get Available Default Values
|
11,910
|
public function transform ( $ value ) { if ( $ value === null || $ value == '' ) { return null ; } if ( ! ( $ value instanceof User ) ) { throw new TransformationFailedException ( 'Expected an instance of a concrete5 user object.' ) ; } return intval ( $ value -> getUserID ( ) ) ; }
|
Converts a concrete5 user object to an integer .
|
11,911
|
public function help ( $ event_name , $ callback ) { if ( ! isset ( $ this -> event_helpers [ $ event_name ] ) ) { $ this -> event_helpers [ $ event_name ] = $ callback ; } }
|
add a helper callback to an event
|
11,912
|
public function sendContent ( SendResponseEvent $ e ) { $ response = $ e -> getResponse ( ) ; if ( ! $ response instanceof ApiProblemResponse ) { return $ this ; } $ response -> getApiProblem ( ) -> setDetailIncludesStackTrace ( $ this -> displayExceptions ( ) ) ; $ request = $ this -> getMvcEvent ( ) -> getRequest ( ) ; $ accept = $ request -> getHeader ( 'Accept' ) ; if ( $ accept instanceof Accept && $ accept -> hasMediaType ( 'text/xml' ) ) { $ arrayResponse = $ response -> getApiProblem ( ) -> toArray ( ) ; $ xmlWriter = new XmlWriter ( ) ; if ( array_key_exists ( 'trace' , $ arrayResponse ) ) { array_walk ( $ arrayResponse [ 'trace' ] , function ( & $ item ) { unset ( $ item [ 'args' ] ) ; } ) ; } if ( array_key_exists ( 'exception_stack' , $ arrayResponse ) ) { array_walk ( $ arrayResponse [ 'exception_stack' ] , function ( & $ item ) { array_walk ( $ item [ 'trace' ] , function ( & $ trace ) { unset ( $ trace [ 'args' ] ) ; } ) ; } ) ; } $ output = $ xmlWriter -> processConfig ( $ arrayResponse ) ; echo $ output ; $ e -> setContentSent ( ) ; return $ this ; } return parent :: sendHeaders ( $ e ) ; }
|
Send the response content
|
11,913
|
public function sendHeaders ( SendResponseEvent $ e ) { $ response = $ e -> getResponse ( ) ; if ( ! $ response instanceof ApiProblemResponse ) { return $ this ; } $ request = $ this -> getMvcEvent ( ) -> getRequest ( ) ; $ accept = $ request -> getHeader ( 'Accept' ) ; if ( $ accept instanceof Accept && $ accept -> hasMediaType ( 'text/xml' ) ) { $ headers = $ response -> getHeaders ( ) ; if ( $ headers -> has ( 'content-type' ) ) { $ contentTypeHeader = $ headers -> get ( 'content-type' ) ; $ headers -> removeHeader ( $ contentTypeHeader ) ; } $ headers -> addHeaderLine ( 'content-type' , 'text/xml' ) ; if ( $ this -> applicationResponse instanceof HttpResponse ) { $ this -> mergeHeaders ( $ this -> applicationResponse , $ response ) ; } } return parent :: sendHeaders ( $ e ) ; }
|
Send HTTP response headers
|
11,914
|
public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { $ signature = ( $ this -> signature ) ( $ request ) ; if ( ! is_array ( $ signature ) ) { throw new OwnershipSignatureTypeException ( $ signature ) ; } $ metadata = $ _SESSION [ self :: METADATA_KEY ] ?? [ ] ; if ( ! $ this -> compare ( $ signature , $ metadata ) ) { $ _SESSION = [ ] ; session_regenerate_id ( ) ; } $ response = $ handler -> handle ( $ request ) ; $ _SESSION [ self :: METADATA_KEY ] = $ signature ; return $ response ; }
|
Build a signature and compare it to the ownership metadata stored in session . Invalidate the session when any key does not match . Process the request and save the current signature in session .
|
11,915
|
private function compare ( array $ signature , array $ metadata ) : bool { foreach ( $ signature as $ key => $ v1 ) { $ v2 = $ metadata [ $ key ] ?? null ; if ( ! is_null ( $ v2 ) && $ v1 !== $ v2 ) return false ; } return true ; }
|
Return whether all keys of the given signature match the given metadata .
|
11,916
|
public function configureLogger ( $ logger , $ level , $ logPath = null ) { $ monolog = $ logger ; switch ( $ level ) { case 'emergency' : case 'emerg' : $ level = Logger :: EMERGENCY ; break ; case 'alert' : $ level = Logger :: ALERT ; break ; case 'critical' : case 'crit' : $ level = Logger :: CRITICAL ; break ; case 'error' : case 'err' : $ level = Logger :: ERROR ; break ; case 'warning' : case 'warn' : $ level = Logger :: WARNING ; break ; case 'notice' : $ level = Logger :: NOTICE ; break ; case 'info' : $ level = Logger :: INFO ; break ; case 'debug' : $ level = Logger :: DEBUG ; break ; } $ this [ 'monolog.level' ] = $ level ; if ( $ logPath ) { $ logPath = str_replace ( array ( '{APP_ROOT}' , '{DATE}' ) , array ( realpath ( __DIR__ . '/../..' ) , $ this [ 'kernel.timer.start' ] ) , $ logPath ) ; $ this [ 'monolog.logfile' ] = $ logPath ; } try { while ( $ monolog -> popHandler ( ) ) { } } catch ( \ LogicException $ e ) { } if ( $ level === 'quiet' ) { $ monolog -> pushHandler ( new NullHandler ( ) ) ; return ; } if ( $ logPath ) { $ monolog -> pushHandler ( new StreamHandler ( $ logPath , $ level ) ) ; } else { $ monolog -> pushHandler ( new StreamHandler ( 'php://stdout' , $ level ) ) ; } }
|
Removes all logging handlers and replaces them with handlers that can write to the given logPath and level .
|
11,917
|
protected function addLogging ( ) { $ this -> register ( new MonologServiceProvider ( ) , array ( 'monolog.name' => 'phpDocumentor' , 'monolog.logfile' => sys_get_temp_dir ( ) . '/phpdoc.log' , 'monolog.debugfile' => sys_get_temp_dir ( ) . '/phpdoc.debug.log' , 'monolog.level' => Logger :: INFO , ) ) ; $ app = $ this ; $ configuration = $ this [ 'config' ] ; $ this [ 'monolog.configure' ] = $ this -> protect ( function ( $ log ) use ( $ app , $ configuration ) { $ paths = $ configuration -> getLogging ( ) -> getPaths ( ) ; $ logLevel = $ configuration -> getLogging ( ) -> getLevel ( ) ; $ app -> configureLogger ( $ log , $ logLevel , $ paths [ 'default' ] , $ paths [ 'errors' ] ) ; } ) ; $ this -> extend ( 'console' , function ( ConsoleApplication $ console ) use ( $ configuration ) { $ console -> getHelperSet ( ) -> set ( new LoggerHelper ( ) ) ; $ console -> getHelperSet ( ) -> set ( new ConfigurationHelper ( $ configuration ) ) ; return $ console ; } ) ; ErrorHandler :: register ( $ this [ 'monolog' ] ) ; }
|
Adds a logging provider to the container of phpDocumentor .
|
11,918
|
public static function generateSuffixedIdentName ( array $ identNames , $ suffix ) { $ ident = implode ( "_" , $ identNames ) . "_" . $ suffix ; $ i = 0 ; $ last = - 1 ; while ( strlen ( $ ident ) > self :: IDENTIFIER_MAX_LENGTH ) { if ( strlen ( $ identNames [ $ i ] ) > 1 || $ last == $ i ) { $ identNames [ $ i ] = substr ( $ identNames [ $ i ] , 0 , strlen ( $ identNames [ $ i ] ) - 1 ) ; $ last = $ i ; } $ i = ( $ i + 1 ) % count ( $ identNames ) ; $ ident = implode ( "_" , $ identNames ) . "_" . $ suffix ; } return $ ident ; }
|
Generate single identifier name for constraints for example obeying oracle 30 chars ident restriction .
|
11,919
|
protected function createInstallOneOfRule ( array $ packages , $ reason , $ job ) { $ literals = array ( ) ; foreach ( $ packages as $ package ) { $ literals [ ] = $ package -> id ; } return new Rule ( $ literals , $ reason , $ job [ 'packageName' ] , $ job ) ; }
|
Creates a rule to install at least one of a set of packages
|
11,920
|
protected function createRemoveRule ( PackageInterface $ package , $ reason , $ job ) { return new Rule ( array ( - $ package -> id ) , $ reason , $ job [ 'packageName' ] , $ job ) ; }
|
Creates a rule to remove a package
|
11,921
|
protected function createConflictRule ( PackageInterface $ issuer , PackageInterface $ provider , $ reason , $ reasonData = null ) { if ( $ issuer === $ provider ) { return null ; } return new Rule ( array ( - $ issuer -> id , - $ provider -> id ) , $ reason , $ reasonData ) ; }
|
Creates a rule for two conflicting packages
|
11,922
|
private function addRule ( $ type , Rule $ newRule = null ) { if ( ! $ newRule || $ this -> rules -> containsEqual ( $ newRule ) ) { return ; } $ this -> rules -> add ( $ newRule , $ type ) ; }
|
Adds a rule unless it duplicates an existing one of any type
|
11,923
|
public function parse ( ) { if ( ! is_string ( $ this -> data ) ) { throw new \ RuntimeException ( 'The given data is no valid string' ) ; } libxml_use_internal_errors ( true ) ; $ xml = simplexml_load_string ( $ this -> data ) ; if ( $ xml === false ) { throw new \ RuntimeException ( 'Error during the loading of the XML file' ) ; } if ( ! isset ( $ xml -> executables , $ xml -> excludes ) ) { throw new \ RuntimeException ( 'Missing configuration elements' ) ; } foreach ( $ xml -> excludes -> children ( ) -> file as $ file ) { $ this -> config -> addExcludedFile ( ( string ) $ file ) ; } foreach ( $ xml -> excludes -> children ( ) -> dir as $ dir ) { $ this -> config -> addExcludedDir ( ( string ) $ dir ) ; } foreach ( $ xml -> executables -> children ( ) as $ file ) { $ this -> config -> addExecutableFile ( ( string ) $ file ) ; } return $ this -> config ; }
|
Load the configuration and return it in an easy to use config bag .
|
11,924
|
protected function build_input ( $ data , array $ fields = [ ] ) { $ input = $ this -> get_open_tag ( $ data , $ fields ) ; $ counter = 1 ; foreach ( $ this -> get_options ( ) as $ key => $ label ) { $ input .= $ this -> get_option ( $ key , $ label , $ counter , $ data , $ fields ) ; $ counter ++ ; } $ input .= $ this -> close_tag ; return $ input ; }
|
Show input labels
|
11,925
|
public function get ( $ method , array $ params , array $ options = array ( ) ) { $ this -> parseOptions ( $ options ) ; $ params = array_merge ( $ params , $ this -> apiKeys ) ; $ response = $ this -> httpAdapter -> getContent ( sprintf ( self :: API_ENDPOINT , $ this -> scheme , $ this -> outputFormat , $ method . '?' . http_build_query ( $ params ) ) , $ this -> headers ) ; return $ this -> responseHandler ( $ response ) ; }
|
Calls the Eventbrite API via GET
|
11,926
|
private function parseOptions ( array $ options ) { if ( isset ( $ options [ 'headers' ] ) && is_array ( $ options [ 'headers' ] ) ) { $ this -> headers = $ options [ 'headers' ] ; } if ( isset ( $ options [ 'scheme' ] ) && strtolower ( $ options [ 'scheme' ] ) === 'http' ) { $ this -> scheme = 'http' ; } if ( isset ( $ options [ 'output_format' ] ) && strtolower ( $ options [ 'output_format' ] ) === 'xml' ) { $ this -> outputFormat = 'xml' ; } }
|
Parser for options like scheme headers and output format .
|
11,927
|
private function responseHandler ( $ responseBody ) { if ( 'json' === $ this -> outputFormat ) { return $ this -> validateJsonResponse ( $ responseBody ) ; } return $ this -> validateXmlResponse ( $ responseBody ) ; }
|
Handler for validate the response body .
|
11,928
|
private function validateJsonResponse ( $ responseBody ) { $ data = json_decode ( $ responseBody ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { throw new \ Exception ( 'Error decoding JSON.' ) ; } if ( isset ( $ data -> error ) ) { throw new \ Exception ( $ data -> error -> error_message ) ; } if ( empty ( $ data ) ) { throw new \ Exception ( 'No results found.' ) ; } return $ responseBody ; }
|
Parses the response content for the JSON output format
|
11,929
|
private function validateXmlResponse ( $ responseBody ) { $ data = simplexml_load_string ( $ responseBody ) ; if ( isset ( $ data -> error_type ) ) { throw new \ Exception ( $ data -> error_message ) ; } return $ responseBody ; }
|
Parses the response content for the XML output format
|
11,930
|
public function getTypes ( $ number ) { $ binstring = decbin ( ( int ) $ number ) ; $ types = array ( ) ; $ mlen = strlen ( $ binstring ) - 3 ; $ low = substr ( $ binstring , $ mlen , strlen ( $ binstring ) ) ; $ high = substr ( $ binstring , 0 , $ mlen ) . '0000' ; $ types [ 'wired' ] = bindec ( $ low ) ; $ types [ 'field' ] = bindec ( $ binstring ) >> 3 ; return $ types ; }
|
Get the wired_type and field_type
|
11,931
|
public function serializeToString ( $ rec = - 1 ) { $ string = '' ; if ( $ rec > - 1 ) { $ string .= $ this -> base128 -> setValue ( $ rec << 3 | $ this -> wired_type ) ; } $ stringinner = '' ; foreach ( $ this -> fields as $ index => $ field ) { if ( is_array ( $ this -> values [ $ index ] ) && count ( $ this -> values [ $ index ] ) > 0 ) { foreach ( $ this -> values [ $ index ] as $ array ) { $ newstring = '' ; if ( method_exists ( $ array , 'serializeToString' ) ) { $ newstring .= $ array -> serializeToString ( $ index ) ; } $ stringinner .= $ newstring ; } } elseif ( $ this -> values [ $ index ] !== null ) { $ newstring = '' ; if ( method_exists ( $ this -> values [ $ index ] , 'serializeToString' ) ) { $ newstring .= $ this -> values [ $ index ] -> serializeToString ( $ index ) ; } $ stringinner .= $ newstring ; } } $ this -> serializeChunk ( $ stringinner ) ; if ( $ this -> wired_type === PBMessage :: WIRED_LENGTH_DELIMITED && $ rec > - 1 ) { $ stringinner = $ this -> base128 -> setValue ( strlen ( $ stringinner ) / PBMessage :: MODUS ) . $ stringinner ; } return $ string . $ stringinner ; }
|
Encodes a Message
|
11,932
|
protected function addArrValue ( $ index ) { $ class_name = $ this -> fields [ $ index ] ; $ real_class_name = __NAMESPACE__ . "\\" . $ class_name ; return $ this -> values [ $ index ] [ ] = new $ real_class_name ( ) ; }
|
Add an array value
|
11,933
|
protected function setValue ( $ index , $ value ) { if ( gettype ( $ value ) === 'object' ) { $ this -> values [ $ index ] = $ value ; } else { $ class_name = $ this -> fields [ $ index ] ; $ real_class_name = __NAMESPACE__ . "\\" . $ class_name ; $ this -> values [ $ index ] = new $ real_class_name ( ) ; $ this -> values [ $ index ] -> value = $ value ; } return $ this ; }
|
Set an value
|
11,934
|
protected function saveString ( $ ch , $ string ) { $ this -> dString .= $ string ; $ content_length = strlen ( $ this -> dString ) ; return strlen ( $ string ) ; }
|
Helper method for send string
|
11,935
|
public function failure ( Exception $ e , Delivery $ delivery , AbstractListener $ listener ) { $ listener -> resend ( $ delivery ) ; }
|
Handle any exception during queued message data processing .
|
11,936
|
public function toString ( $ indent = null ) { $ helperManager = $ this -> getView ( ) -> getHelperPluginManager ( ) ; if ( $ helperManager -> has ( 'dojo' ) ) { $ dojo = $ helperManager -> get ( 'dojo' ) ; $ dojo -> initialize ( ) ; } return parent :: toString ( $ indent ) ; }
|
Find an initialize Dojo helper before rendering head scripts
|
11,937
|
public function addTranslations ( $ filename , $ locale = self :: DEFAULT_LOCALE , $ textDomain = self :: DEFAULT_DOMAIN ) { parent :: addTranslationFile ( self :: TRANSLATION_FILE_TYPE , $ filename , $ textDomain , $ locale ) ; $ this -> messages = array ( ) ; return $ this ; }
|
Adds a translation file for a specific locale or the default locale when none is provided .
|
11,938
|
public function addTranslationFolder ( $ folder , array $ domains = array ( ) ) { if ( empty ( $ domains ) ) { $ domains = array ( self :: DEFAULT_DOMAIN ) ; } foreach ( $ domains as $ domain ) { $ this -> addTranslationsUsingPattern ( $ folder , $ domain ) ; } return $ this ; }
|
Adds a folder with files containing translation sources .
|
11,939
|
public function addTranslationsUsingPattern ( $ baseDir , $ textDomain = self :: DEFAULT_DOMAIN , $ pattern = self :: DEFAULT_PATTERN ) { if ( $ textDomain !== self :: DEFAULT_DOMAIN && $ pattern === self :: DEFAULT_PATTERN ) { $ pattern = $ textDomain . '.' . $ pattern ; } parent :: addTranslationFilePattern ( self :: TRANSLATION_FILE_TYPE , $ baseDir , $ pattern , $ textDomain ) ; $ this -> messages = array ( ) ; return $ this ; }
|
Adds a series of translation files given a pattern .
|
11,940
|
public function translate ( $ message , $ textDomain = self :: DEFAULT_DOMAIN , $ locale = null ) { return parent :: translate ( $ message , $ textDomain , $ locale ) ; }
|
Attempts to translate the given message or code into the provided locale .
|
11,941
|
private function insertUpdate ( $ parentUpdate , $ update ) { $ el = $ update instanceof ElementDependentLayoutUpdateInterface ? $ update -> getElement ( ) : 'root' ; $ parentUpdateIndex = array_search ( $ parentUpdate , $ this -> updates [ $ el ] ) ; $ this -> updates [ $ el ] = array_merge ( array_slice ( $ this -> updates [ $ el ] , 0 , $ parentUpdateIndex , true ) , [ $ update ] , array_slice ( $ this -> updates [ $ el ] , $ parentUpdateIndex , null , true ) ) ; }
|
Insert import update right after its parent update
|
11,942
|
function dispatch ( $ uri ) { $ old_handler = set_error_handler ( array ( $ this , 'error_handler' ) , 5888 ) ; ob_start ( ) ; $ level = ob_get_level ( ) ; $ this -> map_uri_to_response ( $ this -> clean_request_uri ( ( string ) $ uri ) ) -> output ( ) ; while ( ob_get_level ( ) >= $ level ) { ob_end_flush ( ) ; } if ( isset ( $ old_handler ) ) { set_error_handler ( $ old_handler ) ; } }
|
Maps a string to a response which is then rendered .
|
11,943
|
function perform ( $ unconsumed ) { list ( $ action , $ args , $ format ) = $ this -> extract_action_and_args ( $ unconsumed ) ; $ this -> format = isset ( $ format ) ? $ format : 'html' ; $ before_filter_result = $ this -> before_filter ( $ action , $ args ) ; if ( ! ( FALSE === $ before_filter_result || $ this -> performed ) ) { $ mapped_action = $ this -> map_action ( $ action ) ; if ( method_exists ( $ this , $ mapped_action ) ) { call_user_func_array ( array ( & $ this , $ mapped_action ) , $ args ) ; } else { $ this -> does_not_understand ( $ action , $ args ) ; } if ( ! $ this -> performed ) { $ this -> render_action ( $ action ) ; } $ this -> after_filter ( $ action , $ args ) ; } return $ this -> response ; }
|
This method extracts an action string and further arguments from it s parameter . The action string is mapped to a method being called afterwards using the said arguments . That method is called and a response object is generated populated and sent back to the dispatcher .
|
11,944
|
function extract_action_and_args ( $ string ) { if ( '' === $ string ) { return array ( 'index' , array ( ) , NULL ) ; } $ format = NULL ; if ( preg_match ( '/^(.*[^\/.])\.(\w+)$/' , $ string , $ matches ) ) { list ( $ _ , $ string , $ format ) = $ matches ; } $ args = explode ( '/' , $ string ) ; $ action = array_shift ( $ args ) ; return array ( $ action , $ args , $ format ) ; }
|
Extracts action and args from a string .
|
11,945
|
function url_for ( $ to ) { $ args = func_get_args ( ) ; $ args = array_map ( 'urlencode' , $ args ) ; $ args [ 0 ] = $ to ; return $ this -> dispatcher -> trails_uri . '/' . join ( '/' , $ args ) ; }
|
Returns a URL to a specified route to your Trails application .
|
11,946
|
public function getContainer ( ) { $ mutex = new Mutex ( $ this -> file . '.lock' , true ) ; $ ret = $ mutex -> run ( function ( ) { if ( $ this -> needsRecompile ( ) ) { file_put_contents ( $ this -> file , $ this -> compileContainerCode ( ) ) ; } return include $ this -> file ; } ) ; if ( ! ( $ ret instanceof Container ) ) { throw new \ LogicException ( "The container must be returned by the compiler" ) ; } foreach ( $ this -> plugins as $ plugin ) { $ ret -> addPlugin ( $ plugin ) ; } return $ ret ; }
|
Writes the code to a temporary file and returns the resulting Container object .
|
11,947
|
protected function needsRecompile ( ) { clearstatcache ( ) ; return ! is_file ( $ this -> file ) || ( ( ! empty ( $ this -> configTree [ 'z' ] [ 'sources' ] ) && max ( array_map ( 'filemtime' , $ this -> configTree [ 'z' ] [ 'sources' ] ) ) >= filemtime ( $ this -> file ) ) ) ; }
|
Crude check for whether a recompile is needed .
|
11,948
|
public function compileContainerCode ( ) { $ builder = new ContainerBuilder ( $ this -> configTree ) ; foreach ( $ this -> plugins as $ name => $ plugin ) { $ plugin -> setContainerBuilder ( $ builder ) ; } $ containerNode = $ builder -> build ( ) ; $ buffer = new Buffer ( ) ; $ buffer -> write ( '<?php' ) -> eol ( ) ; $ containerNode -> compile ( $ buffer ) ; $ buffer -> writeln ( 'return $z;' ) ; $ code = $ buffer -> getResult ( ) ; return $ code ; }
|
Returns the code for initializing the container .
|
11,949
|
public static function instances ( ) { $ all = [ ] ; foreach ( static :: getNames ( ) as $ name => $ val ) { $ all [ ] = new static ( $ name , $ val ) ; } return $ all ; }
|
Gets all enums
|
11,950
|
public static function nameOf ( $ value ) { $ values = static :: getValues ( ) ; return isset ( $ values [ $ value ] ) ? $ values [ $ value ] : null ; }
|
Gets the name for the enum value
|
11,951
|
public static function valueOf ( $ name ) { $ names = static :: getNames ( ) ; return isset ( $ names [ $ name ] ) ? $ names [ $ name ] : null ; }
|
Gets the enum value for the name
|
11,952
|
public static function fromName ( $ name ) { $ names = static :: getNames ( ) ; if ( array_key_exists ( $ name , $ names ) ) { return new static ( $ name , $ names [ $ name ] ) ; } throw new \ InvalidArgumentException ( "No enum constant '$name' in class " . get_called_class ( ) ) ; }
|
Gets the enum instance for the name
|
11,953
|
public static function fromValue ( $ value ) { $ values = static :: getValues ( ) ; if ( array_key_exists ( $ value , $ values ) ) { return new static ( $ values [ $ value ] , $ value ) ; } throw new \ InvalidArgumentException ( "No enum constant value '$value' class " . get_called_class ( ) ) ; }
|
Gets the enum instance for the value
|
11,954
|
public function s2o ( $ sql , $ params = null , $ class_name = '' ) { if ( is_array ( $ params ) || is_object ( $ params ) ) { $ param = is_array ( $ params ) ? $ params : self :: paramify ( $ params ) ; $ stmt = $ this -> prepare ( $ sql ) ; $ result = $ stmt -> execute ( $ params ) ; if ( ! $ result ) { return Array ( ) ; } } else { $ result = $ this -> query ( $ sql ) ; if ( ! is_object ( $ result ) ) { return Array ( ) ; } else { $ stmt = $ result ; } } if ( ! preg_match ( "~^SELECT|EXEC|CALL~i" , trim ( $ sql ) ) ) { return $ stmt ; } elseif ( ! empty ( $ class_name ) ) { if ( class_exists ( $ class_name ) ) { return $ stmt -> fetchAll ( \ PDO :: FETCH_CLASS , $ class_name ) ; } } else { return $ stmt -> fetchAll ( \ PDO :: FETCH_OBJ ) ; } }
|
Turn a sql query into an array of objects representing each row returned
|
11,955
|
public static function paramify ( $ data , $ omit = Array ( ) ) { $ params = Array ( ) ; if ( is_object ( $ data ) ) { $ data = get_object_vars ( $ data ) ; } if ( is_array ( $ data ) ) { foreach ( $ data as $ key => $ val ) { if ( ! in_array ( $ key , $ omit ) ) { $ params [ ':' . $ key ] = $ val ; } } } return $ params ; }
|
Converts an array into a bound params hash
|
11,956
|
public function prepare ( $ sql , $ driver_options = array ( ) ) { $ md5 = md5 ( $ sql ) ; if ( isset ( $ this -> prepared_sql [ $ md5 ] ) ) { return $ this -> prepared_sql [ $ md5 ] ; } $ stmt = parent :: prepare ( $ sql , $ driver_options ) ; $ this -> prepared_sql [ $ md5 ] = $ stmt ; return $ stmt ; }
|
Used to prepare and store sql statements for value binding
|
11,957
|
protected function printLicenses ( CompletePackageInterface $ package ) { $ spdxLicense = new SpdxLicense ; $ licenses = $ package -> getLicense ( ) ; foreach ( $ licenses as $ licenseId ) { $ license = $ spdxLicense -> getLicenseByIdentifier ( $ licenseId ) ; if ( ! $ license ) { $ out = $ licenseId ; } else { if ( $ license [ 1 ] === true ) { $ out = sprintf ( '%s (%s) (OSI approved) %s' , $ license [ 0 ] , $ licenseId , $ license [ 2 ] ) ; } else { $ out = sprintf ( '%s (%s) %s' , $ license [ 0 ] , $ licenseId , $ license [ 2 ] ) ; } } $ this -> getIO ( ) -> write ( '<info>license</info> : ' . $ out ) ; } }
|
Prints the licenses of a package with metadata
|
11,958
|
protected function filterElements ( Collection $ collection , AdminMenu $ parent = null ) { $ children = $ collection -> filter ( function ( AdminMenu $ menuItem ) use ( $ parent ) { return $ menuItem -> getParent ( ) === $ parent ; } ) ; return $ children ; }
|
Filters the collection and returns only children elements for given parent element
|
11,959
|
public function getCompiler ( ) { if ( ! $ this -> compiler instanceof AbstractCompiler ) { if ( null === $ this -> compiler ) { throw new \ Exception ( 'Compiler not set' ) ; } $ compiler = $ this -> getView ( ) -> getHelperPluginManager ( ) -> getServiceLocator ( ) -> get ( $ this -> compiler ) ; if ( ! $ compiler instanceof AbstractCompiler ) { throw new \ Exception ( sprintf ( 'Invalid compiler type: %s not instance of Spork\CSS\AbstractCompiler' , is_object ( $ compiler ) ? get_class ( $ compiler ) : gettype ( $ compiler ) ) ) ; } $ this -> compiler = $ compiler ; } return $ this -> compiler ; }
|
Get compiler instance
|
11,960
|
protected function initializeResolver ( ) { $ extensions = $ this -> getCompiler ( ) -> getExtensions ( ) ; $ resolver = $ this -> resolver = new AggregateResolver ( ) ; $ stack = array ( $ this -> getView ( ) -> resolver ( ) ) ; while ( $ source = array_shift ( $ stack ) ) { if ( $ source instanceof AggregateResolver ) { foreach ( $ source as $ child ) { array_push ( $ stack , $ child ) ; } } elseif ( $ source instanceof TemplatePathStack ) { foreach ( $ extensions as $ extension ) { $ child = clone $ source ; $ child -> setDefaultSuffix ( $ extension ) ; $ resolver -> attach ( $ child ) ; } } else { $ resolver -> attach ( $ source ) ; } } }
|
Initializes Resolver to find files by mimicking the default template resolver and using compiler extensions .
|
11,961
|
public function getGuards ( ) : array { if ( $ this -> guards ) { return $ this -> guards ; } if ( empty ( $ this -> guardsConfig ) ) { return [ ] ; } $ this -> guards = [ ] ; foreach ( $ this -> guardsConfig as $ guardConfig ) { $ this -> guards [ ] = $ this -> getGuardFactory ( ) -> create ( $ guardConfig ) ; } $ this -> sortGuardsByPriority ( ) ; return $ this -> guards ; }
|
Gets the cached guard list or creates it from the config
|
11,962
|
protected function sortGuardsByPriority ( ) { usort ( $ this -> guards , function ( GuardInterface $ a , GuardInterface $ b ) { return $ b -> getPriority ( ) - $ a -> getPriority ( ) ; } ) ; }
|
Sort the guards list internally
|
11,963
|
public function getFilters ( ) { $ parser = \ Parsedown :: instance ( ) ; $ translator = $ this -> translator ; $ routeRenderer = $ this -> routeRenderer ; return array ( 'markdown' => new \ Twig_SimpleFilter ( 'markdown' , function ( $ value ) use ( $ parser ) { return $ parser -> text ( $ value ) ; } ) , 'trans' => new \ Twig_SimpleFilter ( 'trans' , function ( $ value , $ context ) use ( $ translator ) { if ( ! $ context ) { $ context = array ( ) ; } return vsprintf ( $ translator -> translate ( $ value ) , $ context ) ; } ) , 'route' => new \ Twig_SimpleFilter ( 'route' , function ( $ value , $ presentation = 'normal' ) use ( $ routeRenderer ) { return $ routeRenderer -> render ( $ value , $ presentation ) ; } ) , 'sort' => new \ Twig_SimpleFilter ( 'sort_*' , function ( $ direction , $ collection ) { if ( ! $ collection instanceof Collection ) { return $ collection ; } $ iterator = $ collection -> getIterator ( ) ; $ iterator -> uasort ( function ( $ a , $ b ) use ( $ direction ) { $ aElem = strtolower ( $ a -> getName ( ) ) ; $ bElem = strtolower ( $ b -> getName ( ) ) ; if ( $ aElem === $ bElem ) { return 0 ; } if ( $ direction === 'asc' && $ aElem > $ bElem || $ direction === 'desc' && $ aElem < $ bElem ) { return 1 ; } return - 1 ; } ) ; return $ iterator ; } ) , ) ; }
|
Returns a list of all filters that are exposed by this extension .
|
11,964
|
public function virtualToScalable ( $ event ) { if ( ( $ this -> scalableAttributeName ( ) !== null ) && ( $ this -> virtualAttributesNames ( ) !== null ) ) { $ data = [ ] ; foreach ( $ this -> virtualAttributesNames ( ) as $ name ) { if ( ! empty ( $ this -> owner -> { $ name } ) ) { $ data [ $ name ] = $ this -> owner -> { $ name } ; } } $ this -> owner -> { $ this -> scalableAttributeName ( ) } = $ this -> convert ( $ data ) ; } }
|
Converts configured attributes before saving them to database
|
11,965
|
public function scalableToVirtual ( $ event = null ) { if ( ( $ this -> scalableAttributeName ( ) !== null ) && ( $ this -> virtualAttributesNames ( ) !== null ) ) { $ virtualAttributesConf = [ ] ; foreach ( $ this -> virtualAttributesNames ( ) as $ name ) { $ virtualAttributesConf [ $ name ] = '' ; } $ virtualAttributesNames = ArrayHelper :: merge ( $ virtualAttributesConf , ( ( $ a = $ this -> unConvert ( $ this -> owner -> { $ this -> scalableAttributeName ( ) } ) ) !== null ) ? $ a : [ ] ) ; foreach ( $ virtualAttributesNames as $ name => $ value ) { if ( in_array ( $ name , $ this -> virtualAttributesNames ( ) ) ) { $ this -> owner -> { $ name } = $ value ; } } } }
|
Checks if the defined attributes are unserializeable and unserializes their values
|
11,966
|
public function convert ( $ data ) { if ( empty ( $ data ) || ( $ out = @ serialize ( $ data ) ) === false ) return null ; return $ out ; }
|
Converts some input to a serialized string
|
11,967
|
public function unConvert ( $ data ) { if ( empty ( $ data ) || ! is_string ( $ data ) || ( $ out = @ unserialize ( $ data ) ) === false ) return null ; if ( ! is_array ( $ out ) || empty ( $ out ) ) return null ; return $ out ; }
|
Unconverts a serialized string into an array
|
11,968
|
public function scalableAttributeName ( ) { if ( $ this -> _scalableAttribute !== null ) return $ this -> _scalableAttribute ; if ( in_array ( ( string ) $ this -> scalableAttribute , $ this -> objAttributesNames ( ) ) ) return $ this -> _scalableAttribute = $ this -> scalableAttribute ; return null ; }
|
Verifies the configured scalable attribute
|
11,969
|
public function virtualAttributesNames ( ) { if ( ! empty ( $ this -> _virtualAttributes ) ) return $ this -> _virtualAttributes ; if ( ! is_array ( $ this -> virtualAttributes ) || empty ( $ this -> virtualAttributes ) ) return null ; $ attributes = [ ] ; foreach ( $ this -> virtualAttributes as $ a ) { if ( ! in_array ( $ a , $ this -> objAttributesNames ( ) ) && ! in_array ( $ a , $ attributes ) ) { $ attributes [ ] = $ a ; } } return ! empty ( $ attributes ) ? $ this -> _virtualAttributes = $ attributes : null ; }
|
Verifies the configured virtual attributes
|
11,970
|
public function validateId ( $ attribute , $ params ) { foreach ( Yii :: $ app -> user -> getLoginPriority ( ) as $ item ) { if ( $ item :: validate ( $ this -> $ attribute ) ) { return ; } } $ this -> addError ( $ attribute , Yii :: t ( 'user' , 'Incorrect ID.' ) ) ; }
|
Validates the ID .
|
11,971
|
public static function increment ( string $ str , int $ first = 1 , string $ separator = '_' ) : string { preg_match ( '/(.+)' . $ separator . '([0-9]+)$/' , $ str , $ match ) ; return isset ( $ match [ 2 ] ) ? $ match [ 1 ] . $ separator . ( $ match [ 2 ] + 1 ) : $ str . $ separator . $ first ; }
|
Add s _1 to a string or increment the ending number to allow _2 _3 etc
|
11,972
|
public static function safeString ( string $ str , string $ delimiter = '-' , bool $ lowercase = false ) : string { $ str = filter_var ( $ str , FILTER_SANITIZE_STRING ) ; $ str = html_entity_decode ( $ str , ENT_QUOTES , 'UTF-8' ) ; $ reserved_characters = array ( '/' , '?' , ':' , '@' , '#' , '[' , ']' , '!' , '$' , '&' , '\'' , '(' , ')' , '*' , '+' , ',' , ';' , '=' ) ; $ str = str_replace ( $ reserved_characters , ' ' , $ str ) ; setlocale ( LC_ALL , 'en_US.UTF8' ) ; $ str = Text :: translitIt ( $ str ) ; $ str = iconv ( 'UTF-8' , 'ASCII//TRANSLIT' , $ str ) ; $ str = preg_replace ( "/[^a-zA-Z0-9\/_|+ -]/" , '' , $ str ) ; if ( $ delimiter != null ) { $ str = preg_replace ( "/[\/_|+ -]+/" , $ delimiter , $ str ) ; $ str = trim ( $ str , $ delimiter ) ; } if ( $ lowercase === true ) { $ str = Text :: lowercase ( $ str ) ; } return $ str ; }
|
Create safe string . Use to create safe usernames or filenames .
|
11,973
|
protected function adjustCaseInsensitive ( & $ value , & $ parameters ) { $ parameterAmount = count ( $ parameters ) ; if ( $ parameterAmount == 1 || $ parameterAmount > 1 && $ parameters [ 1 ] ) { $ parameters [ 0 ] = strtolower ( $ parameters [ 0 ] ) ; $ value = strtolower ( $ value ) ; } }
|
Adjusts value and parameters to be case insensitive if the second parameter says so or is not given .
|
11,974
|
public function get ( ConnectionContract $ connection , MailFactoryContract $ factory ) { $ uids = $ connection -> search ( $ this -> parseSearch ( ) ) ; $ stream = $ connection -> getStream ( ) ; $ max = $ this -> limit > 0 ? $ this -> limit : self :: $ max ; $ uids = array_slice ( $ uids , 0 , $ max ) ; return array_map ( function ( $ uid ) use ( $ factory , $ stream ) { return $ factory -> create ( $ uid , $ stream ) ; } , $ uids ) ; }
|
Execute search query on connection and put results into Mail wrappers using factory
|
11,975
|
public function where ( $ flag , $ value = null ) { if ( ! in_array ( strtolower ( $ flag ) , static :: $ searchCriteria ) ) { throw new InvalidArgumentException ( "Invalid where criteria '{$flag}'" ) ; } $ this -> where [ $ flag ] = $ value ; return $ this ; }
|
Set where condition .
|
11,976
|
public function order ( $ orderFlag , $ dir = 'desc' ) { if ( ! in_array ( $ orderFlag , static :: $ orderCriteria ) ) { throw new InvalidArgumentException ( "Invalid order criteria '{$orderFlag}'" ) ; } $ this -> order = $ orderFlag ; $ this -> orderDir = strtolower ( $ dir ) === 'asc' ? 0 : 1 ; return $ this ; }
|
Set sorting order .
|
11,977
|
protected function parseSearch ( ) { return implode ( ' ' , array_map ( function ( $ key , $ val ) { if ( is_null ( $ val ) ) { return strtoupper ( $ key ) ; } return sprintf ( '%s %s' , strtoupper ( $ key ) , $ val ) ; } , array_keys ( $ this -> where ) , array_values ( $ this -> where ) ) ) ; }
|
Parse the where conditions for imap_search
|
11,978
|
protected function toScalar ( $ value ) { if ( is_scalar ( $ value ) ) { return $ value ; } elseif ( null === $ value ) { return 'NULL' ; } else { if ( is_object ( $ value ) ) { if ( is_callable ( [ $ value , '__toString' ] ) ) { return ( string ) $ value ; } elseif ( $ value instanceof \ DateTimeInterface ) { return $ value -> format ( 'Y-m-d H:i:s' ) ; } else { throw new \ InvalidArgumentException ( sprintf ( "Cast of class %s is impossible" , get_class ( $ value ) ) ) ; } } else { throw new \ InvalidArgumentException ( sprintf ( "Cast of type %s is impossible" , gettype ( $ value ) ) ) ; } } }
|
Attempt to convert non - scalar values .
|
11,979
|
public function prePersist ( EventArgs $ args ) { $ em = $ args -> getEntityManager ( ) ; $ object = $ args -> getObject ( ) ; $ class = get_class ( $ object ) ; $ meta = $ em -> getClassMetadata ( $ class ) ; $ reflectionClass = $ meta -> getReflectionClass ( ) ; if ( ! $ reflectionClass || ! $ this -> hasTrait ( $ reflectionClass , 'Blast\BaseEntitiesBundle\Entity\Traits\Sortable' ) ) { return ; } if ( $ object -> getSortRank ( ) ) { return ; } $ maxPos = $ this -> getMaxPosition ( $ em , $ meta ) ; $ maxPos = $ maxPos ? $ maxPos + 1000 : 65536 ; $ object -> setSortRank ( $ maxPos ) ; $ this -> maxPositions [ $ class ] = $ maxPos ; }
|
Compute sortRank for entities that are created .
|
11,980
|
public function getGenericResources ( $ limit = 10 , $ mode = AbstractQuery :: HYDRATE_OBJECT ) { $ builder = $ this -> getEntityManager ( ) -> createQueryBuilder ( ) ; $ builder -> select ( 'e' ) -> from ( $ this -> getEntity ( ) , 'e' ) -> where ( 'e.isGeneric = 1' ) -> setMaxResults ( $ limit ) ; $ query = LocaleAwareTrait :: addHints ( $ builder -> getQuery ( ) ) ; return $ query -> execute ( $ mode ) ; }
|
List Generic Resources
|
11,981
|
private function handleException ( \ Throwable $ t , Request $ request ) { if ( $ this -> log !== null ) { $ this -> log -> error ( 'Exception thrown inside a controller.' , array ( 'exception' => $ t , ) ) ; } else { error_log ( $ t -> getMessage ( ) . ' - ' . $ t -> getTraceAsString ( ) ) ; } $ response = SplashUtils :: buildControllerResponse ( function ( ) use ( $ t , $ request ) { return $ this -> errorController -> serverError ( $ t , $ request ) ; } ) ; return $ response ; }
|
Actually handle the exception .
|
11,982
|
public function cerrarMesa ( $ mesa_id , $ imprimir_ticket = true ) { $ this -> Mesa -> id = $ mesa_id ; if ( ! $ this -> Mesa -> cerrar_mesa ( ) ) { if ( ! $ this -> request -> is ( 'ajax' ) ) { $ this -> setFlash ( 'Error al cerrar la mesa' , 'flash_error' ) ; } } if ( ! $ this -> request -> is ( 'ajax' ) ) { $ this -> redirect ( $ this -> referer ( ) ) ; } }
|
Cierra la mesa calculando el total y si se lo indica imprime el ticket fiscal .
|
11,983
|
public function render ( $ mode , $ node ) { return ( $ mode > 0 || $ node -> hasProperty ( 'renderBox' ) == false || $ node -> getProperty ( 'renderBox' ) === null || $ node -> getProperty ( 'renderBox' ) === true ) ? true : false ; }
|
Decide if box should be rendered or not based on renderMode and node properties
|
11,984
|
public function transform ( $ role ) { $ role = $ this -> entityToArray ( Role :: class , $ role ) ; return [ 'id' => ( int ) $ role [ 'id' ] , 'name' => $ role [ 'name' ] , 'createdAt' => $ role [ 'created_at' ] , 'updatedAt' => $ role [ 'updated_at' ] ] ; }
|
Transforms role entity
|
11,985
|
public function offsetSet ( $ offset , $ value ) { if ( is_null ( $ offset ) ) { $ this -> _args [ count ( $ this -> _args ) ] = $ value ; } else { if ( is_int ( $ offset ) ) { $ this -> _args [ $ offset ] = $ value ; } else { throw new \ Exception ( 'Cannot set offset \'' . $ offset . '\' of IndexedArray.' ) ; } } }
|
Override the offsetSet function to enforce integral keys only .
|
11,986
|
public function offsetGet ( $ offset ) { if ( isset ( $ this -> _args [ $ offset ] ) ) { if ( is_array ( $ this -> _args [ $ offset ] ) ) { return new AssociativeArray ( $ this -> _args [ $ offset ] ) ; } else { return $ this -> _args [ $ offset ] ; } } else { throw new \ Exception ( 'Undefined offset \'' . $ offset . '\'.' ) ; } }
|
Override the offsetGet function to throw an undefined offset error when a key is not found .
|
11,987
|
private function isPrefixedKey ( $ key ) { if ( strlen ( $ key ) > 1 ) { if ( substr ( $ key , 0 , 1 ) == '_' ) { try { intval ( substr ( $ key , 1 , strlen ( $ key ) - 1 ) ) ; return true ; } catch ( \ Exception $ e ) { return false ; } } } }
|
Check if a string is in the proper format to be a prefixed integral array key .
|
11,988
|
public function getPlatformRequirements ( $ withDevReqs = false ) { $ lockData = $ this -> getLockData ( ) ; $ versionParser = new VersionParser ( ) ; $ requirements = array ( ) ; if ( ! empty ( $ lockData [ 'platform' ] ) ) { $ requirements = $ versionParser -> parseLinks ( '__ROOT__' , '1.0.0' , 'requires' , isset ( $ lockData [ 'platform' ] ) ? $ lockData [ 'platform' ] : array ( ) ) ; } if ( $ withDevReqs && ! empty ( $ lockData [ 'platform-dev' ] ) ) { $ devRequirements = $ versionParser -> parseLinks ( '__ROOT__' , '1.0.0' , 'requires' , isset ( $ lockData [ 'platform-dev' ] ) ? $ lockData [ 'platform-dev' ] : array ( ) ) ; $ requirements = array_merge ( $ requirements , $ devRequirements ) ; } return $ requirements ; }
|
Returns the platform requirements stored in the lock file
|
11,989
|
public function setLockData ( array $ packages , $ devPackages , array $ platformReqs , $ platformDevReqs , array $ aliases , $ minimumStability , array $ stabilityFlags , $ preferStable , $ preferLowest , array $ platformOverrides ) { $ lock = array ( '_readme' => array ( 'This file locks the dependencies of your project to a known state' , 'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file' , 'This file is @gener' . 'ated automatically' ) , 'hash' => $ this -> hash , 'packages' => null , 'packages-dev' => null , 'aliases' => array ( ) , 'minimum-stability' => $ minimumStability , 'stability-flags' => $ stabilityFlags , 'prefer-stable' => $ preferStable , 'prefer-lowest' => $ preferLowest , ) ; foreach ( $ aliases as $ package => $ versions ) { foreach ( $ versions as $ version => $ alias ) { $ lock [ 'aliases' ] [ ] = array ( 'alias' => $ alias [ 'alias' ] , 'alias_normalized' => $ alias [ 'alias_normalized' ] , 'version' => $ version , 'package' => $ package , ) ; } } $ lock [ 'packages' ] = $ this -> lockPackages ( $ packages ) ; if ( null !== $ devPackages ) { $ lock [ 'packages-dev' ] = $ this -> lockPackages ( $ devPackages ) ; } $ lock [ 'platform' ] = $ platformReqs ; $ lock [ 'platform-dev' ] = $ platformDevReqs ; if ( $ platformOverrides ) { $ lock [ 'platform-overrides' ] = $ platformOverrides ; } if ( empty ( $ lock [ 'packages' ] ) && empty ( $ lock [ 'packages-dev' ] ) && empty ( $ lock [ 'platform' ] ) && empty ( $ lock [ 'platform-dev' ] ) ) { if ( $ this -> lockFile -> exists ( ) ) { unlink ( $ this -> lockFile -> getPath ( ) ) ; } return false ; } if ( ! $ this -> isLocked ( ) || $ lock !== $ this -> getLockData ( ) ) { $ this -> lockFile -> write ( $ lock ) ; $ this -> lockDataCache = null ; return true ; } return false ; }
|
Locks provided data into lockfile .
|
11,990
|
protected function _initResource ( $ config ) { if ( ! empty ( $ config [ 'data' ] ) && ! empty ( $ config [ 'filename' ] ) ) { throw new InvalidArgumentException ( "The `'data'` or `'filename'` option must be defined." ) ; } if ( $ config [ 'filename' ] ) { $ this -> _filename = $ config [ 'filename' ] ; if ( $ this -> _filename === 'php://input' ) { $ this -> _mode = 'r' ; } $ this -> _resource = fopen ( $ this -> _filename , $ this -> _mode ) ; return ; } if ( is_resource ( $ config [ 'data' ] ) ) { $ this -> _resource = $ config [ 'data' ] ; return ; } elseif ( is_scalar ( $ config [ 'data' ] ) ) { $ this -> _resource = fopen ( 'php://temp' , 'r+' ) ; fwrite ( $ this -> _resource , ( string ) $ config [ 'data' ] ) ; rewind ( $ this -> _resource ) ; } }
|
Init the stream resource .
|
11,991
|
public function length ( ) { if ( $ this -> _limit !== null ) { return $ this -> _limit ; } if ( $ this -> _length !== null ) { return $ this -> _length ; } if ( $ this -> isSeekable ( ) ) { $ old = $ this -> tell ( ) ; $ begin = $ this -> rewind ( ) ; $ end = $ this -> end ( ) ; $ this -> seek ( $ old ) ; return $ end - $ begin ; } }
|
Get the stream range length .
|
11,992
|
public function meta ( $ key = null ) { if ( $ this -> _resource === null && $ this -> _filename ) { $ this -> _resource = fopen ( $ this -> _filename , $ this -> _mode ) ; } if ( ! $ this -> valid ( ) ) { throw new RuntimeException ( 'Invalid resource.' ) ; } $ meta = stream_get_meta_data ( $ this -> _resource ) ; if ( $ key ) { return isset ( $ meta [ $ key ] ) ? $ meta [ $ key ] : null ; } return $ meta ; }
|
Get stream meta data .
|
11,993
|
protected function _ensureReadable ( $ bytePerByte = true ) { if ( ! $ this -> valid ( ) ) { throw new RuntimeException ( 'Cannot read from a closed stream.' ) ; } if ( ! $ this -> isReadable ( ) ) { $ mode = $ this -> meta ( 'mode' ) ; throw new RuntimeException ( "Cannot read on a non-readable stream (mode is `'{$mode}'`)." ) ; } }
|
Throw an exception if a stream is not readable .
|
11,994
|
protected function _ensureWritable ( ) { if ( ! $ this -> valid ( ) ) { throw new RuntimeException ( 'Cannot write on a closed stream.' ) ; } if ( ! $ this -> isWritable ( ) ) { $ mode = $ this -> meta ( 'mode' ) ; throw new RuntimeException ( "Cannot write on a non-writable stream (mode is `'{$mode}'`)." ) ; } }
|
Throw an exception if a stream is not writable .
|
11,995
|
protected function _bufferSize ( $ length ) { if ( $ this -> _limit !== null ) { $ position = $ this -> tell ( ) ; $ max = $ this -> _start + $ this -> _limit ; $ length = $ max - $ position ; } if ( $ length === null ) { $ length = $ this -> _bufferSize ; } return $ length ; }
|
Determine the buffer size to read .
|
11,996
|
public function pipe ( $ stream ) { $ offset = $ stream -> tell ( ) ; $ result = stream_copy_to_stream ( $ this -> resource ( ) , $ stream -> resource ( ) ) ; if ( $ stream -> isSeekable ( ) ) { $ stream -> seek ( $ offset ) ; } return $ result ; }
|
Read the content of this stream and write it to another stream .
|
11,997
|
public function seek ( $ offset , $ whence = SEEK_SET ) { if ( $ this -> _filename === 'php://input' && $ this -> eof ( ) && ! $ offset && $ whence === SEEK_SET ) { $ this -> close ( ) ; $ this -> _resource = fopen ( $ this -> _filename , 'r' ) ; } $ this -> _ensureSeekable ( ) ; fseek ( $ this -> _resource , $ offset , $ whence ) ; return ftell ( $ this -> _resource ) ; }
|
Seek on the stream .
|
11,998
|
public function valid ( ) { if ( $ this -> _resource === null && $ this -> _filename ) { $ this -> _resource = fopen ( $ this -> _filename , $ this -> _mode ) ; } return ! ! $ this -> _resource && is_resource ( $ this -> _resource ) ; }
|
Check if the stream is valid .
|
11,999
|
public static function getMime ( $ stream , $ mime ) { if ( is_string ( $ mime ) ) { return $ mime ; } if ( ! $ mime || ! $ stream -> isSeekable ( ) || ! $ stream -> isReadable ( ) ) { return ; } $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ old = $ stream -> tell ( ) ; $ stream -> rewind ( ) ; $ end = $ stream -> end ( ) ; $ size = min ( $ end - 0 , 4 ) ; if ( $ size === 0 ) { return ; } $ stream -> seek ( $ size , SEEK_SET ) ; $ signature = $ stream -> read ( $ size , false ) ; $ size = min ( $ end - 0 , 1024 ) ; $ stream -> rewind ( ) ; $ signature = $ stream -> read ( $ size , false ) . $ signature ; $ stream -> seek ( $ old , SEEK_SET ) ; return finfo_buffer ( $ finfo , $ signature ) ; }
|
Mime detector . Concat the first 1024 bytes + the last 4 bytes of readable & seekable streams to detext the mime info .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.