idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
600
|
protected function setPdoForType ( Connection $ connection , $ type = null ) { if ( $ type == 'read' ) { $ connection -> setPdo ( $ connection -> getReadPdo ( ) ) ; } else if ( $ type == 'write' ) { $ connection -> setReadPdo ( $ connection -> getPdo ( ) ) ; } return $ connection ; }
|
Prepare the read write mode for database connection instance .
|
601
|
protected function rollback ( $ slug ) { if ( ! $ this -> packages -> exists ( $ slug ) ) { return $ this -> error ( 'Package does not exist.' ) ; } $ this -> requireMigrations ( $ slug ) ; $ this -> migrator -> setConnection ( $ this -> input -> getOption ( 'database' ) ) ; $ pretend = $ this -> input -> getOption ( 'pretend' ) ; $ this -> migrator -> rollback ( $ pretend , $ slug ) ; foreach ( $ this -> migrator -> getNotes ( ) as $ note ) { if ( ! $ this -> option ( 'quiet' ) ) { $ this -> line ( $ note ) ; } } }
|
Run the migration rollback for the specified Package .
|
602
|
public function url ( ) { if ( empty ( $ parameters = func_get_args ( ) ) ) { return $ this -> to ( '/' ) ; } $ path = array_shift ( $ parameters ) ; $ result = preg_replace_callback ( '#\{(\d+)\}#' , function ( $ matches ) use ( $ parameters ) { list ( $ value , $ key ) = $ matches ; return isset ( $ parameters [ $ key ] ) ? $ parameters [ $ key ] : $ value ; } , $ path ) ; return $ this -> to ( $ path ) ; }
|
Create a new redirect response from the given path and arguments .
|
603
|
protected function resolveByOption ( $ option ) { $ model = str_replace ( '/' , '\\' , $ option ) ; $ namespaceModel = $ this -> container -> getNamespace ( ) . 'Models\\' . $ model ; if ( Str :: startsWith ( $ model , '\\' ) ) { $ this -> data [ 'fullModel' ] = trim ( $ model , '\\' ) ; } else { $ this -> data [ 'fullModel' ] = $ namespaceModel ; } $ this -> data [ 'model' ] = $ model = class_basename ( trim ( $ model , '\\' ) ) ; $ this -> data [ 'camelModel' ] = Str :: camel ( $ model ) ; $ this -> data [ 'pluralModel' ] = Str :: plural ( Str :: camel ( $ model ) ) ; $ config = $ this -> container [ 'config' ] ; $ this -> data [ 'fullUserModel' ] = $ model = $ config -> get ( 'auth.providers.users.model' , 'App\Models\User' ) ; $ this -> data [ 'userModel' ] = class_basename ( trim ( $ model , '\\' ) ) ; }
|
Resolve Container after getting input option .
|
604
|
public function showAction ( $ slug ) { $ category = $ this -> getCategoryRepository ( ) -> retrieveActiveBySlug ( $ slug ) ; if ( ! $ category ) { throw $ this -> createNotFoundException ( 'category doesnt exists' ) ; } return $ this -> render ( 'GenjFaqBundle:Category:show.html.twig' , array ( 'category' => $ category ) ) ; }
|
shows questions within 1 category
|
605
|
public function confirmToProceed ( $ warning = 'Application In Production!' , Closure $ callback = null ) { $ shouldConfirm = $ callback ? : $ this -> getDefaultConfirmCallback ( ) ; if ( call_user_func ( $ shouldConfirm ) ) { if ( $ this -> option ( 'force' ) ) return true ; $ this -> comment ( str_repeat ( '*' , strlen ( $ warning ) + 12 ) ) ; $ this -> comment ( '* ' . $ warning . ' *' ) ; $ this -> comment ( str_repeat ( '*' , strlen ( $ warning ) + 12 ) ) ; $ this -> output -> writeln ( '' ) ; $ confirmed = $ this -> confirm ( 'Do you really wish to run this command?' ) ; if ( ! $ confirmed ) { $ this -> comment ( 'Command Cancelled!' ) ; return false ; } } return true ; }
|
Confirm before proceeding with the action
|
606
|
public function ping ( ) { $ apiCall = '/helper/ping' ; $ payload = "" ; $ data = $ this -> requestMonkey ( $ apiCall , $ payload ) ; $ data = json_decode ( $ data , true ) ; if ( isset ( $ data [ 'error' ] ) ) throw new MailchimpAPIException ( $ data ) ; else return $ data [ 'msg' ] ; }
|
Ping the MailChimp API
|
607
|
public function command ( $ command , array $ parameters = array ( ) ) { $ binary = ProcessUtils :: escapeArgument ( ( new PhpExecutableFinder ) -> find ( false ) ) ; if ( defined ( 'HHVM_VERSION' ) ) { $ binary .= ' --php' ; } if ( defined ( 'FORGE_BINARY' ) ) { $ forge = ProcessUtils :: escapeArgument ( FORGE_BINARY ) ; } else { $ forge = 'forge' ; } return $ this -> exec ( "{$binary} {$forge} {$command}" , $ parameters ) ; }
|
Add a new Forge command event to the schedule .
|
608
|
public function authenticate ( $ method , $ arguments ) { $ handlers = $ this -> filterHandlers ( $ method , $ arguments ) ; if ( count ( $ handlers ) > 0 ) { foreach ( $ handlers as $ handler ) { $ isAuthenticated = $ handler -> authenticate ( $ method , $ arguments ) ; if ( $ isAuthenticated ) { return ; } } throw new InvalidAuth ( ) ; } else { throw new MissingAuth ( ) ; } }
|
Attempt to authorize a request . This will iterate over all authentication handlers that can handle this type of request . It will stop after it has found one that can authenticate the request .
|
609
|
private function filterHandlers ( $ method , $ arguments ) { $ handlers = array ( ) ; foreach ( $ this -> handlers as $ handler ) { if ( $ handler -> canHandle ( $ method , $ arguments ) ) { $ handlers [ ] = $ handler ; } } return $ handlers ; }
|
Filters the handlers array down to only the handlers that can handle the given request .
|
610
|
public function buildResult ( $ result ) { $ updates = [ ] ; foreach ( $ result as $ updateData ) { $ update = new Update ( $ updateData ) ; $ updates [ ] = $ update ; $ this -> lastUpdateId = max ( $ this -> lastUpdateId , $ update -> updateId ) ; } return $ updates ; }
|
Build result type from array of data .
|
611
|
public function process ( ServerRequestInterface $ request , RequestHandlerInterface $ handler ) : ResponseInterface { $ httpHandler = $ request -> getAttribute ( AttributeEnum :: ROUTER_ATTRIBUTE ) ; $ info = $ httpHandler [ 2 ] ; $ actionMiddlewares = [ ] ; if ( isset ( $ info [ 'handler' ] ) && \ is_string ( $ info [ 'handler' ] ) ) { $ exploded = explode ( '@' , $ info [ 'handler' ] ) ; $ controllerClass = $ exploded [ 0 ] ?? '' ; $ action = $ exploded [ 1 ] ?? '' ; $ collector = MiddlewareCollector :: getCollector ( ) ; $ collectedMiddlewares = $ collector [ $ controllerClass ] [ 'middlewares' ] ?? [ ] ; if ( $ controllerClass ) { $ collect = $ collectedMiddlewares [ 'group' ] ?? [ ] ; $ collect && $ actionMiddlewares = array_merge ( $ actionMiddlewares , $ collect ) ; } if ( $ action ) { $ collect = $ collectedMiddlewares [ 'actions' ] [ $ action ] ?? [ ] ; $ collect && $ actionMiddlewares = array_merge ( $ actionMiddlewares , $ collect ?? [ ] ) ; } } if ( ! empty ( $ actionMiddlewares ) && $ handler instanceof RequestHandler ) { $ handler -> insertMiddlewares ( $ actionMiddlewares ) ; } return $ handler -> handle ( $ request ) ; }
|
do middlewares of action
|
612
|
public function doesNotThrow ( ) { try { $ this -> data [ 0 ] ( ) ; } catch ( Exception $ exception ) { if ( $ this -> isKindOfClass ( $ exception , $ this -> data [ 1 ] ) ) { $ exceptionClass = get_class ( $ exception ) ; throw new DidNotMatchException ( "Expected {$this->data[1]} not to be thrown, " . "but $exceptionClass was thrown." ) ; } } }
|
Assert that a specific exception is not thrown .
|
613
|
public function throwsAnythingExcept ( ) { try { $ this -> data [ 0 ] ( ) ; } catch ( Exception $ exception ) { $ exceptionClass = get_class ( $ exception ) ; if ( $ exceptionClass === $ this -> data [ 1 ] ) { throw new DidNotMatchException ( "Expected any exception except {$this->data[1]} to be " . "thrown, but $exceptionClass was thrown." ) ; } } }
|
Assert any exception except a specific one was thrown .
|
614
|
protected function seed ( $ slug ) { $ package = $ this -> packages -> where ( 'slug' , $ slug ) ; $ className = $ package [ 'namespace' ] . '\Database\Seeds\DatabaseSeeder' ; if ( ! class_exists ( $ className ) ) { return ; } $ params = array ( ) ; if ( $ this -> option ( 'class' ) ) { $ params [ '--class' ] = $ this -> option ( 'class' ) ; } else { $ params [ '--class' ] = $ className ; } if ( $ option = $ this -> option ( 'database' ) ) { $ params [ '--database' ] = $ option ; } if ( $ option = $ this -> option ( 'force' ) ) { $ params [ '--force' ] = $ option ; } $ this -> call ( 'db:seed' , $ params ) ; }
|
Seed the specific Package .
|
615
|
public function register ( $ assets , $ type , $ position , $ order = 0 , $ mode = 'default' ) { if ( ! in_array ( $ type , $ this -> types ) ) { throw new InvalidArgumentException ( "Invalid assets type [${type}]" ) ; } else if ( ! in_array ( $ mode , array ( 'default' , 'inline' , 'view' ) ) ) { throw new InvalidArgumentException ( "Invalid assets mode [${mode}]" ) ; } else if ( ! empty ( $ items = $ this -> parseAssets ( $ assets , $ order , $ mode ) ) ) { Arr :: set ( $ this -> positions , $ key = "${type}.${position}" , array_merge ( Arr :: get ( $ this -> positions , $ key , array ( ) ) , $ items ) ) ; } }
|
Register new Assets .
|
616
|
public function render ( $ type , $ assets ) { if ( ! in_array ( $ type , $ this -> types ) ) { throw new InvalidArgumentException ( "Invalid assets type [${type}]" ) ; } else if ( ! empty ( $ items = $ this -> parseAssets ( $ assets ) ) ) { return implode ( "\n" , $ this -> renderItems ( $ items , $ type , false ) ) ; } }
|
Render the CSS or JS scripts .
|
617
|
protected function renderItems ( array $ items , $ type , $ sorted = true ) { if ( $ sorted ) { static :: sortItems ( $ items ) ; } return array_map ( function ( $ item ) use ( $ type ) { $ asset = Arr :: get ( $ item , 'asset' ) ; $ mode = Arr :: get ( $ item , 'mode' , 'default' ) ; if ( $ mode === 'inline' ) { $ asset = sprintf ( "\n%s\n" , trim ( $ asset ) ) ; } else if ( $ mode === 'view' ) { $ mode = 'inline' ; $ asset = $ this -> views -> fetch ( $ asset ) ; } $ template = Arr :: get ( static :: $ templates , "${mode}.${type}" ) ; return sprintf ( $ template , $ asset ) ; } , $ items ) ; }
|
Render the given position items to an array of assets .
|
618
|
protected static function sortItems ( array & $ items ) { usort ( $ items , function ( $ a , $ b ) { if ( $ a [ 'order' ] === $ b [ 'order' ] ) { return 0 ; } return ( $ a [ 'order' ] < $ b [ 'order' ] ) ? - 1 : 1 ; } ) ; }
|
Sort the given items by their order .
|
619
|
protected function parseAssets ( $ assets , $ order = 0 , $ mode = 'default' ) { if ( is_string ( $ assets ) && ! empty ( $ assets ) ) { $ assets = array ( $ assets ) ; } else if ( ! is_array ( $ assets ) ) { return array ( ) ; } return array_map ( function ( $ asset ) use ( $ order , $ mode ) { return compact ( 'asset' , 'order' , 'mode' ) ; } , array_filter ( $ assets , function ( $ value ) { return ! empty ( $ value ) ; } ) ) ; }
|
Parses and returns the given assets .
|
620
|
public function getControllerMethod ( ) { if ( ! isset ( $ this -> method ) ) { list ( , $ method ) = $ this -> parseControllerCallback ( ) ; return $ this -> method = $ method ; } return $ this -> method ; }
|
Get the controller method used for the route .
|
621
|
public function bindParameters ( Request $ request ) { $ params = $ this -> matchToKeys ( array_slice ( $ this -> bindPathParameters ( $ request ) , 1 ) ) ; if ( ! is_null ( $ this -> compiled -> getHostRegex ( ) ) ) { $ params = $ this -> bindHostParameters ( $ request , $ params ) ; } return $ this -> parameters = $ this -> replaceDefaults ( $ params ) ; }
|
Extract the parameter list from the request .
|
622
|
protected function matchToKeys ( array $ matches ) { $ parameterNames = $ this -> parameterNames ( ) ; if ( count ( $ parameterNames ) == 0 ) { return array ( ) ; } $ parameters = array_intersect_key ( $ matches , array_flip ( $ parameterNames ) ) ; return array_filter ( $ parameters , function ( $ value ) { return is_string ( $ value ) && ( strlen ( $ value ) > 0 ) ; } ) ; }
|
Combine a set of parameter matches with the route s keys .
|
623
|
public function setApiVersion ( $ version ) { if ( ! in_array ( $ version , $ this -> availableVersions , true ) ) { throw new UnsupportedStripeVersionException ( sprintf ( 'The given Stripe version ("%s") is not supported by ZfrStripe. Value must be one of the following: "%s"' , $ version , implode ( ', ' , $ this -> availableVersions ) ) ) ; } $ this -> version = ( string ) $ version ; $ this -> setDefaultOption ( 'headers' , [ 'Stripe-Version' => $ this -> version ] ) ; if ( $ this -> version < '2015-08-19' ) { $ descriptor = __DIR__ . '/ServiceDescription/Stripe-v1.0.php' ; } else { $ descriptor = __DIR__ . '/ServiceDescription/Stripe-v1.1.php' ; } $ this -> setCommandFactory ( new CompositeFactory ( ) ) ; $ this -> setDescription ( ServiceDescription :: factory ( $ descriptor ) ) ; }
|
Set the Stripe API version
|
624
|
public function afterPrepare ( Event $ event ) { $ command = $ event [ 'command' ] ; $ request = $ command -> getRequest ( ) ; $ request -> getQuery ( ) -> setAggregator ( new StripeQueryAggregator ( ) ) ; }
|
Modify the query aggregator
|
625
|
public function authorizeRequest ( Event $ event ) { $ command = $ event [ 'command' ] ; $ request = $ command -> getRequest ( ) ; $ request -> setAuth ( $ this -> apiKey ) ; }
|
Authorize the request
|
626
|
protected function resolve ( $ name ) { $ config = $ this -> getConfig ( $ name ) ; return $ this -> getConnector ( $ config [ 'driver' ] ) -> connect ( $ config ) ; }
|
Resolve a queue connection .
|
627
|
protected function getConnector ( $ driver ) { if ( isset ( $ this -> connectors [ $ driver ] ) ) { return call_user_func ( $ this -> connectors [ $ driver ] ) ; } throw new \ InvalidArgumentException ( "No connector for [$driver]" ) ; }
|
Get the connector for a given driver .
|
628
|
protected function setMailerDependencies ( $ mailer , $ app ) { $ mailer -> setContainer ( $ app ) ; if ( $ app -> bound ( 'log' ) ) { $ mailer -> setLogger ( $ app [ 'log' ] ) ; } if ( $ app -> bound ( 'queue' ) ) { $ mailer -> setQueue ( $ app [ 'queue' ] ) ; } }
|
Set a few dependencies on the mailer instance .
|
629
|
public function showAction ( $ slug ) { $ securityContext = $ this -> container -> get ( 'security.authorization_checker' ) ; $ question = $ this -> getQuestionRepository ( ) -> findOneBySlug ( $ slug ) ; if ( ! $ question || ( ! $ question -> isPublic ( ) && ! $ securityContext -> isGranted ( 'ROLE_EDITOR' ) ) ) { throw $ this -> createNotFoundException ( 'question not found' ) ; } return $ this -> render ( 'GenjFaqBundle:Question:show.html.twig' , array ( 'question' => $ question ) ) ; }
|
shows question if active
|
630
|
public function listMostRecentAction ( $ max = 3 ) { $ questions = $ this -> getQuestionRepository ( ) -> retrieveMostRecent ( $ max ) ; return $ this -> render ( 'GenjFaqBundle:Question:list_most_recent.html.twig' , array ( 'questions' => $ questions , 'max' => $ max ) ) ; }
|
list most recent added questions based on publishAt
|
631
|
public function listByQueryAction ( $ query , $ max = 30 , $ whereFields = array ( 'headline' , 'body' ) ) { $ questions = $ this -> getQuestionRepository ( ) -> retrieveByQuery ( $ query , $ max , $ whereFields ) ; return $ this -> render ( 'GenjFaqBundle:Question:list_by_query.html.twig' , array ( 'questions' => $ questions , 'max' => $ max ) ) ; }
|
list questions which fitting the query
|
632
|
public function load ( Application $ app , array $ providers ) { $ manifest = $ this -> loadManifest ( ) ; if ( $ this -> shouldRecompile ( $ manifest , $ providers ) ) { $ manifest = $ this -> compileManifest ( $ app , $ providers ) ; } if ( $ app -> runningInConsole ( ) ) { $ manifest [ 'eager' ] = $ manifest [ 'providers' ] ; } foreach ( $ manifest [ 'when' ] as $ provider => $ events ) { $ this -> registerLoadEvents ( $ app , $ provider , $ events ) ; } foreach ( $ manifest [ 'eager' ] as $ provider ) { $ app -> register ( $ this -> createProvider ( $ app , $ provider ) ) ; } $ app -> setDeferredServices ( $ manifest [ 'deferred' ] ) ; }
|
Register the application service providers .
|
633
|
protected function getRecallerId ( ) { if ( $ this -> validRecaller ( $ recaller = $ this -> getRecaller ( ) ) ) { $ segments = explode ( '|' , $ recaller ) ; return head ( $ segments ) ; } }
|
Get the user ID from the recaller cookie .
|
634
|
protected function createRecaller ( $ value ) { $ cookies = $ this -> getCookieJar ( ) ; return $ cookies -> forever ( $ this -> getRecallerName ( ) , $ value ) ; }
|
Create a remember me cookie for a given ID .
|
635
|
protected function refreshRememberToken ( UserInterface $ user ) { $ user -> setRememberToken ( $ token = str_random ( 60 ) ) ; $ this -> provider -> updateRememberToken ( $ user , $ token ) ; }
|
Refresh the remember token for the user .
|
636
|
public function setUser ( UserInterface $ user ) { $ this -> user = $ user ; $ this -> loggedOut = false ; return $ this ; }
|
Set the current user of the application .
|
637
|
protected function getForge ( ) { if ( isset ( $ this -> forge ) ) { return $ this -> forge ; } $ this -> app -> loadDeferredProviders ( ) ; $ this -> forge = ConsoleApplication :: make ( $ this -> app ) ; return $ this -> forge -> boot ( ) ; }
|
Get the forge console instance .
|
638
|
public function where ( $ first , $ operator , $ second , $ boolean = 'and' ) { return $ this -> on ( $ first , $ operator , $ second , $ boolean , true ) ; }
|
Add an on where clause to the join .
|
639
|
protected function prepareResponse ( Request $ request , Exception $ e ) { if ( $ this -> isHttpException ( $ e ) ) { return $ this -> createResponse ( $ this -> renderHttpException ( $ e , $ request ) , $ e ) ; } else { return $ this -> createResponse ( $ this -> convertExceptionToResponse ( $ e , $ request ) , $ e ) ; } }
|
Prepare response containing exception render .
|
640
|
protected function createResponse ( $ response , Exception $ e ) { $ response = new HttpResponse ( $ response -> getContent ( ) , $ response -> getStatusCode ( ) , $ response -> headers -> all ( ) ) ; return $ response -> withException ( $ e ) ; }
|
Map exception into a Nova response .
|
641
|
protected function convertExceptionToResponse ( Exception $ e , Request $ request ) { $ debug = Config :: get ( 'app.debug' ) ; $ e = FlattenException :: create ( $ e ) ; $ handler = new SymfonyExceptionHandler ( $ debug ) ; return SymfonyResponse :: create ( $ handler -> getHtml ( $ e ) , $ e -> getStatusCode ( ) , $ e -> getHeaders ( ) ) ; }
|
Convert the given exception into a Response instance .
|
642
|
protected function callChannelCallback ( $ callback , $ parameters ) { if ( is_string ( $ callback ) ) { list ( $ className , $ method ) = Str :: parseCallback ( $ callback , 'join' ) ; $ callback = array ( $ instance = $ this -> container -> make ( $ className ) , $ method ) ; $ reflector = new ReflectionMethod ( $ instance , $ method ) ; } else { $ reflector = new ReflectionFunction ( $ callback ) ; } return call_user_func_array ( $ callback , $ this -> resolveCallDependencies ( $ parameters , $ reflector ) ) ; }
|
Call a channel callback with the dependencies .
|
643
|
protected function formatChannels ( array $ channels ) { return array_map ( function ( $ channel ) { if ( $ channel instanceof Channel ) { return $ channel -> getName ( ) ; } return $ channel ; } , $ channels ) ; }
|
Format the channel array into an array of strings .
|
644
|
public static function make ( array $ items , $ total , $ perPage = 15 , $ pageName = 'page' , $ page = null ) { if ( is_null ( $ page ) ) { $ page = static :: resolveCurrentPage ( $ pageName ) ; } $ path = static :: resolveCurrentPath ( $ pageName ) ; return new static ( $ items , $ total , $ perPage , $ page , compact ( 'path' , 'pageName' ) ) ; }
|
Create and return a new Paginator instance .
|
645
|
protected function getFullSlider ( $ onEachSide ) { $ currentPage = $ this -> currentPage ( ) ; $ slider = $ this -> getUrlRange ( $ currentPage - $ onEachSide , $ currentPage + $ onEachSide ) ; $ lastPage = $ this -> lastPage ( ) ; return array ( 'first' => $ this -> getUrlRange ( 1 , 2 ) , 'slider' => $ slider , 'last' => $ this -> getUrlRange ( $ lastPage - 1 , $ lastPage ) , ) ; }
|
Get the slider of URLs when a full slider can be made .
|
646
|
protected function pushForeverKeys ( $ namespace , $ key ) { $ fullKey = $ this -> getPrefix ( ) . sha1 ( $ namespace ) . ':' . $ key ; foreach ( explode ( '|' , $ namespace ) as $ segment ) { $ this -> store -> connection ( ) -> lpush ( $ this -> foreverKey ( $ segment ) , $ fullKey ) ; } }
|
Store a copy of the full key for each namespace segment .
|
647
|
protected function deleteForeverKeys ( ) { foreach ( explode ( '|' , $ this -> tags -> getNamespace ( ) ) as $ segment ) { $ this -> deleteForeverValues ( $ segment = $ this -> foreverKey ( $ segment ) ) ; $ this -> store -> connection ( ) -> del ( $ segment ) ; } }
|
Delete all of the items that were stored forever .
|
648
|
protected function deleteForeverValues ( $ foreverKey ) { $ forever = array_unique ( $ this -> store -> connection ( ) -> lrange ( $ foreverKey , 0 , - 1 ) ) ; if ( count ( $ forever ) > 0 ) { call_user_func_array ( array ( $ this -> store -> connection ( ) , 'del' ) , $ forever ) ; } }
|
Delete all of the keys that have been stored forever .
|
649
|
protected function getNamespaceName ( $ className = null ) { $ parts = explode ( '\\' , $ className ? : $ this -> className ) ; array_pop ( $ parts ) ; return implode ( '\\' , $ parts ) ; }
|
Get the namespace for the mocked class .
|
650
|
public function generateCode ( ) { $ refClass = new ReflectionClass ( $ this -> className ) ; $ this -> finalClassesCanNotBeMocked ( $ refClass ) ; $ this -> methods = array ( ) ; $ this -> makeAllAbstractMethodsThrowException ( $ refClass ) ; if ( ! $ this -> niceMock || $ refClass -> isInterface ( ) ) { $ this -> makeAllMethodsThrowException ( $ refClass ) ; } $ this -> renderRules ( ) ; $ this -> renderConstructor ( ) ; $ this -> renderClone ( ) ; $ this -> exposeMethods ( ) ; $ this -> setUpGetCallsForMethod ( ) ; $ code = $ this -> getNamespaceCode ( ) ; $ methods = implode ( "\n" , $ this -> methods ) ; $ superWord = $ this -> getSuperWord ( $ refClass ) ; $ class = "class {$this->getMockName()} $superWord \\{$this->className}" ; if ( 'implements' === $ superWord ) { $ class .= ', ' ; } else { $ class .= ' implements ' ; } $ class .= '\Concise\Mock\MockInterface' ; return $ code . "$class { public static \$_methodCalls = array(); $methods }" ; }
|
Generate the PHP code for the mocked class .
|
651
|
public function newInstance ( ) { $ name = "{$this->getMockNamespaceName()}\\{$this->getMockName()}" ; $ code = $ this -> generateCode ( ) ; $ reflect = eval ( "$code return new \\ReflectionClass('$name');" ) ; try { return $ reflect -> newInstanceArgs ( $ this -> constructorArgs ) ; } catch ( ReflectionException $ e ) { return $ reflect -> newInstance ( ) ; } }
|
Create a new instance of the mocked class . There is no need to generate the code before invoking this .
|
652
|
public function package ( $ package , $ hint , $ namespace = null ) { $ namespace = $ this -> getPackageNamespace ( $ package , $ namespace ) ; $ this -> addNamespace ( $ namespace , $ hint ) ; }
|
Register a Package for cascading configuration .
|
653
|
public static function insert ( $ object ) { $ db = new DatabaseManager ( ) ; $ connection = $ db -> getDbh ( ) ; $ objectAsArrayForSqlInsert = DatatbaseUtility :: objectToArrayLessId ( $ object ) ; $ fields = array_keys ( $ objectAsArrayForSqlInsert ) ; $ insertFieldList = DatatbaseUtility :: fieldListToInsertString ( $ fields ) ; $ valuesFieldList = DatatbaseUtility :: fieldListToValuesString ( $ fields ) ; $ statement = $ connection -> prepare ( 'INSERT into ' . static :: getTableName ( ) . ' ' . $ insertFieldList . $ valuesFieldList ) ; $ statement -> execute ( $ objectAsArrayForSqlInsert ) ; $ queryWasSuccessful = ( $ statement -> rowCount ( ) > 0 ) ; if ( $ queryWasSuccessful ) { return $ connection -> lastInsertId ( ) ; } else { return - 1 ; } }
|
insert new record into the DB table returns new record ID if insertation was successful otherwise - 1
|
654
|
public function getDestinationPath ( $ package ) { $ packages = $ this -> config -> getPackages ( ) ; $ namespace = isset ( $ packages [ $ package ] ) ? $ packages [ $ package ] : null ; if ( is_null ( $ namespace ) ) { throw new \ InvalidArgumentException ( "Configuration not found." ) ; } return $ this -> publishPath . str_replace ( '/' , DS , "/Packages/{$namespace}" ) ; }
|
Get the target destination path for the configuration files .
|
655
|
public function getSortedQuestions ( ) { $ criteria = Criteria :: create ( ) ; $ criteria -> orderBy ( array ( 'rank' => 'ASC' ) ) ; return $ this -> getQuestions ( ) -> matching ( $ criteria ) ; }
|
Get Sorted questions by Rank
|
656
|
public static function onlyTrashed ( ) { $ instance = new static ; $ column = $ instance -> getQualifiedDeletedAtColumn ( ) ; return $ instance -> newQueryWithoutScope ( new SoftDeletingScope ) -> whereNotNull ( $ column ) ; }
|
Get a new query builder that only includes soft deletes .
|
657
|
protected function call ( $ pipe , $ passable , $ stack ) { if ( $ pipe instanceof Closure ) { return call_user_func ( $ pipe , $ passable , $ stack ) ; } else if ( ! is_object ( $ pipe ) ) { list ( $ name , $ parameters ) = $ this -> parsePipeString ( $ pipe ) ; $ pipe = $ this -> getContainer ( ) -> make ( $ name ) ; $ parameters = array_merge ( array ( $ passable , $ stack ) , $ parameters ) ; } else { $ parameters = array ( $ passable , $ stack ) ; } return call_user_func_array ( array ( $ pipe , $ this -> method ) , $ parameters ) ; }
|
Call the pipe Closure or the method handle in its class instance .
|
658
|
public function containsString ( ) { if ( strpos ( $ this -> data [ 0 ] , $ this -> data [ 1 ] ) === false ) { throw new DidNotMatchException ( ) ; } return $ this -> data [ 0 ] ; }
|
A string contains a substring . Returns original string .
|
659
|
public function doesNotContainString ( ) { if ( strpos ( $ this -> data [ 0 ] , $ this -> data [ 1 ] ) !== false ) { throw new DidNotMatchException ( ) ; } return $ this -> data [ 0 ] ; }
|
A string does not contain a substring . Returns original string .
|
660
|
public function get ( ) { $ compiler = new ClassCompiler ( $ this -> className , $ this -> niceMock , $ this -> constructorArgs , $ this -> disableConstructor , $ this -> disableClone ) ; if ( $ this -> customClassName ) { $ compiler -> setCustomClassName ( $ this -> customClassName ) ; } $ compiler -> setRules ( $ this -> rules ) ; foreach ( $ this -> expose as $ method ) { $ compiler -> addExpose ( $ method ) ; } $ mockInstance = $ compiler -> newInstance ( ) ; $ this -> testCase -> addMockInstance ( $ this , $ mockInstance ) ; $ this -> restoreState ( $ mockInstance ) ; foreach ( $ this -> properties as $ name => $ value ) { $ this -> testCase -> setProperty ( $ mockInstance , $ name , $ value ) ; } return $ mockInstance ; }
|
Compiler the mock into a usable instance .
|
661
|
public function with ( ) { $ methodArguments = new MethodArguments ( ) ; $ this -> currentWith = $ methodArguments -> getMethodArgumentValues ( func_get_args ( ) , $ this -> getClassName ( ) . "::" . $ this -> currentRules [ 0 ] ) ; foreach ( $ this -> currentRules as $ rule ) { if ( $ this -> rules [ $ rule ] [ md5 ( 'null' ) ] [ 'hasSetTimes' ] ) { $ renderer = new ValueRenderer ( ) ; $ converter = new NumberToTimesConverter ( ) ; $ args = $ renderer -> renderAll ( $ this -> currentWith ) ; $ times = $ this -> rules [ $ rule ] [ md5 ( 'null' ) ] [ 'times' ] ; $ convertToMethod = $ converter -> convertToMethod ( $ times ) ; throw new Exception ( sprintf ( "%s:\n ->expects('%s')->with(%s)->%s" , "When using with you must specify expectations for each with()" , $ rule , $ args , $ convertToMethod ) ) ; } $ this -> rules [ $ rule ] [ md5 ( 'null' ) ] [ 'times' ] = - 1 ; } $ this -> setupWith ( new Action \ ReturnValueAction ( array ( null ) ) , $ this -> isExpecting ? 1 : - 1 ) ; return $ this ; }
|
Expected arguments when invoking the mock .
|
662
|
protected function parseErrors ( $ provider ) { if ( $ provider instanceof MessageBag ) { return $ provider ; } else if ( $ provider instanceof MessageProviderInterface ) { return $ provider -> getMessageBag ( ) ; } return new MessageBag ( ( array ) $ provider ) ; }
|
Parse the given errors into an appropriate value .
|
663
|
public static function createFromBase ( SymfonyRequest $ request ) { if ( $ request instanceof static ) return $ request ; $ content = $ request -> content ; $ request = ( new static ) -> duplicate ( $ request -> query -> all ( ) , $ request -> request -> all ( ) , $ request -> attributes -> all ( ) , $ request -> cookies -> all ( ) , $ request -> files -> all ( ) , $ request -> server -> all ( ) ) ; $ request -> content = $ content ; $ request -> request = $ request -> getInputSource ( ) ; return $ request ; }
|
Create an Nova request from a Symfony instance .
|
664
|
public function shouldUse ( $ name ) { $ this -> setDefaultDriver ( $ name ) ; $ this -> userResolver = function ( $ name = null ) { return $ this -> guard ( $ name ) -> user ( ) ; } ; }
|
Set the default guard driver the factory should serve .
|
665
|
public function DumpList ( $ options = array ( ) , $ listId = false ) { $ api = $ this -> url . 'list/' ; if ( ! $ listId ) $ listId = $ this -> listId ; $ payload = array_merge ( array ( 'id' => $ this -> listId ) , $ options ) ; $ data = $ this -> requestMonkey ( $ api , $ payload , true ) ; if ( empty ( $ data ) || ! isset ( $ data ) ) return $ data ; $ result = preg_split ( '/$\R?^/m' , $ data ) ; $ headerArray = json_decode ( $ result [ 0 ] ) ; unset ( $ result [ 0 ] ) ; $ data = array ( ) ; foreach ( $ result as $ value ) { $ data [ ] = array_combine ( $ headerArray , json_decode ( $ value ) ) ; } return $ data ; }
|
Dump members of a list
|
666
|
public function url ( $ page ) { $ paginator = $ this -> getPaginator ( ) ; $ pageName = $ paginator -> getPageName ( ) ; $ query = array_merge ( $ paginator -> getQuery ( ) , array ( $ pageName => $ page ) ) ; return $ this -> buildUrl ( $ paginator -> getPath ( ) , $ query , $ paginator -> fragment ( ) ) ; }
|
Resolve the URL for a given page number .
|
667
|
protected function buildUrl ( $ path , array $ query , $ fragment ) { if ( ! empty ( $ query ) ) { $ separator = Str :: contains ( $ path , '?' ) ? '&' : '?' ; $ path .= $ separator . http_build_query ( $ query , '' , '&' ) ; } if ( ! empty ( $ fragment ) ) { $ path .= '#' . $ fragment ; } return $ path ; }
|
Build the full query portion of a URL .
|
668
|
protected function createFileDriver ( ) { $ path = $ this -> app [ 'config' ] [ 'cache.path' ] ; return $ this -> repository ( new FileStore ( $ this -> app [ 'files' ] , $ path ) ) ; }
|
Create an instance of the file cache driver .
|
669
|
protected function loadSession ( ) { $ this -> attributes = $ this -> readFromHandler ( ) ; foreach ( array_merge ( $ this -> bags , array ( $ this -> metaBag ) ) as $ bag ) { $ this -> initializeLocalBag ( $ bag ) ; $ bag -> initialize ( $ this -> bagData [ $ bag -> getStorageKey ( ) ] ) ; } }
|
Load the session data from the handler .
|
670
|
protected function readFromHandler ( ) { $ data = $ this -> handler -> read ( $ this -> getId ( ) ) ; return $ data ? unserialize ( $ data ) : array ( ) ; }
|
Read the session data from the handler .
|
671
|
protected function compileUpdateJoinWheres ( Builder $ query ) { $ joinWheres = array ( ) ; foreach ( $ query -> joins as $ join ) { foreach ( $ join -> clauses as $ clause ) { $ joinWheres [ ] = $ this -> compileJoinConstraint ( $ clause ) ; } } return implode ( ' ' , $ joinWheres ) ; }
|
Compile the join clauses for an update .
|
672
|
public function apply ( Builder $ builder ) { $ model = $ builder -> getModel ( ) ; $ builder -> whereNull ( $ model -> getQualifiedDeletedAtColumn ( ) ) ; $ this -> extend ( $ builder ) ; }
|
Apply the scope to a given ORM query builder .
|
673
|
public function remove ( Builder $ builder ) { $ column = $ builder -> getModel ( ) -> getQualifiedDeletedAtColumn ( ) ; $ query = $ builder -> getQuery ( ) ; foreach ( ( array ) $ query -> wheres as $ key => $ where ) { if ( $ this -> isSoftDeleteConstraint ( $ where , $ column ) ) { unset ( $ query -> wheres [ $ key ] ) ; $ query -> wheres = array_values ( $ query -> wheres ) ; } } }
|
Remove the scope from the given ORM query builder .
|
674
|
protected function addForceDelete ( Builder $ builder ) { $ builder -> macro ( 'forceDelete' , function ( Builder $ builder ) { return $ builder -> getQuery ( ) -> delete ( ) ; } ) ; }
|
Add the force delete extension to the builder .
|
675
|
protected function addRestore ( Builder $ builder ) { $ builder -> macro ( 'restore' , function ( Builder $ builder ) { $ builder -> withTrashed ( ) ; return $ builder -> update ( array ( $ builder -> getModel ( ) -> getDeletedAtColumn ( ) => null ) ) ; } ) ; }
|
Add the restore extension to the builder .
|
676
|
public static function build ( Configuration $ configuration = null ) : DIContainer { if ( $ configuration === null ) { $ configuration = new Configuration ( ) ; } $ defaultDefinitions = \ array_merge ( require __DIR__ . '/definitions.php' , [ Configuration :: class => $ configuration ] ) ; $ customDefinitions = self :: parseDefinitions ( $ configuration -> getDefinitions ( ) ) ; return self :: getContainerBuilder ( $ configuration ) -> addDefinitions ( $ defaultDefinitions , ... $ customDefinitions ) -> build ( ) ; }
|
Build PHP - DI container .
|
677
|
private static function getContainerBuilder ( Configuration $ configuration ) : DIContainerBuilder { $ containerBuilder = new DIContainerBuilder ( $ configuration -> getContainerClass ( ) ) ; $ containerBuilder -> useAutowiring ( $ configuration -> doesUseAutowiring ( ) ) ; $ containerBuilder -> useAnnotations ( $ configuration -> doesUseAnnotations ( ) ) ; $ containerBuilder -> ignorePhpDocErrors ( $ configuration -> doesIgnorePhpDocErrors ( ) ) ; if ( $ configuration -> doesUseDefinitionCache ( ) ) { $ containerBuilder -> enableDefinitionCache ( ) ; } if ( $ configuration -> getWrapContainer ( ) !== null ) { $ containerBuilder -> wrapContainer ( $ configuration -> getWrapContainer ( ) ) ; } if ( $ configuration -> getProxiesPath ( ) !== null ) { $ containerBuilder -> writeProxiesToFile ( true , $ configuration -> getProxiesPath ( ) ) ; } if ( ! empty ( $ configuration -> getCompilationPath ( ) ) ) { $ containerBuilder -> enableCompilation ( $ configuration -> getCompilationPath ( ) , 'CompiledContainer' , $ configuration -> getCompiledContainerClass ( ) ) ; } return $ containerBuilder ; }
|
Get configured container builder .
|
678
|
private static function parseDefinitions ( array $ definitions ) : array { if ( \ count ( $ definitions ) === 0 ) { return $ definitions ; } return \ array_map ( function ( $ definition ) { if ( \ is_array ( $ definition ) ) { return $ definition ; } return self :: loadDefinitionsFromPath ( $ definition ) ; } , $ definitions ) ; }
|
Parse definitions .
|
679
|
private static function loadDefinitionsFromPath ( string $ path ) : array { if ( ! \ file_exists ( $ path ) ) { throw new \ RuntimeException ( \ sprintf ( 'Path "%s" does not exist' , $ path ) ) ; } if ( ! \ is_dir ( $ path ) ) { return self :: loadDefinitionsFromFile ( $ path ) ; } $ definitions = [ ] ; foreach ( \ glob ( $ path . '/*.php' , \ GLOB_ERR ) as $ file ) { if ( \ is_file ( $ file ) ) { $ definitions [ ] = self :: loadDefinitionsFromFile ( $ file ) ; } } return \ count ( $ definitions ) === 0 ? [ ] : \ array_merge ( ... $ definitions ) ; }
|
Load definitions from path .
|
680
|
private static function loadDefinitionsFromFile ( string $ file ) : array { if ( ! \ is_file ( $ file ) || ! \ is_readable ( $ file ) ) { throw new \ RuntimeException ( \ sprintf ( '"%s" must be a readable file' , $ file ) ) ; } $ definitions = require $ file ; if ( ! \ is_array ( $ definitions ) ) { throw new \ RuntimeException ( \ sprintf ( 'Definitions file should return an array. "%s" returned' , \ gettype ( $ definitions ) ) ) ; } return $ definitions ; }
|
Load definitions from file .
|
681
|
protected function createCookieDriver ( ) { $ lifetime = $ this -> app [ 'config' ] [ 'session.lifetime' ] ; return $ this -> buildSession ( new CookieSessionHandler ( $ this -> app [ 'cookie' ] , $ lifetime ) ) ; }
|
Create an instance of the cookie session driver .
|
682
|
public function load ( $ environment = null ) { foreach ( $ this -> loader -> load ( $ environment ) as $ key => $ value ) { $ _ENV [ $ key ] = $ value ; $ _SERVER [ $ key ] = $ value ; putenv ( "{$key}={$value}" ) ; } }
|
Load the server variables for a given environment .
|
683
|
public function guessPackagePath ( ) { $ reflection = new ReflectionClass ( $ this ) ; $ path = $ reflection -> getFileName ( ) ; return realpath ( dirname ( $ path ) . '/../' ) ; }
|
Guess the package path for the provider .
|
684
|
public function hasItems ( ) { if ( count ( $ this -> data [ 1 ] ) === 0 ) { return ; } foreach ( $ this -> data [ 1 ] as $ key => $ value ) { $ this -> failIf ( ! $ this -> itemExists ( array ( $ this -> data [ 0 ] , array ( $ key => $ value ) ) ) ) ; } }
|
Assert an array has all key and value items .
|
685
|
public function hasKey ( ) { $ this -> failIf ( ! array_key_exists ( $ this -> data [ 1 ] , $ this -> data [ 0 ] ) ) ; return $ this -> data [ 0 ] [ $ this -> data [ 1 ] ] ; }
|
Assert an array has key returns value .
|
686
|
public function hasValues ( ) { $ keys = array_values ( $ this -> data [ 0 ] ) ; foreach ( $ this -> data [ 1 ] as $ key ) { $ this -> failIf ( ( ! in_array ( $ key , $ keys ) ) ) ; } }
|
Assert an array has several values in any order .
|
687
|
protected function queueToNotifiable ( $ notifiable , $ id , $ notification , $ channel ) { $ notification -> id = $ id ; $ job = with ( new SendQueuedNotifications ( $ notifiable , $ notification , array ( $ channel ) ) ) -> onConnection ( $ notification -> connection ) -> onQueue ( $ notification -> queue ) -> delay ( $ notification -> delay ) ; $ this -> bus -> dispatch ( $ job ) ; }
|
Queue the given notification to the given notifiable via a channel .
|
688
|
protected function handleException ( $ e ) { if ( isset ( $ this -> exceptions ) ) { $ this -> exceptions -> report ( $ e ) ; } if ( $ this -> causedByLostConnection ( $ e ) ) { $ this -> shouldQuit = true ; } }
|
Handle an exception that occurred while handling a job .
|
689
|
public static function setSerializeHandler ( ) { $ formats = [ 'php_serialize' , 'php' , 'php_binary' , ] ; \ Wikimedia \ suppressWarnings ( ) ; ini_set ( 'session.serialize_handler' , 'php_serialize' ) ; \ Wikimedia \ restoreWarnings ( ) ; if ( ini_get ( 'session.serialize_handler' ) === 'php_serialize' ) { return 'php_serialize' ; } $ format = ini_get ( 'session.serialize_handler' ) ; if ( in_array ( $ format , $ formats , true ) ) { return $ format ; } foreach ( $ formats as $ format ) { \ Wikimedia \ suppressWarnings ( ) ; ini_set ( 'session.serialize_handler' , $ format ) ; \ Wikimedia \ restoreWarnings ( ) ; if ( ini_get ( 'session.serialize_handler' ) === $ format ) { return $ format ; } } throw new \ DomainException ( 'Failed to set serialize handler to a supported format.' . ' Supported formats are: ' . implode ( ', ' , $ formats ) . '.' ) ; }
|
Try to set session . serialize_handler to a supported format
|
690
|
public static function encode ( array $ data ) { $ format = ini_get ( 'session.serialize_handler' ) ; if ( ! is_string ( $ format ) ) { throw new \ UnexpectedValueException ( 'Could not fetch the value of session.serialize_handler' ) ; } switch ( $ format ) { case 'php' : return self :: encodePhp ( $ data ) ; case 'php_binary' : return self :: encodePhpBinary ( $ data ) ; case 'php_serialize' : return self :: encodePhpSerialize ( $ data ) ; default : throw new \ DomainException ( "Unsupported format \"$format\"" ) ; } }
|
Encode a session array to a string using the format in session . serialize_handler
|
691
|
public static function decode ( $ data ) { if ( ! is_string ( $ data ) ) { throw new \ InvalidArgumentException ( '$data must be a string' ) ; } $ format = ini_get ( 'session.serialize_handler' ) ; if ( ! is_string ( $ format ) ) { throw new \ UnexpectedValueException ( 'Could not fetch the value of session.serialize_handler' ) ; } switch ( $ format ) { case 'php' : return self :: decodePhp ( $ data ) ; case 'php_binary' : return self :: decodePhpBinary ( $ data ) ; case 'php_serialize' : return self :: decodePhpSerialize ( $ data ) ; default : throw new \ DomainException ( "Unsupported format \"$format\"" ) ; } }
|
Decode a session string to an array using the format in session . serialize_handler
|
692
|
private static function serializeValue ( $ value ) { try { return serialize ( $ value ) ; } catch ( \ Exception $ ex ) { self :: $ logger -> error ( 'Value serialization failed: ' . $ ex -> getMessage ( ) ) ; return null ; } }
|
Serialize a value with error logging
|
693
|
private static function unserializeValue ( & $ string ) { $ error = null ; set_error_handler ( function ( $ errno , $ errstr ) use ( & $ error ) { $ error = $ errstr ; return true ; } ) ; $ ret = unserialize ( $ string ) ; restore_error_handler ( ) ; if ( $ error !== null ) { self :: $ logger -> error ( 'Value unserialization failed: ' . $ error ) ; return [ false , null ] ; } $ serialized = serialize ( $ ret ) ; $ l = strlen ( $ serialized ) ; if ( substr ( $ string , 0 , $ l ) !== $ serialized ) { self :: $ logger -> error ( 'Value unserialization failed: read value does not match original string' ) ; return [ false , null ] ; } $ string = substr ( $ string , $ l ) ; return [ true , $ ret ] ; }
|
Unserialize a value with error logging
|
694
|
public static function encodePhp ( array $ data ) { $ ret = '' ; foreach ( $ data as $ key => $ value ) { if ( strcmp ( $ key , intval ( $ key ) ) === 0 ) { self :: $ logger -> warning ( "Ignoring unsupported integer key \"$key\"" ) ; continue ; } if ( strcspn ( $ key , '|!' ) !== strlen ( $ key ) ) { self :: $ logger -> error ( "Serialization failed: Key with unsupported characters \"$key\"" ) ; return null ; } $ v = self :: serializeValue ( $ value ) ; if ( $ v === null ) { return null ; } $ ret .= "$key|$v" ; } return $ ret ; }
|
Encode a session array to a string in php format
|
695
|
public static function decodePhp ( $ data ) { if ( ! is_string ( $ data ) ) { throw new \ InvalidArgumentException ( '$data must be a string' ) ; } $ ret = [ ] ; while ( $ data !== '' && $ data !== false ) { $ i = strpos ( $ data , '|' ) ; if ( $ i === false ) { if ( substr ( $ data , - 1 ) !== '!' ) { self :: $ logger -> warning ( 'Ignoring garbage at end of string' ) ; } break ; } $ key = substr ( $ data , 0 , $ i ) ; $ data = substr ( $ data , $ i + 1 ) ; if ( strpos ( $ key , '!' ) !== false ) { self :: $ logger -> warning ( "Decoding found a key with unsupported characters: \"$key\"" ) ; } if ( $ data === '' || $ data === false ) { self :: $ logger -> error ( 'Unserialize failed: unexpected end of string' ) ; return null ; } list ( $ ok , $ value ) = self :: unserializeValue ( $ data ) ; if ( ! $ ok ) { return null ; } $ ret [ $ key ] = $ value ; } return $ ret ; }
|
Decode a session string in php format to an array
|
696
|
public static function encodePhpBinary ( array $ data ) { $ ret = '' ; foreach ( $ data as $ key => $ value ) { if ( strcmp ( $ key , intval ( $ key ) ) === 0 ) { self :: $ logger -> warning ( "Ignoring unsupported integer key \"$key\"" ) ; continue ; } $ l = strlen ( $ key ) ; if ( $ l > 127 ) { self :: $ logger -> warning ( "Ignoring overlong key \"$key\"" ) ; continue ; } $ v = self :: serializeValue ( $ value ) ; if ( $ v === null ) { return null ; } $ ret .= chr ( $ l ) . $ key . $ v ; } return $ ret ; }
|
Encode a session array to a string in php_binary format
|
697
|
public static function decodePhpBinary ( $ data ) { if ( ! is_string ( $ data ) ) { throw new \ InvalidArgumentException ( '$data must be a string' ) ; } $ ret = [ ] ; while ( $ data !== '' && $ data !== false ) { $ l = ord ( $ data [ 0 ] ) ; if ( strlen ( $ data ) < ( $ l & 127 ) + 1 ) { self :: $ logger -> error ( 'Unserialize failed: unexpected end of string' ) ; return null ; } if ( $ l > 127 ) { $ data = substr ( $ data , ( $ l & 127 ) + 1 ) ; continue ; } $ key = substr ( $ data , 1 , $ l ) ; $ data = substr ( $ data , $ l + 1 ) ; if ( $ data === '' || $ data === false ) { self :: $ logger -> error ( 'Unserialize failed: unexpected end of string' ) ; return null ; } list ( $ ok , $ value ) = self :: unserializeValue ( $ data ) ; if ( ! $ ok ) { return null ; } $ ret [ $ key ] = $ value ; } return $ ret ; }
|
Decode a session string in php_binary format to an array
|
698
|
public static function encodePhpSerialize ( array $ data ) { try { return serialize ( $ data ) ; } catch ( \ Exception $ ex ) { self :: $ logger -> error ( 'PHP serialization failed: ' . $ ex -> getMessage ( ) ) ; return null ; } }
|
Encode a session array to a string in php_serialize format
|
699
|
public static function decodePhpSerialize ( $ data ) { if ( ! is_string ( $ data ) ) { throw new \ InvalidArgumentException ( '$data must be a string' ) ; } $ error = null ; set_error_handler ( function ( $ errno , $ errstr ) use ( & $ error ) { $ error = $ errstr ; return true ; } ) ; $ ret = unserialize ( $ data ) ; restore_error_handler ( ) ; if ( $ error !== null ) { self :: $ logger -> error ( 'PHP unserialization failed: ' . $ error ) ; return null ; } if ( ! is_array ( $ ret ) ) { self :: $ logger -> error ( 'PHP unserialization failed (value was not an array)' ) ; return null ; } return $ ret ; }
|
Decode a session string in php_serialize format to an array
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.