idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
38,400 | public function include ( $ includes ) { $ items = $ this -> items ; ( function ( ) use ( $ includes , $ items ) : void { $ this -> including ( $ includes ) -> loadIncludes ( $ items ) ; } ) -> bindTo ( $ this -> items [ 0 ] -> builder ( ) , Query :: class ) ( ) ; return $ this ; } | Eager loads relations on the collection . |
38,401 | protected function createClusterClient ( string $ server ) : Redis { [ $ server , $ port ] = explode ( ':' , $ server , 2 ) ; $ isPersistent = $ this -> connection -> isPersistent ( ) ; $ timeout = $ this -> connection -> getTimeout ( ) ; $ name = $ this -> connection -> getName ( ) ; $ connection = new Connection ( $ server , $ port , $ isPersistent , $ timeout , $ name ) ; return new static ( $ connection , [ 'password' => $ this -> password , 'database' => $ this -> database ] ) ; } | Creates a cluster client . |
38,402 | protected function handleErrorResponse ( string $ response ) { $ response = substr ( $ response , 1 ) ; [ $ type , $ error ] = explode ( ' ' , $ response , 2 ) ; switch ( $ type ) { case 'MOVED' : case 'ASK' : return $ this -> getClusterClient ( $ error ) -> sendCommandAndGetResponse ( $ this -> lastCommand ) ; break ; default : throw new RedisException ( vsprintf ( '%s.' , [ $ response ] ) ) ; } } | Handles redis error responses . |
38,403 | protected function handleBulkResponse ( string $ response ) : ? string { if ( $ response === '$-1' ) { return null ; } $ length = ( int ) substr ( $ response , 1 ) ; return substr ( $ this -> connection -> read ( $ length + static :: CRLF_LENGTH ) , 0 , - static :: CRLF_LENGTH ) ; } | Handles a bulk response . |
38,404 | protected function handleMultiBulkResponse ( string $ response ) : ? array { if ( $ response === '*-1' ) { return null ; } $ data = [ ] ; $ count = ( int ) substr ( $ response , 1 ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ data [ ] = $ this -> getResponse ( ) ; } return $ data ; } | Handles a multi - bulk response . |
38,405 | protected function getResponse ( ) { $ response = trim ( $ this -> connection -> readLine ( ) ) ; switch ( substr ( $ response , 0 , 1 ) ) { case '-' : return $ this -> handleErrorResponse ( $ response ) ; break ; case '+' : return $ this -> handleStatusResponse ( $ response ) ; break ; case ':' : return $ this -> handleIntegerResponse ( $ response ) ; break ; case '$' : return $ this -> handleBulkResponse ( $ response ) ; break ; case '*' : return $ this -> handleMultiBulkResponse ( $ response ) ; break ; default : throw new RedisException ( vsprintf ( 'Unable to handle server response [ %s ].' , [ $ response ] ) ) ; } } | Returns response from redis server . |
38,406 | protected function sendCommandToServer ( string $ command ) : void { $ this -> lastCommand = $ command ; $ this -> connection -> write ( $ command ) ; } | Sends command to server . |
38,407 | public function pipeline ( Closure $ pipeline ) : array { $ this -> pipelined = true ; $ pipeline ( $ this ) ; $ responses = [ ] ; $ commands = count ( $ this -> commands ) ; $ this -> sendCommandToServer ( implode ( '' , $ this -> commands ) ) ; for ( $ i = 0 ; $ i < $ commands ; $ i ++ ) { $ responses [ ] = $ this -> getResponse ( ) ; } $ this -> commands = [ ] ; $ this -> pipelined = false ; return $ responses ; } | Pipeline commands . |
38,408 | protected function buildCommand ( string $ name ) : array { $ command = strtoupper ( str_replace ( '_' , ' ' , Str :: camel2underscored ( $ name ) ) ) ; if ( strpos ( $ command , ' ' ) === false ) { return [ $ command ] ; } $ command = explode ( ' ' , $ command , 2 ) ; if ( strpos ( $ command [ 1 ] , ' ' ) !== false ) { $ command [ 1 ] = str_replace ( ' ' , '-' , $ command [ 1 ] ) ; } return $ command ; } | Builds command from method name . |
38,409 | protected function isValidInput ( array $ columnNames , array $ rows ) : bool { $ columns = count ( $ columnNames ) ; if ( ! empty ( $ rows ) ) { foreach ( $ rows as $ row ) { if ( count ( $ row ) !== $ columns ) { return false ; } } } return true ; } | Checks if the number of cells in each row matches the number of columns . |
38,410 | protected function getColumnWidths ( array $ columnNames , array $ rows ) : array { $ columnWidths = [ ] ; foreach ( array_values ( $ columnNames ) as $ key => $ value ) { $ columnWidths [ $ key ] = $ this -> stringWidthWithoutFormatting ( $ value ) ; } foreach ( $ rows as $ row ) { foreach ( array_values ( $ row ) as $ key => $ value ) { $ width = $ this -> stringWidthWithoutFormatting ( $ value ) ; if ( $ width > $ columnWidths [ $ key ] ) { $ columnWidths [ $ key ] = $ width ; } } } return $ columnWidths ; } | Returns an array containing the maximum width of each column . |
38,411 | protected function buildRowSeparator ( array $ columnWidths , string $ separator = '-' ) : string { $ columns = count ( $ columnWidths ) ; return str_repeat ( $ separator , array_sum ( $ columnWidths ) + ( ( $ columns * 4 ) - ( $ columns - 1 ) ) ) . PHP_EOL ; } | Builds a row separator . |
38,412 | protected function buildTableRow ( array $ colums , array $ columnWidths ) : string { $ cells = [ ] ; foreach ( array_values ( $ colums ) as $ key => $ value ) { $ cells [ ] = $ value . str_repeat ( ' ' , $ columnWidths [ $ key ] - $ this -> stringWidthWithoutFormatting ( $ value ) ) ; } return '| ' . implode ( ' | ' , $ cells ) . ' |' . PHP_EOL ; } | Builds a table row . |
38,413 | public function addUser ( User $ user ) : bool { if ( ! $ this -> isPersisted ) { throw new LogicException ( 'You can only add a user to a group that exist in the database.' ) ; } if ( ! $ user -> isPersisted ( ) ) { throw new LogicException ( 'You can only add a user that exist in the database to a group.' ) ; } return $ this -> users ( ) -> link ( $ user ) ; } | Adds a user to the group . |
38,414 | public function removeUser ( User $ user ) : bool { if ( ! $ this -> isPersisted ) { throw new LogicException ( 'You can only remove a user from a group that exist in the database.' ) ; } if ( ! $ user -> isPersisted ( ) ) { throw new LogicException ( 'You can only remove a user that exist in the database from a group.' ) ; } return $ this -> users ( ) -> unlink ( $ user ) ; } | Removes a user from the group . |
38,415 | public function isMember ( User $ user ) { if ( ! $ this -> isPersisted ) { throw new LogicException ( 'You can only check if a user is a member of a group that exist in the database.' ) ; } if ( ! $ user -> isPersisted ( ) ) { throw new LogicException ( 'You can only check if a user that exist in the database is a member of a group.' ) ; } return $ this -> users ( ) -> where ( $ user -> getPrimaryKey ( ) , '=' , $ user -> getPrimaryKeyValue ( ) ) -> count ( ) > 0 ; } | Returns TRUE if a user is a member of the group and FALSE if not . |
38,416 | protected function buildList ( array $ items , string $ marker , int $ nestingLevel = 0 ) : string { $ list = '' ; foreach ( $ items as $ item ) { if ( is_array ( $ item ) ) { $ list .= $ this -> buildList ( $ item , $ marker , $ nestingLevel + 1 ) ; } else { $ list .= $ this -> buildListItem ( $ item , $ marker , $ nestingLevel ) ; } } return $ list ; } | Builds an unordered list . |
38,417 | protected function checkConfigurationExistence ( string $ configuration ) : bool { $ configurations = array_keys ( $ this -> config -> get ( 'cache.configurations' ) ) ; if ( ! in_array ( $ configuration , $ configurations ) ) { $ message = 'The [ ' . $ configuration . ' ] configuration does not exist.' ; if ( ( $ suggestion = $ this -> suggest ( $ configuration , $ configurations ) ) !== null ) { $ message .= ' Did you mean [ ' . $ suggestion . ' ]?' ; } $ this -> error ( $ message ) ; return false ; } return true ; } | Checks if the configuration exists . |
38,418 | protected function getImageInfo ( $ file ) { $ imageInfo = getimagesize ( $ file ) ; if ( $ imageInfo === false ) { throw new RuntimeException ( vsprintf ( 'Unable to process the image [ %s ].' , [ $ file ] ) ) ; } return $ imageInfo ; } | Collects information about the image . |
38,419 | protected function createImageResource ( $ image , $ imageInfo ) { switch ( $ imageInfo [ 2 ] ) { case IMAGETYPE_JPEG : return imagecreatefromjpeg ( $ image ) ; break ; case IMAGETYPE_GIF : return imagecreatefromgif ( $ image ) ; break ; case IMAGETYPE_PNG : return imagecreatefrompng ( $ image ) ; break ; default : throw new RuntimeException ( vsprintf ( 'Unable to open [ %s ]. Unsupported image type.' , [ pathinfo ( $ image , PATHINFO_EXTENSION ) ] ) ) ; } } | Creates an image resource that we can work with . |
38,420 | protected function hexToRgb ( $ hex ) { $ hex = str_replace ( '#' , '' , $ hex ) ; if ( preg_match ( '/^([a-f0-9]{3}){1,2}$/i' , $ hex ) === 0 ) { throw new InvalidArgumentException ( vsprintf ( 'Invalid HEX value [ %s ].' , [ $ hex ] ) ) ; } if ( strlen ( $ hex ) === 3 ) { $ r = hexdec ( str_repeat ( substr ( $ hex , 0 , 1 ) , 2 ) ) ; $ g = hexdec ( str_repeat ( substr ( $ hex , 1 , 1 ) , 2 ) ) ; $ b = hexdec ( str_repeat ( substr ( $ hex , 2 , 1 ) , 2 ) ) ; } else { $ r = hexdec ( substr ( $ hex , 0 , 2 ) ) ; $ g = hexdec ( substr ( $ hex , 2 , 2 ) ) ; $ b = hexdec ( substr ( $ hex , 4 , 2 ) ) ; } return [ 'r' => $ r , 'g' => $ g , 'b' => $ b ] ; } | Converts HEX value to an RGB array . |
38,421 | protected function createConnection ( string $ host , int $ port , bool $ persistent , int $ timeout ) { try { if ( $ persistent ) { return pfsockopen ( 'tcp://' . $ host , $ port , $ errNo , $ errStr , $ timeout ) ; } return fsockopen ( 'tcp://' . $ host , $ port , $ errNo , $ errStr , $ timeout ) ; } catch ( Throwable $ e ) { $ message = $ this -> name === null ? 'Failed to connect' : vsprintf ( 'Failed to connect to [ %s ]' , [ $ this -> name ] ) ; throw new RedisException ( vsprintf ( '%s. %s' , [ $ message , $ e -> getMessage ( ) ] ) , ( int ) $ errNo ) ; } } | Creates a socket connection to the server . |
38,422 | public function readLine ( ) : string { $ line = fgets ( $ this -> connection ) ; if ( $ line === false || $ line === '' ) { throw new RedisException ( $ this -> appendReadErrorReason ( 'Failed to read line from the server.' ) ) ; } return $ line ; } | Gets line from the server . |
38,423 | public function read ( int $ bytes ) : string { $ bytesLeft = $ bytes ; $ data = '' ; do { $ chunk = fread ( $ this -> connection , min ( $ bytesLeft , 4096 ) ) ; if ( $ chunk === false || $ chunk === '' ) { throw new RedisException ( $ this -> appendReadErrorReason ( 'Failed to read data from the server.' ) ) ; } $ data .= $ chunk ; $ bytesLeft = $ bytes - strlen ( $ data ) ; } while ( $ bytesLeft > 0 ) ; return $ data ; } | Reads n bytes from the server . |
38,424 | public function write ( string $ data ) : int { $ totalBytesWritten = 0 ; $ bytesLeft = strlen ( $ data ) ; do { $ totalBytesWritten += $ bytesWritten = fwrite ( $ this -> connection , $ data ) ; if ( $ bytesWritten === false || $ bytesWritten === 0 ) { throw new RedisException ( 'Failed to write data to the server.' ) ; } $ bytesLeft -= $ bytesWritten ; $ data = substr ( $ data , $ bytesWritten ) ; } while ( $ bytesLeft > 0 ) ; return $ totalBytesWritten ; } | Writes data to the server . |
38,425 | protected function suggest ( string $ string , array $ alternatives ) : ? string { $ suggestion = false ; foreach ( $ alternatives as $ alternative ) { similar_text ( $ string , $ alternative , $ similarity ) ; if ( $ similarity > 66 && ( $ suggestion === false || $ suggestion [ 'similarity' ] < $ similarity ) ) { $ suggestion = [ 'string' => $ alternative , 'similarity' => $ similarity ] ; } } return $ suggestion === false ? null : $ suggestion [ 'string' ] ; } | Returns the string that resembles the provided string the most . NULL is returned if no string with a similarity of 66% or more is found . |
38,426 | protected function stringWidthWithoutFormatting ( string $ string ) : int { return ( int ) mb_strwidth ( $ this -> formatter !== null ? $ this -> formatter -> stripTags ( $ string ) : $ string ) ; } | Returns the width of the string without formatting . |
38,427 | public function can ( string $ action , $ entity ) : bool { return $ this -> authorizer -> can ( $ this , $ action , $ entity ) ; } | Returns true if allowed to perform the action on the entity and false if not . |
38,428 | public function on ( $ column1 , ? string $ operator = null , $ column2 = null , string $ separator = 'AND' ) : Join { if ( $ column1 instanceof Closure ) { $ join = new self ; $ column1 ( $ join ) ; $ this -> conditions [ ] = [ 'type' => 'nestedJoinCondition' , 'join' => $ join , 'separator' => $ separator , ] ; } else { $ this -> conditions [ ] = [ 'type' => 'joinCondition' , 'column1' => $ column1 , 'operator' => $ operator , 'column2' => $ column2 , 'separator' => $ separator , ] ; } return $ this ; } | Adds a ON condition to the join . |
38,429 | public function onRaw ( $ column1 , string $ operator , string $ raw , string $ separator = 'AND' ) : Join { return $ this -> on ( $ column1 , $ operator , new Raw ( $ raw ) , $ separator ) ; } | Adds a raw ON condition to the join . |
38,430 | public function orOn ( $ column1 , ? string $ operator = null , $ column2 = null ) : Join { return $ this -> on ( $ column1 , $ operator , $ column2 , 'OR' ) ; } | Adds a OR ON condition to the join . |
38,431 | public function orOnRaw ( $ column1 , string $ operator , string $ raw ) : Join { return $ this -> onRaw ( $ column1 , $ operator , $ raw , 'OR' ) ; } | Adds a raw OR ON condition to the join . |
38,432 | public function override ( string $ name , $ handler ) : void { $ this -> clear ( $ name ) ; $ this -> register ( $ name , $ handler ) ; } | Overrides an event . |
38,433 | protected function executeHandler ( $ handler , array $ parameters ) { if ( $ handler instanceof Closure ) { return $ this -> executeClosureHandler ( $ handler , $ parameters ) ; } $ handler = $ this -> resolveHandler ( $ handler ) ; return $ this -> executeClassHandler ( $ handler , $ parameters ) ; } | Executes the event handler and returns the response . |
38,434 | public function trigger ( string $ name , array $ parameters = [ ] , bool $ break = false ) : array { $ returnValues = [ ] ; if ( isset ( $ this -> events [ $ name ] ) ) { foreach ( $ this -> events [ $ name ] as $ handler ) { $ returnValues [ ] = $ last = $ this -> executeHandler ( $ handler , $ parameters ) ; if ( $ break && $ last === false ) { break ; } } } return $ returnValues ; } | Runs all closures for an event and returns an array contaning the return values of each event handler . |
38,435 | protected function normalizeDriverName ( string $ driver ) : string { foreach ( $ this -> driverAliases as $ normalized => $ aliases ) { if ( in_array ( $ driver , $ aliases ) ) { return $ normalized ; } } return $ driver ; } | Returns the normalized driver name . |
38,436 | protected function connect ( string $ connectionName ) : Connection { if ( ! isset ( $ this -> configurations [ $ connectionName ] ) ) { throw new RuntimeException ( vsprintf ( '[ %s ] has not been defined in the database configuration.' , [ $ connectionName ] ) ) ; } $ config = $ this -> configurations [ $ connectionName ] ; $ driver = $ this -> normalizeDriverName ( explode ( ':' , $ config [ 'dsn' ] , 2 ) [ 0 ] ) ; $ compiler = $ this -> getQueryCompilerClass ( $ driver ) ; $ helper = $ this -> getQueryBuilderHelperClass ( $ driver ) ; $ connection = $ this -> getConnectionClass ( $ driver ) ; return new $ connection ( $ connectionName , $ compiler , $ helper , $ config ) ; } | Connects to the chosen database and returns the connection . |
38,437 | public function getLogs ( bool $ groupedByConnection = true ) : array { $ logs = [ ] ; if ( $ groupedByConnection ) { foreach ( $ this -> connections as $ connection ) { $ logs [ $ connection -> getName ( ) ] = $ connection -> getLog ( ) ; } } else { foreach ( $ this -> connections as $ connection ) { $ logs = array_merge ( $ logs , $ connection -> getLog ( ) ) ; } } return $ logs ; } | Returns the query log for all connections . |
38,438 | protected function getDimensionsForUnixLike ( ) : ? array { if ( ( $ width = getenv ( 'COLUMNS' ) ) !== false && ( $ height = getenv ( 'LINES' ) ) !== false ) { return [ 'width' => ( int ) $ width , 'height' => ( int ) $ height ] ; } exec ( 'stty size' , $ output , $ status ) ; if ( $ status === 0 && preg_match ( '/^([0-9]+) ([0-9]+)$/' , current ( $ output ) , $ matches ) ) { return [ 'width' => ( int ) $ matches [ 2 ] , 'height' => ( int ) $ matches [ 1 ] ] ; } return null ; } | Attempts to get dimensions for Unix - like platforms . |
38,439 | public function hasAnsiSupport ( ) : bool { if ( $ this -> hasAnsiSupport === null ) { $ this -> hasAnsiSupport = PHP_OS_FAMILY !== 'Windows' || ( getenv ( 'ANSICON' ) !== false || getenv ( 'ConEmuANSI' ) === 'ON' ) ; } return $ this -> hasAnsiSupport ; } | Do we have ANSI support? |
38,440 | protected function checkForInvalidArguments ( CommandInterface $ command , array $ providedArguments , array $ globalOptions ) : void { $ commandArguments = array_keys ( $ command -> getCommandArguments ( ) + $ command -> getCommandOptions ( ) ) ; $ defaultAndGlobalOptions = array_merge ( [ 'arg0' , 'arg1' ] , $ globalOptions ) ; foreach ( array_keys ( $ providedArguments ) as $ name ) { if ( ! in_array ( $ name , $ defaultAndGlobalOptions ) && ! in_array ( $ name , $ commandArguments ) ) { if ( strpos ( $ name , 'arg' ) === 0 ) { throw new InvalidArgumentException ( vsprintf ( 'Invalid argument [ %s ].' , [ $ name ] ) , $ name ) ; } throw new InvalidOptionException ( vsprintf ( 'Invalid option [ %s ].' , [ $ name ] ) , $ name , $ this -> suggest ( $ name , $ commandArguments ) ) ; } } } | Checks for invalid arguments or options . |
38,441 | protected function checkForMissingArgumentsOrOptions ( array $ commandArguments , array $ providedArguments , string $ exception ) : void { $ providedArguments = array_keys ( $ providedArguments ) ; foreach ( $ commandArguments as $ name => $ details ) { if ( isset ( $ details [ 'optional' ] ) && $ details [ 'optional' ] === false && ! in_array ( $ name , $ providedArguments ) ) { $ type = $ exception === MissingArgumentException :: class ? 'argument' : 'option' ; throw new $ exception ( vsprintf ( 'Missing required %s [ %s ].' , [ $ type , $ name ] ) , $ name ) ; } } } | Checks for missing required arguments or options . |
38,442 | protected function checkForMissingArguments ( CommandInterface $ command , array $ providedArguments ) : void { $ this -> checkForMissingArgumentsOrOptions ( $ command -> getCommandArguments ( ) , $ providedArguments , MissingArgumentException :: class ) ; } | Checks for missing required arguments . |
38,443 | protected function checkForMissingOptions ( CommandInterface $ command , array $ providedArguments ) : void { $ this -> checkForMissingArgumentsOrOptions ( $ command -> getCommandOptions ( ) , $ providedArguments , MissingOptionException :: class ) ; } | Checks for missing required options . |
38,444 | protected function checkArgumentsAndOptions ( CommandInterface $ command , array $ providedArguments , array $ globalOptions ) : void { if ( $ command -> isStrict ( ) ) { $ this -> checkForInvalidArguments ( $ command , $ providedArguments , $ globalOptions ) ; } $ this -> checkForMissingArguments ( $ command , $ providedArguments ) ; $ this -> checkForMissingOptions ( $ command , $ providedArguments ) ; } | Checks arguments and options . |
38,445 | protected function convertArgumentsToCamelCase ( array $ arguments ) : array { return array_combine ( array_map ( function ( $ key ) { return Str :: underscored2camel ( str_replace ( '-' , '_' , $ key ) ) ; } , array_keys ( $ arguments ) ) , array_values ( $ arguments ) ) ; } | Converts arguments to camel case . |
38,446 | public function dispatch ( string $ command , array $ arguments , array $ globalOptions ) : int { $ command = $ this -> resolve ( $ command ) ; $ this -> checkArgumentsAndOptions ( $ command , $ arguments , $ globalOptions ) ; $ returnValue = $ this -> execute ( $ command , $ arguments ) ; return is_int ( $ returnValue ) ? $ returnValue : CommandInterface :: STATUS_SUCCESS ; } | Dispatches the command . |
38,447 | public function touch ( ) : bool { if ( $ this -> isPersisted ) { $ this -> columns [ $ this -> getUpdatedAtColumn ( ) ] = null ; return $ this -> save ( ) ; } return false ; } | Allows you to update the updated at timestamp without modifying any data . |
38,448 | protected function touchRelated ( ) : void { foreach ( $ this -> getRelationsToTouch ( ) as $ touch ) { $ touch = explode ( '.' , $ touch ) ; $ relation = $ this -> { array_shift ( $ touch ) } ( ) ; foreach ( $ touch as $ nested ) { $ related = $ relation -> first ( ) ; if ( $ related === false ) { continue 2 ; } $ relation = $ related -> $ nested ( ) ; } $ relation -> update ( [ $ relation -> getModel ( ) -> getUpdatedAtColumn ( ) => null ] ) ; } } | Touches related records . |
38,449 | public function setCharset ( string $ charset ) : ViewFactory { $ this -> globalVariables [ '__charset__' ] = $ this -> charset = $ charset ; return $ this ; } | Sets the charset . |
38,450 | public function extend ( string $ extension , $ renderer ) : ViewFactory { $ this -> renderers = [ $ extension => $ renderer ] + $ this -> renderers ; return $ this ; } | Registers a custom view renderer . |
38,451 | public function assign ( string $ name , $ value ) : ViewFactory { $ this -> globalVariables [ $ name ] = $ value ; return $ this ; } | Assign a global view variable that will be available in all views . |
38,452 | public function autoAssign ( $ view , callable $ variables ) : ViewFactory { foreach ( ( array ) $ view as $ name ) { $ this -> autoAssignVariables [ $ name ] = $ variables ; } return $ this ; } | Assign variables that should be auto assigned to views upon creation . |
38,453 | protected function getViewPathAndExtension ( string $ view , bool $ throwException = true ) { if ( ! isset ( $ this -> viewCache [ $ view ] ) ) { foreach ( $ this -> renderers as $ extension => $ renderer ) { $ paths = $ this -> getCascadingFilePaths ( $ view , $ extension ) ; foreach ( $ paths as $ path ) { if ( $ this -> fileSystem -> has ( $ path ) ) { return $ this -> viewCache [ $ view ] = [ $ path , $ extension ] ; } } } if ( $ throwException ) { throw new ViewException ( vsprintf ( 'The [ %s ] view does not exist.' , [ $ view ] ) ) ; } return false ; } return $ this -> viewCache [ $ view ] ; } | Returns an array containing the view path and the renderer we should use . |
38,454 | protected function rendererFactory ( $ renderer ) : RendererInterface { return $ renderer instanceof Closure ? $ this -> container -> call ( $ renderer ) : $ this -> container -> get ( $ renderer ) ; } | Creates a renderer instance . |
38,455 | protected function resolveRenderer ( string $ extension ) : RendererInterface { if ( ! isset ( $ this -> rendererInstances [ $ extension ] ) ) { $ this -> rendererInstances [ $ extension ] = $ this -> rendererFactory ( $ this -> renderers [ $ extension ] ) ; } return $ this -> rendererInstances [ $ extension ] ; } | Returns a renderer instance . |
38,456 | protected function getAutoAssignVariablesForView ( string $ view ) : array { if ( ! isset ( $ this -> autoAssignVariables [ $ view ] ) ) { return [ ] ; } return ( $ this -> autoAssignVariables [ $ view ] ) ( ) ; } | Returns view specific auto assign variables . |
38,457 | protected function mergeVariables ( string $ view , array $ variables ) : array { return $ variables + $ this -> getAutoAssignVariables ( $ view ) + $ this -> globalVariables ; } | Returns array where variables have been merged in order of importance . |
38,458 | public function create ( string $ view , array $ variables = [ ] ) : View { [ $ path , $ extension ] = $ this -> getViewPathAndExtension ( $ view ) ; return new View ( $ path , $ this -> mergeVariables ( $ view , $ variables ) , $ this -> resolveRenderer ( $ extension ) ) ; } | Creates and returns a view instance . |
38,459 | public function render ( string $ view , array $ variables = [ ] ) : string { return $ this -> create ( $ view , $ variables ) -> render ( ) ; } | Creates and returns a rendered view . |
38,460 | public static function getTraits ( $ class , bool $ autoload = true ) : array { $ traits = [ ] ; do { $ traits += class_uses ( $ class , $ autoload ) ; } while ( $ class = get_parent_class ( $ class ) ) ; $ search = $ traits ; $ searched = [ ] ; while ( ! empty ( $ search ) ) { $ trait = array_pop ( $ search ) ; if ( isset ( $ searched [ $ trait ] ) ) { continue ; } $ traits += $ search += class_uses ( $ trait , $ autoload ) ; $ searched [ $ trait ] = $ trait ; } return $ traits ; } | Returns an array of all traits used by a class . |
38,461 | protected function authorize ( string $ action , $ entity ) : void { if ( $ this -> authorizer -> can ( $ this -> gatekeeper -> getUser ( ) , $ action , $ entity ) === false ) { throw new ForbiddenException ; } } | Throws a ForbiddenException if the user is not allowed to perform the action on the entity . |
38,462 | public function reload ( ) : bool { if ( $ this -> isPersisted ) { $ model = static :: get ( $ this -> getPrimaryKeyValue ( ) ) ; if ( $ model !== false ) { $ this -> original = $ this -> columns = $ model -> getRawColumnValues ( ) ; $ this -> related = $ model -> getRelated ( ) ; return true ; } } return false ; } | Reloads the record from the database . |
38,463 | public function getMessageWithSuggestion ( ) : string { $ message = $ this -> getMessage ( ) ; if ( $ this -> suggestion !== null ) { $ message .= ' Did you mean [ ' . $ this -> suggestion . ' ]?' ; } return $ message ; } | Returns the exception message with a suggestion . |
38,464 | protected function normalizeMultiUpload ( array $ files ) : array { $ normalized = [ ] ; $ keys = array_keys ( $ files ) ; $ count = count ( $ files [ 'name' ] ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { foreach ( $ keys as $ key ) { $ normalized [ $ i ] [ $ key ] = $ files [ $ key ] [ $ i ] ; } } return $ normalized ; } | Normalizes a multi file upload array to a more manageable format . |
38,465 | protected function needToCompile ( string $ view , string $ compiled ) : bool { return ! $ this -> fileSystem -> has ( $ compiled ) || $ this -> fileSystem -> lastModified ( $ compiled ) < $ this -> fileSystem -> lastModified ( $ view ) ; } | Returns TRUE if the template needs to be compiled and FALSE if not . |
38,466 | protected function compile ( string $ view ) : void { ( new Compiler ( $ this -> fileSystem , $ this -> cachePath , $ view ) ) -> compile ( ) ; } | Compiles view . |
38,467 | public function output ( string $ name ) : void { $ parent = $ this -> close ( ) ; $ output = current ( $ this -> blocks [ $ name ] ) ; unset ( $ this -> blocks [ $ name ] ) ; if ( ! empty ( $ parent ) ) { $ output = str_replace ( '__PARENT__' , $ parent , $ output ) ; } echo $ output ; } | Output a template block . |
38,468 | public function getErrorMessage ( ) : string { switch ( $ this -> errorCode ) { case UPLOAD_ERR_OK : return 'There is no error, the file was successfully uploaded.' ; case UPLOAD_ERR_INI_SIZE : return 'The uploaded file exceeds the upload_max_filesize directive in php.ini.' ; case UPLOAD_ERR_FORM_SIZE : return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.' ; case UPLOAD_ERR_PARTIAL : return 'The uploaded file was only partially uploaded.' ; case UPLOAD_ERR_NO_FILE : return 'No file was uploaded.' ; case UPLOAD_ERR_NO_TMP_DIR : return 'Missing a temporary folder.' ; case UPLOAD_ERR_CANT_WRITE : return 'Failed to write file to disk.' ; case UPLOAD_ERR_EXTENSION : return 'A PHP extension stopped the file upload.' ; default : return 'Unknown upload error.' ; } } | Returns a human friendly error message . |
38,469 | public function moveTo ( string $ path ) : bool { if ( $ this -> hasError ( ) ) { throw new UploadException ( vsprintf ( '%s' , [ $ this -> getErrorMessage ( ) ] ) , $ this -> getErrorCode ( ) ) ; } if ( $ this -> isUploaded ( ) === false ) { throw new UploadException ( 'The file that you\'re trying to move was not uploaded.' , - 1 ) ; } return $ this -> moveUploadedFile ( $ path ) ; } | Moves the file to the desired path . |
38,470 | protected function buildJsonPath ( array $ segments ) : string { $ path = '' ; foreach ( $ segments as $ segment ) { if ( is_numeric ( $ segment ) ) { $ path .= '[' . $ segment . ']' ; } else { $ path .= '.' . '"' . str_replace ( [ '"' , "'" ] , [ '\\\"' , "''" ] , $ segment ) . '"' ; } } return '$' . $ path ; } | Builds a JSON path . |
38,471 | protected function fileFactory ( array $ configuration ) : File { return ( new File ( $ this -> container -> get ( FileSystem :: class ) , $ configuration [ 'path' ] , $ this -> classWhitelist ) ) -> setPrefix ( $ configuration [ 'prefix' ] ?? '' ) ; } | File store factory . |
38,472 | protected function databaseFactory ( array $ configuration ) : Database { return ( new Database ( $ this -> container -> get ( DatabaseConnectionManager :: class ) -> connection ( $ configuration [ 'configuration' ] ) , $ configuration [ 'table' ] , $ this -> classWhitelist ) ) -> setPrefix ( $ configuration [ 'prefix' ] ?? '' ) ; } | Database store factory . |
38,473 | protected function redisFactory ( array $ configuration ) : Redis { return ( new Redis ( $ this -> container -> get ( RedisConnectionManager :: class ) -> connection ( $ configuration [ 'configuration' ] ) , $ this -> classWhitelist ) ) -> setPrefix ( $ configuration [ 'prefix' ] ?? '' ) ; } | Redis store factory . |
38,474 | protected function instantiate ( string $ configuration ) { if ( ! isset ( $ this -> configurations [ $ configuration ] ) ) { throw new RuntimeException ( vsprintf ( '[ %s ] has not been defined in the cache configuration.' , [ $ configuration ] ) ) ; } $ configuration = $ this -> configurations [ $ configuration ] ; return $ this -> factory ( $ configuration [ 'type' ] , $ configuration ) ; } | Returns a cache instance . |
38,475 | protected function setEmptyNullablesToNull ( array $ values ) : array { $ nullables = $ this -> getNullableColumns ( ) ; foreach ( $ values as $ column => $ value ) { if ( $ value === '' && in_array ( $ column , $ nullables ) ) { $ values [ $ column ] = null ; } } return $ values ; } | Will replace empty strings with null if the column is nullable . |
38,476 | public static function underscored2camel ( string $ string , bool $ upper = false ) : string { return preg_replace_callback ( ( $ upper ? '/(?:^|_)(.?)/u' : '/_(.?)/u' ) , function ( $ matches ) { return mb_strtoupper ( $ matches [ 1 ] ) ; } , $ string ) ; } | Converts underscored to camel case . |
38,477 | public static function slug ( string $ string ) : string { return rawurlencode ( mb_strtolower ( preg_replace ( '/\s{1,}/' , '-' , trim ( preg_replace ( '/[\x0-\x1F\x21-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/' , '' , $ string ) ) ) ) ) ; } | Creates a URL friendly string . |
38,478 | public static function autolink ( string $ string , array $ attributes = [ ] ) : string { return preg_replace_callback ( '#\b(?<!href="|">)[a-z]+://\S+(?:/|\b)#i' , function ( $ matches ) use ( $ attributes ) { return ( new HTML ( ) ) -> tag ( 'a' , [ 'href' => $ matches [ 0 ] ] + $ attributes , $ matches [ 0 ] ) ; } , $ string ) ; } | Converts URLs in a text into clickable links . |
38,479 | public static function mask ( string $ string , int $ visible = 3 , string $ mask = '*' ) : string { if ( $ visible === 0 ) { return str_repeat ( $ mask , mb_strlen ( $ string ) ) ; } $ visible = mb_substr ( $ string , - $ visible ) ; return str_pad ( $ visible , ( mb_strlen ( $ string ) + ( strlen ( $ visible ) - mb_strlen ( $ visible ) ) ) , $ mask , STR_PAD_LEFT ) ; } | Returns a masked string where only the last n characters are visible . |
38,480 | public static function increment ( string $ string , int $ start = 1 , string $ separator = '_' ) : string { preg_match ( '/(.+)' . preg_quote ( $ separator ) . '([0-9]+)$/' , $ string , $ matches ) ; return isset ( $ matches [ 2 ] ) ? $ matches [ 1 ] . $ separator . ( ( int ) $ matches [ 2 ] + 1 ) : $ string . $ separator . $ start ; } | Increments a string by appending a number to it or increasing the number . |
38,481 | public function flush ( ? string $ chunk , bool $ flushEmpty = false ) : void { if ( $ this -> isCGI ) { if ( ! empty ( $ chunk ) ) { echo $ chunk ; flush ( ) ; } } else { if ( ! empty ( $ chunk ) || $ flushEmpty === true ) { printf ( "%x\r\n%s\r\n" , strlen ( $ chunk ) , $ chunk ) ; flush ( ) ; } } } | Flushes a chunck of data . |
38,482 | protected function flow ( ) : void { while ( ob_get_level ( ) > 0 ) ob_end_clean ( ) ; $ stream = $ this -> stream ; $ stream ( $ this ) ; $ this -> flush ( null , true ) ; } | Sends the stream . |
38,483 | protected function buildProgressBar ( float $ percent ) : string { $ fill = ( int ) floor ( $ percent * $ this -> width ) ; $ progressBar = str_pad ( $ this -> progress , strlen ( $ this -> items ) , '0' , STR_PAD_LEFT ) . '/' . $ this -> items . ' ' ; $ progressBar .= str_repeat ( $ this -> filledTemplate , $ fill ) ; $ progressBar .= str_repeat ( $ this -> emptyTemplate , ( $ this -> width - $ fill ) ) ; $ progressBar .= str_pad ( ' ' . ( ( int ) ( $ percent * 100 ) ) . '% ' , 6 , ' ' , STR_PAD_LEFT ) ; return $ progressBar ; } | Builds the progressbar . |
38,484 | public function draw ( ) : void { if ( $ this -> items === 0 ) { return ; } $ percent = ( float ) min ( ( $ this -> progress / $ this -> items ) , 1 ) ; $ progressBar = $ this -> buildProgressBar ( $ percent ) ; $ this -> output -> write ( "\r" . $ this -> prefix . $ progressBar ) ; if ( $ this -> progress === $ this -> items ) { $ this -> output -> write ( PHP_EOL ) ; } } | Draws the progressbar . |
38,485 | public function advance ( ) : void { $ this -> progress ++ ; if ( $ this -> progress === $ this -> items || ( $ this -> progress % $ this -> redrawRate ) === 0 ) { $ this -> draw ( ) ; } } | Move progress forward and redraws the progressbar . |
38,486 | protected function reactorFactory ( ) : Reactor { return new Reactor ( $ this -> container -> get ( Input :: class ) , $ this -> container -> get ( Output :: class ) , $ this -> container ) ; } | Creates a reactor instance . |
38,487 | protected function registerGlobalReactorOptions ( ) : void { $ this -> reactor -> registerGlobalOption ( 'env' , 'Overrides the Mako environment' , function ( Config $ config , $ option ) : void { putenv ( 'MAKO_ENV=' . $ option ) ; $ config -> setEnvironment ( $ option ) ; } , 'init' ) ; $ this -> reactor -> registerGlobalOption ( 'mute' , 'Mutes all output' , function ( Output $ output ) : void { $ output -> mute ( ) ; } , 'init' ) ; } | Registers global reactor options . |
38,488 | protected function startReactor ( ) : void { $ this -> container -> registerSingleton ( [ Input :: class , 'input' ] , function ( ) { return $ this -> inputFactory ( ) ; } ) ; $ this -> container -> registerSingleton ( [ Output :: class , 'output' ] , function ( ) { return $ this -> outputFactory ( ) ; } ) ; $ this -> reactor = $ this -> reactorFactory ( ) ; $ this -> reactor -> setLogo ( $ this -> loadLogo ( ) ) ; $ this -> registerGlobalReactorOptions ( ) ; $ this -> reactor -> handleGlobalOptions ( 'init' ) ; } | Starts the reactor . |
38,489 | protected function getCommands ( ) : array { $ commands = [ 'app.generate_key' => GenerateKey :: class , 'app.generate_secret' => GenerateSecret :: class , ] ; if ( $ this -> container -> has ( Routes :: class ) ) { $ commands = array_merge ( $ commands , [ 'app.routes' => ListRoutes :: class , 'server' => Server :: class , ] ) ; } if ( $ this -> container -> has ( CacheManager :: class ) ) { $ commands = array_merge ( $ commands , [ 'cache.remove' => Remove :: class , 'cache.clear' => Clear :: class , ] ) ; } if ( $ this -> container -> has ( DatabaseConnectionManager :: class ) ) { $ commands = array_merge ( $ commands , [ 'migrate.create' => Create :: class , 'migrate.status' => Status :: class , 'migrate.up' => Up :: class , 'migrate.down' => Down :: class , 'migrate.reset' => Reset :: class , ] ) ; } $ commands += $ this -> config -> get ( 'application.commands' ) ; foreach ( $ this -> packages as $ package ) { $ commands += $ package -> getCommands ( ) ; } return $ commands ; } | Returns all registered commands . |
38,490 | public function get ( $ key , $ default = null ) { if ( array_key_exists ( $ key , $ this -> items ) ) { return $ this -> items [ $ key ] ; } return $ default ; } | Returns an item from the collection . |
38,491 | public function offsetGet ( $ offset ) { if ( array_key_exists ( $ offset , $ this -> items ) ) { return $ this -> items [ $ offset ] ; } throw new OutOfBoundsException ( vsprintf ( 'Undefined offset [ %s ].' , [ $ offset ] ) ) ; } | Returns the value at the specified offset . |
38,492 | public function sort ( callable $ comparator , bool $ maintainIndexAssociation = true ) : bool { return $ maintainIndexAssociation ? uasort ( $ this -> items , $ comparator ) : usort ( $ this -> items , $ comparator ) ; } | Sorts the collection using the specified comparator callable and returns TRUE on success and FALSE on failure . |
38,493 | public function each ( callable $ callable ) : void { foreach ( $ this -> items as $ key => $ value ) { $ this -> items [ $ key ] = $ callable ( $ value , $ key ) ; } } | Applies the callable on all items in the collection . |
38,494 | public function filter ( ? callable $ callable = null ) { if ( $ callable === null ) { return new static ( array_filter ( $ this -> items ) ) ; } return new static ( array_filter ( $ this -> items , $ callable , ARRAY_FILTER_USE_BOTH ) ) ; } | Returns a new filtered collection . |
38,495 | protected function buildCommand ( string $ command , bool $ background = false , bool $ sameEnvironment = true ) : string { if ( $ sameEnvironment && strpos ( $ command , '--env=' ) === false && ( $ environment = $ this -> app -> getEnvironment ( ) ) !== null ) { $ command .= ' --env=' . $ environment ; } $ command = PHP_BINARY . ' ' . $ this -> buildReactorPath ( ) . ' ' . $ command . ' 2>&1' ; if ( DIRECTORY_SEPARATOR === '\\' ) { if ( $ background ) { $ command = '/b ' . $ command ; } return 'start ' . $ command ; } if ( $ background ) { $ command .= ' &' ; } return $ command ; } | Returns command that we re going to execute . |
38,496 | protected function fire ( string $ command , Closure $ handler , bool $ sameEnvironment = true ) : int { $ process = popen ( $ this -> buildCommand ( $ command , false , $ sameEnvironment ) , 'r' ) ; while ( ! feof ( $ process ) ) { $ handler ( fread ( $ process , 4096 ) ) ; } return pclose ( $ process ) ; } | Runs command as a separate process and feeds output to handler . |
38,497 | protected function fireAndForget ( string $ command , bool $ sameEnvironment = true ) : void { pclose ( popen ( $ this -> buildCommand ( $ command , true , $ sameEnvironment ) , 'r' ) ) ; } | Starts command as a background process . |
38,498 | public function registerGlobalOption ( string $ name , string $ description , Closure $ handler , string $ group = 'default' ) : void { $ this -> options [ $ group ] [ $ name ] = [ 'description' => $ description , 'handler' => $ handler ] ; } | Register a global reactor option . |
38,499 | public function handleGlobalOptions ( string $ group = 'default' ) : void { if ( isset ( $ this -> options [ $ group ] ) ) { foreach ( $ this -> options [ $ group ] as $ name => $ option ) { $ input = $ this -> input -> getArgument ( $ name ) ; if ( ! empty ( $ input ) ) { $ handler = $ option [ 'handler' ] ; $ this -> container -> call ( $ handler , [ 'option' => $ input ] ) ; } } } } | Handles global reactor options . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.