idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
38,500 | protected function drawTable ( string $ heading , array $ headers , array $ rows ) : void { if ( ! empty ( $ rows ) ) { $ this -> output -> write ( PHP_EOL ) ; $ this -> output -> writeLn ( '<yellow>' . $ heading . '</yellow>' ) ; $ this -> output -> write ( PHP_EOL ) ; $ table = new Table ( $ this -> output ) ; $ headers = array_map ( function ( $ value ) { return '<green>' . $ value . '</green>' ; } , $ headers ) ; $ table -> draw ( $ headers , $ rows ) ; } } | Draws information table . |
38,501 | protected function getOptions ( ) : array { $ options = [ ] ; foreach ( $ this -> options as $ group ) { foreach ( $ group as $ name => $ option ) { $ options [ ] = [ '--' . $ name , $ option [ 'description' ] ] ; } } sort ( $ options ) ; return $ options ; } | Returns an array of option information . |
38,502 | protected function displayReactorInfo ( ) : void { if ( ! empty ( $ this -> logo ) ) { $ this -> output -> writeLn ( $ this -> logo ) ; $ this -> output -> write ( PHP_EOL ) ; } $ this -> output -> writeLn ( '<yellow>Usage:</yellow>' ) ; $ this -> output -> write ( PHP_EOL ) ; $ this -> output -> writeLn ( 'php reactor [command] [arguments] [options]' ) ; $ this -> listOptions ( ) ; } | Displays basic reactor information . |
38,503 | protected function getCommands ( ) : array { $ info = [ ] ; foreach ( $ this -> commands as $ name => $ class ) { $ command = $ this -> instantiateCommandWithoutConstructor ( $ class ) ; $ info [ $ name ] = [ $ name , $ command -> getCommandDescription ( ) ] ; } ksort ( $ info ) ; return $ info ; } | Returns an array of command information . |
38,504 | protected function convertArgumentsAndOptionsArrayToRows ( array $ input ) : array { $ rows = [ ] ; foreach ( $ input as $ name => $ info ) { $ rows [ ] = [ $ name , $ info [ 'description' ] , var_export ( $ info [ 'optional' ] , true ) ] ; } return $ rows ; } | Converst the argument and options arrays to table rows . |
38,505 | protected function displayCommandHelp ( string $ command ) : int { $ commandInstance = $ this -> instantiateCommandWithoutConstructor ( $ this -> commands [ $ command ] ) ; $ this -> output -> writeLn ( '<yellow>Command:</yellow>' ) ; $ this -> output -> write ( PHP_EOL ) ; $ this -> output -> writeLn ( 'php reactor ' . $ command ) ; $ this -> output -> write ( PHP_EOL ) ; $ this -> output -> writeLn ( '<yellow>Description:</yellow>' ) ; $ this -> output -> write ( PHP_EOL ) ; $ this -> output -> writeLn ( $ commandInstance -> getCommandDescription ( ) ) ; if ( ! empty ( $ arguments = $ commandInstance -> getCommandArguments ( ) ) ) { $ this -> drawTable ( 'Arguments:' , [ 'Name' , 'Description' , 'Optional' ] , $ this -> convertArgumentsAndOptionsArrayToRows ( $ arguments ) ) ; } if ( ! empty ( $ options = $ commandInstance -> getCommandOptions ( ) ) ) { $ this -> drawTable ( 'Options:' , [ 'Name' , 'Description' , 'Optional' ] , $ this -> convertArgumentsAndOptionsArrayToRows ( $ options ) ) ; } return CommandInterface :: STATUS_SUCCESS ; } | Displays information about the chosen command . |
38,506 | protected function unknownCommand ( string $ command ) : int { $ message = 'Unknown command [ ' . $ command . ' ].' ; if ( ( $ suggestion = $ this -> suggest ( $ command , array_keys ( $ this -> commands ) ) ) !== null ) { $ message .= ' Did you mean [ ' . $ suggestion . ' ]?' ; } $ this -> output -> writeLn ( '<red>' . $ message . '</red>' ) ; $ this -> listCommands ( ) ; return CommandInterface :: STATUS_ERROR ; } | Displays error message for unknown commands . |
38,507 | protected function getGlobalOptionNames ( ) : array { $ names = [ ] ; foreach ( $ this -> options as $ group ) { $ names = array_merge ( $ names , array_keys ( $ group ) ) ; } return $ names ; } | Returns the names of the global options . |
38,508 | public function run ( ) : int { $ this -> handleGlobalOptions ( ) ; if ( ( $ command = $ this -> input -> getArgument ( 1 ) ) === null ) { return $ this -> displayReactorInfoAndCommandList ( ) ; } if ( $ this -> commandExists ( $ command ) === false ) { return $ this -> unknownCommand ( $ command ) ; } if ( $ this -> input -> getArgument ( 'help' , false ) !== false ) { return $ this -> displayCommandHelp ( $ command ) ; } return $ this -> dispatch ( $ command ) ; } | Run the reactor . |
38,509 | public function addMiddleware ( string $ middleware , bool $ inner = true ) : int { return $ inner ? $ this -> onion -> addInnerLayer ( $ middleware ) : $ this -> onion -> addOuterLayer ( $ middleware ) ; } | Adds middleware . |
38,510 | protected function resolveCommand ( $ command , array $ parameters ) : CommandInterface { if ( $ command instanceof CommandInterface ) { return $ command ; } return $ this -> container -> get ( $ command , $ parameters ) ; } | Resolves the command . |
38,511 | protected function resolveCommandHandler ( CommandInterface $ command ) : CommandHandlerInterface { $ class = get_class ( $ command ) ; $ commandSuffixLength = strlen ( static :: COMMAND_SUFFIX ) ; if ( static :: COMMAND_SUFFIX === substr ( $ class , - $ commandSuffixLength ) ) { $ handler = substr_replace ( $ class , static :: HANDLER_SUFFIX , strrpos ( $ class , static :: COMMAND_SUFFIX ) , $ commandSuffixLength ) ; } else { $ handler = $ class . static :: HANDLER_SUFFIX ; } return $ this -> container -> get ( $ handler ) ; } | Resolves the command handler . |
38,512 | protected function resolveOnion ( array $ middleware ) : Onion { if ( empty ( $ middleware ) ) { return $ this -> onion ; } $ onion = clone $ this -> onion ; foreach ( $ middleware as $ layer ) { $ onion -> addLayer ( $ layer ) ; } return $ onion ; } | Resolves the onion instance . |
38,513 | public function addMeta ( string $ key , $ value ) : void { Arr :: set ( $ this -> meta , $ key , $ value ) ; } | Adds meta . |
38,514 | public function getSigned ( string $ name , $ default = null ) { if ( empty ( $ this -> signer ) ) { throw new RuntimeException ( 'A [ Signer ] instance is required to read signed cookies.' ) ; } if ( isset ( $ this -> cookies [ $ name ] ) && ( $ cookie = $ this -> signer -> validate ( $ this -> cookies [ $ name ] ) ) !== false ) { return $ cookie ; } return $ default ; } | Gets a signed cookie value . |
38,515 | public function instance ( ? string $ configuration = null ) { $ configuration = $ configuration ?? $ this -> default ; if ( ! isset ( $ this -> instances [ $ configuration ] ) ) { $ this -> instances [ $ configuration ] = $ this -> instantiate ( $ configuration ) ; } return $ this -> instances [ $ configuration ] ; } | Returns an instance of the chosen adapter configuration . |
38,516 | protected function parseKey ( string $ key ) : array { return ( strpos ( $ key , '.' ) === false ) ? [ $ key , null ] : explode ( '.' , $ key , 2 ) ; } | Parses the language key . |
38,517 | protected function load ( string $ file ) : void { $ this -> configuration [ $ file ] = $ this -> loader -> load ( $ file , $ this -> environment ) ; } | Loads the configuration file . |
38,518 | public function get ( string $ key , $ default = null ) { [ $ file , $ path ] = $ this -> parseKey ( $ key ) ; if ( ! isset ( $ this -> configuration [ $ file ] ) ) { $ this -> load ( $ file ) ; } return $ path === null ? $ this -> configuration [ $ file ] : Arr :: get ( $ this -> configuration [ $ file ] , $ path , $ default ) ; } | Returns config value or entire config array from a file . |
38,519 | public function set ( string $ key , $ value ) : void { [ $ file ] = $ this -> parseKey ( $ key ) ; if ( ! isset ( $ this -> configuration [ $ file ] ) ) { $ this -> load ( $ file ) ; } Arr :: set ( $ this -> configuration , $ key , $ value ) ; } | Sets a config value . |
38,520 | public function getNamedRoute ( string $ name ) : Route { if ( ! isset ( $ this -> namedRoutes [ $ name ] ) ) { throw new RuntimeException ( vsprintf ( 'No route named [ %s ] has been defined.' , [ $ name ] ) ) ; } return $ this -> namedRoutes [ $ name ] ; } | Returns the named route . |
38,521 | public function group ( array $ options , Closure $ routes ) : void { $ this -> groups [ ] = $ options ; $ routes ( $ this ) ; array_pop ( $ this -> groups ) ; } | Adds a grouped set of routes to the colleciton . |
38,522 | public function get ( string $ route , $ action , ? string $ name = null ) : Route { return $ this -> registerRoute ( [ 'GET' , 'HEAD' , 'OPTIONS' ] , $ route , $ action , $ name ) ; } | Adds a route that responds to GET requests to the collection . |
38,523 | public function register ( array $ methods , string $ route , $ action , ? string $ name = null ) : Route { return $ this -> registerRoute ( $ methods , $ route , $ action , $ name ) ; } | Adds a route that respodns to the chosen HTTP methods to the collection . |
38,524 | public function draw ( int $ from = 5 ) : void { $ dots = 0 ; $ fromLength = strlen ( $ from ) ; $ totalLength = $ fromLength + 5 ; do { do { $ numbers = str_pad ( $ from , $ fromLength , '0' , STR_PAD_LEFT ) ; $ this -> output -> write ( "\r" . str_pad ( $ numbers . ' ' . str_repeat ( '.' , $ dots ) . ' ' , $ totalLength , ' ' ) ) ; $ this -> sleep ( ) ; } while ( $ dots ++ < 3 ) ; $ dots = 0 ; } while ( $ from -- > 1 ) ; $ this -> output -> write ( "\r" . str_repeat ( ' ' , $ totalLength ) . "\r" ) ; } | Counts down from n . |
38,525 | public function removeConfiguration ( string $ name ) : void { unset ( $ this -> configurations [ $ name ] , $ this -> connections [ $ name ] ) ; } | Removes a configuration . It will also remove any active connection linked to the configuration . |
38,526 | protected function getFilePath ( string $ file , ? string $ extension = null , ? string $ suffix = null ) : string { if ( strpos ( $ file , '::' ) === false ) { $ path = $ this -> path ; } else { [ $ namespace , $ file ] = explode ( '::' , $ file , 2 ) ; if ( ! isset ( $ this -> namespaces [ $ namespace ] ) ) { throw new RuntimeException ( vsprintf ( 'The [ %s ] namespace does not exist.' , [ $ namespace ] ) ) ; } $ path = $ this -> namespaces [ $ namespace ] ; } if ( $ suffix !== null ) { $ path .= DIRECTORY_SEPARATOR . $ suffix ; } return $ path . DIRECTORY_SEPARATOR . str_replace ( '.' , DIRECTORY_SEPARATOR , $ file ) . ( $ extension ?? $ this -> extension ) ; } | Returns the path to the file . |
38,527 | protected function getCascadingFilePaths ( string $ file , ? string $ extension = null , ? string $ suffix = null ) : array { $ paths = [ ] ; if ( strpos ( $ file , '::' ) === false ) { $ paths [ ] = $ this -> getFilePath ( $ file , $ extension , $ suffix ) ; } else { $ paths [ ] = $ this -> getFilePath ( $ file , $ extension , $ suffix ) ; [ $ package , $ file ] = explode ( '::' , $ file ) ; $ suffix = 'packages' . DIRECTORY_SEPARATOR . $ package . ( ( $ suffix !== null ) ? DIRECTORY_SEPARATOR . $ suffix : '' ) ; array_unshift ( $ paths , $ this -> getFilePath ( $ file , $ extension , $ suffix ) ) ; } return $ paths ; } | Returns an array of cascading file paths . |
38,528 | public static function validate ( string $ uuid ) : bool { $ uuid = str_replace ( [ 'urn:uuid:' , '{' , '}' ] , '' , $ uuid ) ; return ( bool ) preg_match ( '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i' , $ uuid ) ; } | Checks if a UUID is valid . |
38,529 | public static function toBinary ( string $ uuid ) : string { if ( ! static :: validate ( $ uuid ) ) { throw new InvalidArgumentException ( 'The provided string is not a valid UUID.' ) ; } $ hex = str_replace ( [ 'urn:uuid:' , '{' , '}' , '-' ] , '' , $ uuid ) ; $ binary = '' ; for ( $ i = 0 ; $ i < 32 ; $ i += 2 ) { $ binary .= chr ( hexdec ( $ hex [ $ i ] . $ hex [ $ i + 1 ] ) ) ; } return $ binary ; } | Converts a UUID from its hexadecimal representation to a binary string . |
38,530 | public static function toHexadecimal ( string $ bytes ) : string { if ( strlen ( $ bytes ) !== 16 ) { throw new InvalidArgumentException ( 'The input must be exactly 16 bytes.' ) ; } return vsprintf ( '%s%s-%s-%s-%s-%s%s%s' , str_split ( bin2hex ( $ bytes ) , 4 ) ) ; } | Converts a binary UUID to its hexadecimal representation . |
38,531 | public static function v3 ( string $ namespace , string $ name ) : string { $ hash = md5 ( self :: toBinary ( $ namespace ) . $ name ) ; return sprintf ( '%s-%s-%x-%x-%s' , substr ( $ hash , 0 , 8 ) , substr ( $ hash , 8 , 4 ) , ( hexdec ( substr ( $ hash , 12 , 4 ) ) & 0x0fff ) | 0x3000 , ( hexdec ( substr ( $ hash , 16 , 4 ) ) & 0x3fff ) | 0x8000 , substr ( $ hash , 20 , 12 ) ) ; } | Returns a V3 UUID . |
38,532 | public static function v4 ( ) : string { $ random = random_bytes ( 16 ) ; $ random [ 6 ] = chr ( ord ( $ random [ 6 ] ) & 0x0f | 0x40 ) ; $ random [ 8 ] = chr ( ord ( $ random [ 8 ] ) & 0x3f | 0x80 ) ; return vsprintf ( '%s%s-%s-%s-%s-%s%s%s' , str_split ( bin2hex ( $ random ) , 4 ) ) ; } | Returns a V4 UUID . |
38,533 | public static function v5 ( string $ namespace , string $ name ) : string { $ hash = sha1 ( static :: toBinary ( $ namespace ) . $ name ) ; return sprintf ( '%s-%s-%x-%x-%s' , substr ( $ hash , 0 , 8 ) , substr ( $ hash , 8 , 4 ) , ( hexdec ( substr ( $ hash , 12 , 4 ) ) & 0x0fff ) | 0x5000 , ( hexdec ( substr ( $ hash , 16 , 4 ) ) & 0x3fff ) | 0x8000 , substr ( $ hash , 20 , 12 ) ) ; } | Returns a V5 UUID . |
38,534 | protected function nl ( int $ lines = 1 , int $ writer = Output :: STANDARD ) : void { $ this -> output -> write ( str_repeat ( PHP_EOL , $ lines ) , $ writer ) ; } | Writes n newlines to output . |
38,535 | protected function alert ( string $ message , string $ template = Alert :: DEFAULT , int $ writer = Output :: STANDARD ) : void { ( new Alert ( $ this -> output ) ) -> draw ( $ message , $ template , $ writer ) ; } | Draws an alert . |
38,536 | protected function ol ( array $ items , string $ marker = '<yellow>%s</yellow>.' , int $ writer = Output :: STANDARD ) : void { ( new OrderedList ( $ this -> output ) ) -> draw ( $ items , $ marker , $ writer ) ; } | Draws an ordered list . |
38,537 | protected function confirm ( string $ question , string $ default = 'n' ) { return ( new Confirmation ( $ this -> input , $ this -> output ) ) -> ask ( $ question , $ default ) ; } | Writes question to output and returns boolesn value corresponding to the chosen value . |
38,538 | public static function decode ( string $ key ) : string { if ( strpos ( $ key , 'hex:' ) === 0 ) { return hex2bin ( mb_substr ( $ key , 4 , null , '8bit' ) ) ; } return $ key ; } | Converts a hexadecimal key into its binary representation . |
38,539 | protected function escape ( string $ string ) : string { if ( ( $ formatter = $ this -> output -> getFormatter ( ) ) === null ) { return $ string ; } return $ formatter -> escape ( $ string ) ; } | Escape formatting tags . |
38,540 | protected function determineExceptionType ( Throwable $ exception ) : string { if ( $ exception instanceof ErrorException ) { $ code = $ exception -> getCode ( ) ; $ codes = [ E_ERROR => 'Fatal Error' , E_PARSE => 'Parse Error' , E_COMPILE_ERROR => 'Compile Error' , E_COMPILE_WARNING => 'Compile Warning' , E_STRICT => 'Strict Mode Error' , E_NOTICE => 'Notice' , E_WARNING => 'Warning' , E_RECOVERABLE_ERROR => 'Recoverable Error' , E_DEPRECATED => 'Deprecated' , E_USER_NOTICE => 'Notice' , E_USER_WARNING => 'Warning' , E_USER_ERROR => 'Error' , E_USER_DEPRECATED => 'Deprecated' , ] ; return in_array ( $ code , array_keys ( $ codes ) ) ? $ codes [ $ code ] : 'ErrorException' ; } return get_class ( $ exception ) ; } | Determines the exception type . |
38,541 | protected function getStyleCodes ( string $ tag ) : array { if ( isset ( $ this -> styles [ $ tag ] ) ) { return [ $ this -> styles [ $ tag ] ] ; } elseif ( isset ( $ this -> userStyles [ $ tag ] ) ) { $ codes = [ ] ; foreach ( $ this -> userStyles [ $ tag ] as $ tag ) { $ codes = array_merge ( $ codes , $ this -> getStyleCodes ( $ tag ) ) ; } return $ codes ; } throw new FormatterException ( vsprintf ( 'Undefined formatting tag [ %s ] detected.' , [ $ tag ] ) ) ; } | Returns style codes associated with the tag name . |
38,542 | protected function closeStyle ( string $ tag ) : string { if ( $ this -> getTagName ( $ tag ) !== end ( $ this -> openTags ) ) { throw new FormatterException ( 'Detected incorrectly nested formatting tag.' ) ; } array_pop ( $ this -> openTags ) ; $ style = $ this -> getSgrResetSequence ( ) ; if ( ! empty ( $ this -> openTags ) ) { foreach ( $ this -> openTags as $ tag ) { $ style .= $ this -> getSgrStyleSequence ( $ tag ) ; } } return $ style ; } | Returns ANSI SGR escape sequence for style reset and ANSI SGR escape sequence for parent style if the closed tag was nested . |
38,543 | public function matches ( string $ pattern ) : bool { return ( bool ) preg_match ( '#' . $ pattern . '#' , $ this -> request -> getPath ( ) ) ; } | Returns TRUE if the pattern matches the current route and FALSE if not . |
38,544 | public function to ( string $ path , array $ queryParams = [ ] , string $ separator = '&' , $ language = true ) : string { $ url = $ this -> baseURL . ( $ this -> cleanURLs ? '' : '/' . $ this -> scriptName ) . ( $ language === true ? $ this -> languagePrefix : ( ! $ language ? '' : '/' . $ language ) ) . $ path ; if ( ! empty ( $ queryParams ) ) { $ url .= '?' . http_build_query ( $ queryParams , '' , $ separator , PHP_QUERY_RFC3986 ) ; } return $ url ; } | Returns the URL of the specified path . |
38,545 | public function toLanguage ( string $ route , $ language , array $ queryParams = [ ] , string $ separator = '&' ) : string { return $ this -> to ( $ route , $ queryParams , $ separator , $ language ) ; } | Returns the URL of the specified route . |
38,546 | public function add ( string $ name , $ value ) : void { Arr :: set ( $ this -> parameters , $ name , $ value ) ; } | Adds a parameter . |
38,547 | protected function buildPageUrl ( int $ page ) : string { if ( $ this -> params === null ) { $ this -> params = $ this -> request -> getQuery ( ) -> all ( ) ; } return $ this -> urlBuilder -> current ( [ $ this -> options [ 'page_key' ] => $ page ] + $ this -> params ) ; } | Builds a url to the desired page . |
38,548 | public function pagination ( ) : array { if ( empty ( $ this -> pagination ) ) { if ( empty ( $ this -> request ) ) { throw new RuntimeException ( 'A [ Request ] instance is required to generate the pagination array.' ) ; } if ( empty ( $ this -> urlBuilder ) ) { throw new RuntimeException ( 'A [ URLBuilder ] instance is required to generate the pagination array.' ) ; } $ pagination = $ this -> toArray ( ) ; if ( $ this -> options [ 'max_page_links' ] !== 0 ) { if ( $ this -> pages > $ this -> options [ 'max_page_links' ] ) { $ start = ( int ) max ( ( $ this -> currentPage ) - ceil ( $ this -> options [ 'max_page_links' ] / 2 ) , 0 ) ; $ end = $ start + $ this -> options [ 'max_page_links' ] ; if ( $ end > $ this -> pages ) { $ end = $ this -> pages ; } if ( $ start > ( $ end - $ this -> options [ 'max_page_links' ] ) ) { $ start = $ end - $ this -> options [ 'max_page_links' ] ; } } else { $ start = 0 ; $ end = $ this -> pages ; } $ pagination [ 'pages' ] = [ ] ; for ( $ i = $ start + 1 ; $ i <= $ end ; $ i ++ ) { $ pagination [ 'pages' ] [ ] = [ 'url' => $ this -> buildPageUrl ( $ i ) , 'number' => $ i , 'is_current' => $ i === $ this -> currentPage , ] ; } } $ this -> pagination = $ pagination ; } return $ this -> pagination ; } | Builds and returns the pagination array . |
38,549 | public function render ( string $ view ) : string { if ( empty ( $ this -> viewFactory ) ) { throw new RuntimeException ( 'A [ ViewFactory ] instance is required to render pagination views.' ) ; } return $ this -> viewFactory -> create ( $ view , $ this -> pagination ( ) ) -> render ( ) ; } | Renders and returns the pagination partial . |
38,550 | protected function getForeignKey ( ) { if ( $ this -> foreignKey === null ) { $ this -> foreignKey = $ this -> parent -> getForeignKey ( ) ; } return $ this -> foreignKey ; } | Returns the foreign key . |
38,551 | protected function keys ( array $ results ) { $ keys = [ ] ; foreach ( $ results as $ result ) { $ keys [ ] = $ result -> getPrimaryKeyValue ( ) ; } return array_unique ( $ keys ) ; } | Returns the keys used to eagerly load records . |
38,552 | protected function lazyCriterion ( ) : void { $ this -> where ( $ this -> table . '.' . $ this -> getForeignKey ( ) , '=' , $ this -> parent -> getPrimaryKeyValue ( ) ) ; } | Sets the criterion used when lazy loading related records . |
38,553 | protected function eagerLoadChunked ( array $ keys ) { if ( count ( $ keys ) > static :: EAGER_LOAD_CHUNK_SIZE ) { $ records = [ ] ; foreach ( array_chunk ( $ keys , static :: EAGER_LOAD_CHUNK_SIZE ) as $ chunk ) { $ query = clone $ this ; $ records = array_merge ( $ records , $ query -> eagerCriterion ( $ chunk ) -> all ( ) -> getItems ( ) ) ; } return $ this -> createResultSet ( $ records ) ; } return $ this -> eagerCriterion ( $ keys ) -> all ( ) ; } | Eager loads records in chunks . |
38,554 | protected function setOperation ( $ query , string $ operation ) { if ( ( $ query instanceof Subquery ) === false ) { $ query = new Subquery ( $ query ) ; } $ this -> setOperations [ ] = [ 'query' => $ query , 'operation' => $ operation , ] ; return $ this ; } | Adds a set operation . |
38,555 | public function table ( $ table ) { if ( $ table instanceof Closure ) { $ table = new Subquery ( $ table , 'mako0' ) ; } $ this -> table = $ table ; return $ this ; } | Sets table we want to query . |
38,556 | public function whereRaw ( $ column , $ operator = null , ? string $ raw = null , string $ separator = 'AND' ) { if ( $ raw === null ) { $ this -> wheres [ ] = [ 'type' => 'whereRaw' , 'raw' => new Raw ( $ column , is_array ( $ operator ) ? $ operator : [ ] ) , 'separator' => $ separator , ] ; return $ this ; } return $ this -> where ( $ column , $ operator , new Raw ( $ raw ) , $ separator ) ; } | Adds a raw WHERE clause . |
38,557 | public function orWhereRaw ( $ column , $ operator = null , ? string $ raw = null ) { return $ this -> whereRaw ( $ column , $ operator , $ raw , 'OR' ) ; } | Adds a raw OR WHERE clause . |
38,558 | public function between ( $ column , $ value1 , $ value2 , string $ separator = 'AND' , bool $ not = false ) { $ this -> wheres [ ] = [ 'type' => 'between' , 'column' => $ column , 'value1' => $ value1 , 'value2' => $ value2 , 'separator' => $ separator , 'not' => $ not , ] ; return $ this ; } | Adds a BETWEEN clause . |
38,559 | public function notBetween ( $ column , $ value1 , $ value2 ) { return $ this -> between ( $ column , $ value1 , $ value2 , 'AND' , true ) ; } | Adds a NOT BETWEEN clause . |
38,560 | public function orNotBetween ( $ column , $ value1 , $ value2 ) { return $ this -> between ( $ column , $ value1 , $ value2 , 'OR' , true ) ; } | Adds a OR NOT BETWEEN clause . |
38,561 | public function in ( $ column , $ values , string $ separator = 'AND' , bool $ not = false ) { if ( $ values instanceof Raw || $ values instanceof Subquery ) { $ values = [ $ values ] ; } elseif ( $ values instanceof Closure ) { $ values = [ new Subquery ( $ values ) ] ; } $ this -> wheres [ ] = [ 'type' => 'in' , 'column' => $ column , 'values' => $ values , 'separator' => $ separator , 'not' => $ not , ] ; return $ this ; } | Adds a IN clause . |
38,562 | public function isNull ( $ column , string $ separator = 'AND' , bool $ not = false ) { $ this -> wheres [ ] = [ 'type' => 'null' , 'column' => $ column , 'separator' => $ separator , 'not' => $ not , ] ; return $ this ; } | Adds a IS NULL clause . |
38,563 | public function exists ( $ query , string $ separator = 'AND' , bool $ not = false ) { if ( $ query instanceof Closure ) { $ query = new Subquery ( $ query ) ; } $ this -> wheres [ ] = [ 'type' => 'exists' , 'query' => $ query , 'separator' => $ separator , 'not' => $ not , ] ; return $ this ; } | Adds a EXISTS clause . |
38,564 | public function join ( $ table , $ column1 = null , $ operator = null , $ column2 = null , string $ type = 'INNER' , bool $ raw = false ) { $ join = new Join ( $ type , $ table ) ; if ( $ column1 instanceof Closure ) { $ column1 ( $ join ) ; } else { if ( $ raw ) { $ join -> onRaw ( $ column1 , $ operator , $ column2 ) ; } else { $ join -> on ( $ column1 , $ operator , $ column2 ) ; } } $ this -> joins [ ] = $ join ; return $ this ; } | Adds a JOIN clause . |
38,565 | public function joinRaw ( $ table , $ column1 , $ operator , $ raw , string $ type = 'INNER' ) { return $ this -> join ( $ table , $ column1 , $ operator , $ raw , $ type , true ) ; } | Adds a raw JOIN clause . |
38,566 | public function leftJoin ( $ table , $ column1 = null , $ operator = null , $ column2 = null ) { return $ this -> join ( $ table , $ column1 , $ operator , $ column2 , 'LEFT OUTER' ) ; } | Adds a LEFT OUTER JOIN clause . |
38,567 | public function leftJoinRaw ( $ table , $ column1 , $ operator , $ raw ) { return $ this -> joinRaw ( $ table , $ column1 , $ operator , $ raw , 'LEFT OUTER' ) ; } | Adds a raw LEFT OUTER JOIN clause . |
38,568 | public function having ( $ column , $ operator , $ value , string $ separator = 'AND' ) { $ this -> havings [ ] = [ 'column' => $ column , 'operator' => $ operator , 'value' => $ value , 'separator' => $ separator , ] ; return $ this ; } | Adds a HAVING clause . |
38,569 | public function havingRaw ( $ raw , $ operator , $ value , string $ separator = 'AND' ) { return $ this -> having ( new Raw ( $ raw ) , $ operator , $ value , $ separator ) ; } | Adds a raw HAVING clause . |
38,570 | public function orderBy ( $ columns , string $ order = 'ASC' ) { $ this -> orderings [ ] = [ 'column' => is_array ( $ columns ) ? $ columns : [ $ columns ] , 'order' => ( $ order === 'ASC' || $ order === 'asc' ) ? 'ASC' : 'DESC' , ] ; return $ this ; } | Adds a ORDER BY clause . |
38,571 | public function column ( $ column = null ) { if ( $ column !== null ) { $ this -> select ( [ $ column ] ) ; } $ query = $ this -> limit ( 1 ) -> compiler -> select ( ) ; return $ this -> connection -> column ( $ query [ 'sql' ] , $ query [ 'params' ] ) ; } | Executes a SELECT query and returns the value of the chosen column of the first row of the result set . |
38,572 | protected function fetchFirst ( ... $ fetchMode ) { $ query = $ this -> limit ( 1 ) -> compiler -> select ( ) ; return $ this -> connection -> first ( $ query [ 'sql' ] , $ query [ 'params' ] , ... $ fetchMode ) ; } | Executes a SELECT query and returns the first row of the result set . |
38,573 | protected function fetchAll ( bool $ returnResultSet , ... $ fetchMode ) { $ query = $ this -> compiler -> select ( ) ; $ results = $ this -> connection -> all ( $ query [ 'sql' ] , $ query [ 'params' ] , ... $ fetchMode ) ; return $ returnResultSet ? $ this -> createResultSet ( $ results ) : $ results ; } | Executes a SELECT query and returns an array containing all of the result set rows . |
38,574 | protected function fetchYield ( ... $ fetchMode ) : Generator { $ query = $ this -> compiler -> select ( ) ; yield from $ this -> connection -> yield ( $ query [ 'sql' ] , $ query [ 'params' ] , ... $ fetchMode ) ; } | Executes a SELECT query and returns a generator that lets you iterate over the results . |
38,575 | protected function paginationCount ( ) : int { $ clone = ( clone $ this ) -> clearOrderings ( ) ; if ( empty ( $ this -> groupings ) && $ this -> distinct === false ) { return $ clone -> count ( ) ; } return $ this -> newInstance ( ) -> table ( new Subquery ( $ clone , 'count' ) ) -> count ( ) ; } | Returns the number of records that the query will return . |
38,576 | public function paginate ( ? int $ itemsPerPage = null , array $ options = [ ] ) { $ count = $ this -> paginationCount ( ) ; $ pagination = static :: getPaginationFactory ( ) -> create ( $ count , $ itemsPerPage , $ options ) ; if ( $ count > 0 ) { $ results = $ this -> limit ( $ pagination -> limit ( ) ) -> offset ( $ pagination -> offset ( ) ) -> all ( ) ; } else { $ results = $ this -> createResultSet ( [ ] ) ; } $ results -> setPagination ( $ pagination ) ; return $ results ; } | Paginates the results using a pagination instance . |
38,577 | public function batch ( Closure $ processor , int $ batchSize = 1000 , int $ offsetStart = 0 , ? int $ offsetEnd = null ) : void { $ this -> limit ( $ batchSize ) ; while ( true ) { $ query = clone $ this ; if ( $ offsetEnd !== null && $ offsetStart >= $ offsetEnd ) { break ; } if ( $ offsetStart !== 0 ) { $ query -> offset ( $ offsetStart ) ; } $ results = $ query -> all ( ) ; if ( count ( $ results ) > 0 ) { $ processor ( $ results ) ; $ offsetStart += $ batchSize ; } else { break ; } } } | Fetches data in batches and passes them to the processor closure . |
38,578 | protected function aggregate ( string $ function , $ column ) { $ this -> select ( [ new Raw ( sprintf ( $ function , $ this -> compiler -> columns ( is_array ( $ column ) ? $ column : [ $ column ] ) ) ) ] ) ; if ( $ this -> inSubqueryContext === false ) { $ query = $ this -> compiler -> select ( ) ; return $ this -> connection -> column ( $ query [ 'sql' ] , $ query [ 'params' ] ) ; } } | Sets the selected column of the query to the chosen aggreate . Executes the query and returns the result if not in subquery context . |
38,579 | public function insert ( array $ values = [ ] ) : bool { $ query = $ this -> compiler -> insert ( $ values ) ; return $ this -> connection -> query ( $ query [ 'sql' ] , $ query [ 'params' ] ) ; } | Inserts data into the chosen table . |
38,580 | public function insertAndGetId ( array $ values , string $ primaryKey = 'id' ) { return $ this -> helper -> insertAndGetId ( $ this , $ values , $ primaryKey ) ; } | Inserts data into the chosen table and returns the auto increment id . |
38,581 | public function update ( array $ values ) : int { $ query = $ this -> compiler -> update ( $ values ) ; return $ this -> connection -> queryAndCount ( $ query [ 'sql' ] , $ query [ 'params' ] ) ; } | Updates data from the chosen table . |
38,582 | public function increment ( $ column , int $ increment = 1 ) : int { return $ this -> update ( [ $ column => new Raw ( $ this -> compiler -> escapeIdentifier ( $ column ) . ' + ' . ( int ) $ increment ) ] ) ; } | Increments column value . |
38,583 | public function decrement ( $ column , int $ decrement = 1 ) : int { return $ this -> update ( [ $ column => new Raw ( $ this -> compiler -> escapeIdentifier ( $ column ) . ' - ' . ( int ) $ decrement ) ] ) ; } | Decrements column value . |
38,584 | public function delete ( ) : int { $ query = $ this -> compiler -> delete ( ) ; return $ this -> connection -> queryAndCount ( $ query [ 'sql' ] , $ query [ 'params' ] ) ; } | Deletes data from the chosen table . |
38,585 | public function getFileNamespace ( ) : string { if ( $ this -> fileNamespace === null ) { $ this -> fileNamespace = str_replace ( '/' , '-' , strtolower ( $ this -> packageName ) ) ; } return $ this -> fileNamespace ; } | Returns the package namespace . |
38,586 | public function getClassNamespace ( bool $ prefix = false ) : string { if ( $ this -> classNamespace === null ) { $ this -> classNamespace = substr ( static :: class , 0 , strrpos ( static :: class , '\\' ) ) ; } return $ prefix ? '\\' . $ this -> classNamespace : $ this -> classNamespace ; } | Returns the class namespace . |
38,587 | public function getPath ( ) : string { if ( $ this -> path === null ) { $ this -> path = dirname ( ( new ReflectionClass ( $ this ) ) -> getFileName ( ) , 2 ) ; } return $ this -> path ; } | Returns package path . |
38,588 | public function boot ( ) : void { $ fileSystem = $ this -> container -> get ( FileSystem :: class ) ; if ( $ fileSystem -> isDirectory ( $ path = $ this -> getConfigPath ( ) ) ) { $ configLoader = $ this -> container -> get ( Config :: class ) -> getLoader ( ) ; if ( in_array ( NamespacedFileLoaderTrait :: class , class_uses ( $ configLoader ) ) ) { $ configLoader -> registerNamespace ( $ this -> getFileNamespace ( ) , $ path ) ; } } if ( $ fileSystem -> isDirectory ( $ path = $ this -> getI18nPath ( ) ) && $ this -> container -> has ( I18n :: class ) ) { $ i18nLoader = $ this -> container -> get ( I18n :: class ) -> getLoader ( ) ; if ( in_array ( NamespacedFileLoaderTrait :: class , class_uses ( $ i18nLoader ) ) ) { $ i18nLoader -> registerNamespace ( $ this -> getFileNamespace ( ) , $ path ) ; } } if ( $ fileSystem -> isDirectory ( $ path = $ this -> getViewPath ( ) ) && $ this -> container -> has ( ViewFactory :: class ) ) { $ this -> container -> get ( ViewFactory :: class ) -> registerNamespace ( $ this -> getFileNamespace ( ) , $ path ) ; } $ this -> bootstrap ( ) ; } | Boots the package . |
38,589 | protected function calculateWidth ( array $ items , string $ marker ) : array { $ count = 0 ; foreach ( $ items as $ item ) { if ( ! is_array ( $ item ) ) { $ count ++ ; } } $ number = strlen ( $ count ) ; $ marker = strlen ( sprintf ( $ this -> formatter === null ? $ marker : $ this -> formatter -> stripTags ( $ marker ) , '' ) ) + $ number ; return [ 'number' => $ number , 'marker' => $ marker ] ; } | Calculates the maximum width of a marker in a list . |
38,590 | protected function buildList ( array $ items , string $ marker , int $ nestingLevel = 0 , int $ parentWidth = 0 ) : string { $ width = $ this -> calculateWidth ( $ items , $ marker ) ; $ number = 0 ; $ list = '' ; foreach ( $ items as $ item ) { if ( is_array ( $ item ) ) { $ list .= $ this -> buildList ( $ item , $ marker , ( $ nestingLevel + 1 ) , ( $ width [ 'marker' ] - 1 + $ parentWidth ) ) ; } else { $ list .= $ this -> buildListItem ( $ item , $ marker , $ width [ 'number' ] , ++ $ number , $ nestingLevel , $ parentWidth ) ; } } return $ list ; } | Builds an ordered list . |
38,591 | public function getWriter ( int $ writer = Output :: STANDARD ) : WriterInterface { return ( $ writer === static :: STANDARD ) ? $ this -> standard : $ this -> error ; } | Returns the chosen writer . |
38,592 | public function dump ( $ value , int $ writer = Output :: STANDARD ) : void { $ this -> getWriter ( $ writer ) -> write ( var_export ( $ value , true ) . PHP_EOL ) ; } | Dumps a value to the output . |
38,593 | public function clearLines ( int $ lines ) : void { if ( $ this -> environment -> hasAnsiSupport ( ) ) { for ( $ i = 0 ; $ i < $ lines ; $ i ++ ) { if ( $ i > 0 ) { $ this -> write ( "\033[F" ) ; } $ this -> clearLine ( ) ; } } } | Clears n lines . |
38,594 | public function getHeaders ( ) : array { $ headers = [ ] ; foreach ( $ this -> parameters as $ key => $ value ) { if ( strpos ( $ key , 'HTTP_' ) === 0 ) { $ headers [ substr ( $ key , 5 ) ] = $ value ; } elseif ( in_array ( $ key , [ 'CONTENT_LENGTH' , 'CONTENT_MD5' , 'CONTENT_TYPE' ] ) ) { $ headers [ $ key ] = $ value ; } } return $ headers ; } | Returns all the request headers . |
38,595 | public function assign ( string $ name , $ value ) : View { $ this -> variables [ $ name ] = $ value ; return $ this ; } | Assign a local view variable . |
38,596 | protected function connect ( string $ connection ) : Redis { if ( ! isset ( $ this -> configurations [ $ connection ] ) ) { throw new RuntimeException ( vsprintf ( '[ %s ] has not been defined in the redis configuration.' , [ $ connection ] ) ) ; } $ config = $ this -> configurations [ $ connection ] ; return new Redis ( new Connection ( $ config [ 'host' ] , $ config [ 'port' ] , $ config [ 'persistent' ] ?? false , $ config [ 'timeout' ] ?? 60 , $ connection ) , $ config ) ; } | Connects to the chosen redis configuration and returns the connection . |
38,597 | protected function deriveKey ( string $ key , string $ salt , int $ keySize ) : string { return hash_pbkdf2 ( static :: DERIVATION_HASH , $ key , $ salt , static :: DERIVATION_ITERATIONS , $ keySize , true ) ; } | Generate a PBKDF2 key derivation of a supplied key . |
38,598 | protected function getContext ( ) : array { if ( $ this -> app -> isCommandLine ( ) === false && $ this -> container -> has ( Gatekeeper :: class ) ) { $ user = $ this -> container -> get ( Gatekeeper :: class ) -> getUser ( ) ; return [ 'user_id' => $ user !== null ? $ user -> getId ( ) : null ] ; } return [ ] ; } | Get global logger context . |
38,599 | protected function getHandler ( ) : HandlerInterface { $ handler = new StreamHandler ( $ this -> app -> getPath ( ) . '/storage/logs/' . date ( 'Y-m-d' ) . '.mako' ) ; $ formatter = new LineFormatter ( null , null , true , true ) ; $ formatter -> includeStacktraces ( ) ; $ handler -> setFormatter ( $ formatter ) ; return $ handler ; } | Returns the default handler . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.