idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
38,200
public function lap ( ) : float { $ last = end ( $ this -> laps ) ; $ time = $ last -> stop ( ) ; $ this -> start ( ) ; return $ time ; }
Starts a new lap and returns the time of the previous lap .
38,201
public function getElapsedTime ( ) : float { $ last = end ( $ this -> laps ) ; return ( $ last -> isRunning ( ) ? microtime ( true ) : $ last -> getStopTime ( ) ) - $ this -> laps [ 0 ] -> getStartTime ( ) ; }
Get elapsed time .
38,202
public function stop ( ) : float { $ last = end ( $ this -> laps ) ; $ last -> stop ( ) ; return $ last -> getStopTime ( ) - $ this -> laps [ 0 ] -> getStartTime ( ) ; }
Stops the timer and returns the elapsed time .
38,203
public function alongWith ( array $ columns ) { foreach ( $ columns as $ key => $ value ) { if ( strpos ( $ value , '.' ) === false ) { $ columns [ $ key ] = $ this -> getJunctionTable ( ) . '.' . $ value ; } } $ this -> alongWith = $ columns ; return $ this ; }
Columns to include with the result .
38,204
protected function getJunctionTable ( ) { if ( $ this -> junctionTable === null ) { $ tables = [ $ this -> parent -> getTable ( ) , $ this -> model -> getTable ( ) ] ; sort ( $ tables ) ; $ this -> junctionTable = implode ( '_' , $ tables ) ; } return $ this -> junctionTable ; }
Returns the the junction table .
38,205
protected function getJunctionKey ( ) { if ( $ this -> junctionKey === null ) { $ this -> junctionKey = $ this -> model -> getForeignKey ( ) ; } return $ this -> junctionKey ; }
Returns the the junction key .
38,206
protected function junctionJoin ( ) : void { $ this -> join ( $ this -> getJunctionTable ( ) , $ this -> getJunctionTable ( ) . '.' . $ this -> getJunctionKey ( ) , '=' , $ this -> model -> getTable ( ) . '.' . $ this -> model -> getPrimaryKey ( ) ) ; }
Joins the junction table .
38,207
public function eagerLoad ( array & $ results , string $ relation , ? Closure $ criteria , array $ includes ) : void { $ this -> model -> setIncludes ( $ includes ) ; $ grouped = [ ] ; if ( $ criteria !== null ) { $ criteria ( $ this ) ; } $ foreignKey = $ this -> getForeignKey ( ) ; foreach ( $ this -> eagerLoadChunked ( $ this -> keys ( $ results ) ) as $ related ) { $ grouped [ $ related -> getRawColumnValue ( $ foreignKey ) ] [ ] = $ related ; unset ( $ related -> $ foreignKey ) ; } foreach ( $ results as $ result ) { $ result -> setRelated ( $ relation , $ this -> createResultSet ( $ grouped [ $ result -> getPrimaryKeyValue ( ) ] ?? [ ] ) ) ; } }
Eager loads related records and matches them with their parent records .
38,208
protected function getJunctionKeys ( $ id ) : array { $ ids = [ ] ; foreach ( ( is_array ( $ id ) ? $ id : [ $ id ] ) as $ value ) { if ( $ value instanceof $ this -> model ) { $ value = $ value -> getPrimaryKeyValue ( ) ; } $ ids [ ] = $ value ; } return $ ids ; }
Returns an array of ids .
38,209
public function link ( $ id , array $ attributes = [ ] ) : bool { $ success = true ; $ foreignKey = $ this -> getForeignKey ( ) ; $ foreignKeyValue = $ this -> parent -> getPrimaryKeyValue ( ) ; $ junctionKey = $ this -> getJunctionKey ( ) ; foreach ( $ this -> getJunctionKeys ( $ id ) as $ key => $ id ) { $ columns = [ $ foreignKey => $ foreignKeyValue , $ junctionKey => $ id ] ; $ success = $ success && $ this -> junction ( ) -> insert ( $ columns + $ this -> getJunctionAttributes ( $ key , $ attributes ) ) ; } return $ success ; }
Links related records .
38,210
public function updateLink ( $ id , array $ attributes ) : bool { $ success = true ; $ foreignKey = $ this -> getForeignKey ( ) ; $ foreignKeyValue = $ this -> parent -> getPrimaryKeyValue ( ) ; $ junctionKey = $ this -> getJunctionKey ( ) ; foreach ( $ this -> getJunctionKeys ( $ id ) as $ key => $ id ) { $ success = $ success && ( bool ) $ this -> junction ( ) -> where ( $ foreignKey , '=' , $ foreignKeyValue ) -> where ( $ junctionKey , '=' , $ id ) -> update ( $ this -> getJunctionAttributes ( $ key , $ attributes ) ) ; } return $ success ; }
Updates junction attributes .
38,211
public function unlink ( $ id = null ) : bool { $ query = $ this -> junction ( ) -> where ( $ this -> getForeignKey ( ) , '=' , $ this -> parent -> getPrimaryKeyValue ( ) ) ; if ( $ id !== null ) { $ query -> in ( $ this -> getJunctionKey ( ) , $ this -> getJunctionKeys ( $ id ) ) ; } return ( bool ) $ query -> delete ( ) ; }
Unlinks related records .
38,212
public function synchronize ( array $ ids ) : bool { $ success = true ; $ keys = $ this -> getJunctionKeys ( $ ids ) ; $ existing = $ this -> junction ( ) -> where ( $ this -> getForeignKey ( ) , '=' , $ this -> parent -> getPrimaryKeyValue ( ) ) -> select ( [ $ this -> getJunctionKey ( ) ] ) -> all ( ) -> pluck ( $ this -> getJunctionKey ( ) ) ; if ( ! empty ( $ diff = array_diff ( $ keys , $ existing ) ) ) { $ success = $ success && $ this -> link ( $ diff ) ; } if ( ! empty ( $ diff = array_diff ( $ existing , $ keys ) ) ) { $ success = $ success && $ this -> unlink ( $ diff ) ; } return $ success ; }
Synchronize related records .
38,213
protected function findAvailablePort ( int $ port ) : ? int { $ attempts = 0 ; while ( $ attempts ++ < static :: MAX_PORTS_TO_TRY ) { if ( ( $ socket = @ fsockopen ( 'localhost' , $ port , $ errorNumber , $ errorString , 0.1 ) ) === false ) { return $ port ; } fclose ( $ socket ) ; $ port ++ ; } return null ; }
Tries to find an avaiable port closest to the desired port .
38,214
protected function stripLocaleSegment ( array $ languages , string $ path ) : string { foreach ( $ languages as $ key => $ language ) { if ( $ path === '/' . $ key || strpos ( $ path , '/' . $ key . '/' ) === 0 ) { $ this -> language = $ language ; $ this -> languagePrefix = $ key ; $ path = '/' . ltrim ( mb_substr ( $ path , ( mb_strlen ( $ key ) + 1 ) ) , '/' ) ; break ; } } return $ path ; }
Strips the locale segment from the path .
38,215
protected function determinePath ( array $ languages ) : string { $ path = '/' ; $ server = $ this -> server -> all ( ) ; if ( isset ( $ server [ 'PATH_INFO' ] ) ) { $ path = $ server [ 'PATH_INFO' ] ; } elseif ( isset ( $ server [ 'REQUEST_URI' ] ) ) { if ( $ path = parse_url ( $ server [ 'REQUEST_URI' ] , PHP_URL_PATH ) ) { $ basePath = pathinfo ( $ server [ 'SCRIPT_NAME' ] , PATHINFO_DIRNAME ) ; if ( $ basePath !== '/' && stripos ( $ path , $ basePath ) === 0 ) { $ path = mb_substr ( $ path , mb_strlen ( $ basePath ) ) ; } if ( stripos ( $ path , '/' . $ this -> scriptName ) === 0 ) { $ path = mb_substr ( $ path , ( strlen ( $ this -> scriptName ) + 1 ) ) ; } $ path = rawurldecode ( $ path ) ; } } return $ this -> stripLocaleSegment ( $ languages , $ path ) ; }
Determines the request path .
38,216
protected function determineMethod ( ) : string { $ this -> realMethod = $ method = strtoupper ( $ this -> server -> get ( 'REQUEST_METHOD' , 'GET' ) ) ; if ( $ method === 'POST' ) { return strtoupper ( $ this -> post -> get ( 'REQUEST_METHOD_OVERRIDE' , $ this -> server -> get ( 'HTTP_X_HTTP_METHOD_OVERRIDE' , 'POST' ) ) ) ; } return $ method ; }
Determines the request method .
38,217
public function getContentType ( ) : string { if ( $ this -> contentType === null ) { $ this -> contentType = rtrim ( strtok ( ( string ) $ this -> headers -> get ( 'content-type' ) , ';' ) ) ; } return $ this -> contentType ; }
Returns the content type of the request body . An empty string will be returned if the header is missing .
38,218
public function setAttribute ( string $ name , $ value ) : void { Arr :: set ( $ this -> attributes , $ name , $ value ) ; }
Sets a request attribute .
38,219
public function getRawBody ( ) : string { if ( $ this -> rawBody === null ) { $ this -> rawBody = file_get_contents ( 'php://input' ) ; } return $ this -> rawBody ; }
Returns the raw request body .
38,220
public function getBody ( ) : Parameters { if ( $ this -> parsedBody === null ) { $ this -> parsedBody = new Body ( $ this -> getRawBody ( ) , $ this -> getContentType ( ) ) ; } return $ this -> parsedBody ; }
Returns the parsed request body .
38,221
public function getData ( ) : Parameters { if ( $ this -> realMethod === 'GET' ) { return $ this -> getQuery ( ) ; } elseif ( $ this -> realMethod === 'POST' && $ this -> hasFormData ( ) ) { return $ this -> getPost ( ) ; } return $ this -> getBody ( ) ; }
Returns the data of the current request method .
38,222
public function getIp ( ) : string { if ( $ this -> ip === null ) { $ ip = $ this -> server -> get ( 'REMOTE_ADDR' ) ; if ( ! empty ( $ this -> trustedProxies ) ) { $ ips = $ this -> server -> get ( 'HTTP_X_FORWARDED_FOR' ) ; if ( ! empty ( $ ips ) ) { $ ips = array_map ( 'trim' , explode ( ',' , $ ips ) ) ; foreach ( $ ips as $ key => $ value ) { foreach ( $ this -> trustedProxies as $ trustedProxy ) { if ( IP :: inRange ( $ value , $ trustedProxy ) ) { unset ( $ ips [ $ key ] ) ; break ; } } } $ ip = end ( $ ips ) ; } } $ this -> ip = ( filter_var ( $ ip , FILTER_VALIDATE_IP ) !== false ) ? $ ip : '127.0.0.1' ; } return $ this -> ip ; }
Returns the ip of the client that made the request .
38,223
public function getBaseURL ( ) : string { if ( $ this -> baseURL === null ) { $ protocol = $ this -> isSecure ( ) ? 'https://' : 'http://' ; if ( ( $ host = $ this -> server -> get ( 'HTTP_HOST' ) ) === null ) { $ host = $ this -> server -> get ( 'SERVER_NAME' ) ; $ port = $ this -> server -> get ( 'SERVER_PORT' ) ; if ( $ port !== null && $ port != 80 ) { $ host = $ host . ':' . $ port ; } } $ this -> baseURL = $ protocol . $ host . $ this -> getBasePath ( ) ; } return $ this -> baseURL ; }
Returns the base url of the request .
38,224
public function has ( string $ name ) : bool { return isset ( $ this -> headers [ $ this -> normalizeName ( $ name ) ] ) ; }
Returns true if the header exists and false if not .
38,225
protected function parseAcceptHeader ( ? string $ headerValue ) : array { $ groupedAccepts = [ ] ; if ( empty ( $ headerValue ) ) { return $ groupedAccepts ; } foreach ( explode ( ',' , $ headerValue ) as $ accept ) { $ quality = 1 ; if ( strpos ( $ accept , ';' ) ) { [ $ accept , $ quality ] = explode ( ';' , $ accept , 2 ) ; $ quality = substr ( trim ( $ quality ) , 2 ) ; } $ groupedAccepts [ $ quality ] [ ] = trim ( $ accept ) ; } krsort ( $ groupedAccepts ) ; return array_merge ( ... array_values ( $ groupedAccepts ) ) ; }
Parses a accpet header and returns the values in descending order of preference .
38,226
protected function calculateNewDimensions ( $ width , $ height , $ oldWidth , $ oldHeight , $ aspectRatio ) { if ( $ height === null ) { $ newWidth = round ( $ oldWidth * ( $ width / 100 ) ) ; $ newHeight = round ( $ oldHeight * ( $ width / 100 ) ) ; } else { if ( $ aspectRatio === Image :: RESIZE_AUTO ) { $ percentage = min ( ( $ width / $ oldWidth ) , ( $ height / $ oldHeight ) ) ; $ newWidth = round ( $ oldWidth * $ percentage ) ; $ newHeight = round ( $ oldHeight * $ percentage ) ; } elseif ( $ aspectRatio === Image :: RESIZE_WIDTH ) { $ newWidth = $ width ; $ newHeight = round ( $ oldHeight * ( $ width / $ oldWidth ) ) ; } elseif ( $ aspectRatio === Image :: RESIZE_HEIGHT ) { $ newWidth = round ( $ oldWidth * ( $ height / $ oldHeight ) ) ; $ newHeight = $ height ; } else { $ newWidth = $ width ; $ newHeight = $ height ; } } return [ $ newWidth , $ newHeight ] ; }
Calculates new image dimensions .
38,227
public function registerMiddleware ( string $ name , string $ middleware , ? int $ priority = null ) : Dispatcher { $ this -> middleware [ $ name ] = $ middleware ; if ( $ priority !== null ) { $ this -> middlewarePriority [ $ name ] = $ priority ; } return $ this ; }
Registers middleware .
38,228
protected function resolveMiddleware ( string $ middleware ) : array { [ $ name , $ parameters ] = $ this -> parseFunction ( $ middleware ) ; if ( ! isset ( $ this -> middleware [ $ name ] ) ) { throw new RuntimeException ( vsprintf ( 'No middleware named [ %s ] has been registered.' , [ $ middleware ] ) ) ; } return [ 'name' => $ name , 'middleware' => $ this -> middleware [ $ name ] , 'parameters' => $ parameters ] ; }
Resolves the middleware .
38,229
protected function orderMiddlewareByPriority ( array $ middleware ) : array { if ( empty ( $ this -> middlewarePriority ) ) { return $ middleware ; } $ priority = array_intersect_key ( $ this -> middlewarePriority , $ middleware ) + array_fill_keys ( array_keys ( array_diff_key ( $ middleware , $ this -> middlewarePriority ) ) , static :: MIDDLEWARE_DEFAULT_PRIORITY ) ; $ position = 0 ; foreach ( $ priority as $ key => $ value ) { $ priority [ $ key ] = [ $ position ++ , $ value ] ; } uasort ( $ priority , function ( $ a , $ b ) { return $ a [ 1 ] === $ b [ 1 ] ? ( $ a [ 0 ] > $ b [ 0 ] ? 1 : - 1 ) : ( $ a [ 1 ] > $ b [ 1 ] ? 1 : - 1 ) ; } ) ; foreach ( $ priority as $ key => $ value ) { $ priority [ $ key ] = $ value [ 1 ] ; } return array_merge ( $ priority , $ middleware ) ; }
Orders resolved middleware by priority .
38,230
protected function addMiddlewareToStack ( Onion $ onion , array $ middleware ) : void { if ( empty ( $ middleware ) === false ) { $ resolved = [ ] ; foreach ( $ middleware as $ layer ) { $ layer = $ this -> resolveMiddleware ( $ layer ) ; $ resolved [ $ layer [ 'name' ] ] [ ] = $ layer ; } foreach ( $ this -> orderMiddlewareByPriority ( $ resolved ) as $ name ) { foreach ( $ name as $ layer ) { $ onion -> addLayer ( $ layer [ 'middleware' ] , $ layer [ 'parameters' ] ) ; } } } }
Adds route middleware to the stack .
38,231
protected function executeClosure ( Closure $ closure , array $ parameters ) : Response { return $ this -> response -> setBody ( $ this -> container -> call ( $ closure , $ parameters ) ) ; }
Executes a closure action .
38,232
protected function executeController ( string $ controller , array $ parameters ) : Response { if ( strpos ( $ controller , '::' ) === false ) { $ method = '__invoke' ; } else { [ $ controller , $ method ] = explode ( '::' , $ controller , 2 ) ; } $ controller = $ this -> container -> get ( $ controller ) ; if ( method_exists ( $ controller , 'beforeAction' ) ) { $ returnValue = $ this -> container -> call ( [ $ controller , 'beforeAction' ] ) ; } if ( empty ( $ returnValue ) ) { $ this -> response -> setBody ( $ this -> container -> call ( [ $ controller , $ method ] , $ parameters ) ) ; if ( method_exists ( $ controller , 'afterAction' ) ) { $ this -> container -> call ( [ $ controller , 'afterAction' ] ) ; } } else { $ this -> response -> setBody ( $ returnValue ) ; } return $ this -> response ; }
Executes a controller action .
38,233
protected function executeAction ( Route $ route ) : Response { $ action = $ route -> getAction ( ) ; $ parameters = $ route -> getParameters ( ) ; if ( $ action instanceof Closure ) { return $ this -> executeClosure ( $ action , $ parameters ) ; } return $ this -> executeController ( $ action , $ parameters ) ; }
Executes the route action .
38,234
public function dispatch ( Route $ route ) : Response { $ onion = new Onion ( $ this -> container , null , MiddlewareInterface :: class ) ; $ this -> addMiddlewareToStack ( $ onion , array_merge ( $ this -> globalMiddleware , $ route -> getMiddleware ( ) ) ) ; return $ onion -> peel ( function ( ) use ( $ route ) { return $ this -> executeAction ( $ route ) ; } , [ $ this -> request , $ this -> response ] ) ; }
Dispatches the route and returns the response .
38,235
public function commit ( ) : void { $ this -> sessionData [ 'mako.flashdata' ] = $ this -> flashData ; if ( ! $ this -> destroyed ) { $ this -> store -> write ( $ this -> sessionId , $ this -> sessionData , $ this -> options [ 'data_ttl' ] ) ; } }
Writes data to session store .
38,236
protected function setCookie ( ) : void { if ( $ this -> options [ 'cookie_options' ] [ 'secure' ] && ! $ this -> request -> isSecure ( ) ) { throw new RuntimeException ( 'Attempted to set a secure cookie over a non-secure connection.' ) ; } $ this -> response -> getCookies ( ) -> addSigned ( $ this -> options [ 'name' ] , $ this -> sessionId , $ this -> options [ 'cookie_ttl' ] , $ this -> options [ 'cookie_options' ] ) ; }
Adds a session cookie to the response .
38,237
protected function loadData ( ) : void { $ data = $ this -> store -> read ( $ this -> sessionId ) ; $ this -> sessionData = $ data === false ? [ ] : $ data ; }
Loads the session data .
38,238
public function regenerateId ( bool $ keepOld = false ) : string { if ( ! $ keepOld ) { $ this -> store -> delete ( $ this -> sessionId ) ; } $ this -> sessionId = $ this -> generateId ( ) ; $ this -> setCookie ( ) ; return $ this -> sessionId ; }
Regenerate the session id and returns it .
38,239
public function getAndPut ( string $ key , $ value , $ default = null ) { $ storedValue = $ this -> get ( $ key , $ default ) ; $ this -> put ( $ key , $ value ) ; return $ storedValue ; }
Gets a value from the session and replaces it .
38,240
public function getAndRemove ( string $ key , $ default = null ) { $ storedValue = $ this -> get ( $ key , $ default ) ; $ this -> remove ( $ key ) ; return $ storedValue ; }
Gets a value from the session and removes it .
38,241
public function reflash ( array $ keys = [ ] ) : void { $ flashData = $ this -> sessionData [ 'mako.flashdata' ] ?? [ ] ; $ flashData = empty ( $ keys ) ? $ flashData : array_intersect_key ( $ flashData , array_flip ( $ keys ) ) ; $ this -> flashData = array_merge ( $ this -> flashData , $ flashData ) ; }
Extends the lifetime of the flash data by one request .
38,242
public function generateOneTimeToken ( ) : string { if ( ! empty ( $ this -> sessionData [ 'mako.tokens' ] ) ) { $ this -> sessionData [ 'mako.tokens' ] = array_slice ( $ this -> sessionData [ 'mako.tokens' ] , 0 , ( static :: MAX_TOKENS - 1 ) ) ; } else { $ this -> sessionData [ 'mako.tokens' ] = [ ] ; } $ token = $ this -> generateId ( ) ; array_unshift ( $ this -> sessionData [ 'mako.tokens' ] , $ token ) ; return $ token ; }
Returns random security token .
38,243
public function validateOneTimeToken ( string $ token ) : bool { if ( ! empty ( $ this -> sessionData [ 'mako.tokens' ] ) ) { foreach ( $ this -> sessionData [ 'mako.tokens' ] as $ key => $ value ) { if ( hash_equals ( $ value , $ token ) ) { unset ( $ this -> sessionData [ 'mako.tokens' ] [ $ key ] ) ; return true ; } } } return false ; }
Validates security token .
38,244
protected function redirectResponse ( string $ location , array $ routeParams = [ ] , array $ queryParams = [ ] , string $ separator = '&' , $ language = true ) : Redirect { if ( $ this -> routes -> hasNamedRoute ( $ location ) ) { $ location = $ this -> urlBuilder -> toRoute ( $ location , $ routeParams , $ queryParams , $ separator , $ language ) ; } return new Redirect ( $ location ) ; }
Returns a redirect response container .
38,245
protected function streamResponse ( Closure $ stream , ? string $ contentType = null , ? string $ charset = null ) : Stream { return new Stream ( $ stream , $ contentType , $ charset ) ; }
Returns a stream response container .
38,246
protected function jsonResponse ( $ data , int $ options = 0 , ? int $ status = null , ? string $ charset = null ) : JSON { return new JSON ( $ data , $ options , $ status , $ charset ) ; }
Returns a JSON response builder .
38,247
public function getRelated ( ) { if ( $ this -> parent -> getRawColumnValue ( $ this -> getForeignKey ( ) ) === null ) { return false ; } return $ this -> first ( ) ; }
Returns related a record from the database .
38,248
protected function getDatabaseStore ( Container $ container , array $ config , $ classWhitelist ) { return new Database ( $ container -> get ( DatabaseConnectionManager :: class ) -> connection ( $ config [ 'configuration' ] ) , $ config [ 'table' ] , $ classWhitelist ) ; }
Returns a database store instance .
38,249
protected function getFileStore ( Container $ container , array $ config , $ classWhitelist ) { return new File ( $ container -> get ( FileSystem :: class ) , $ config [ 'path' ] , $ classWhitelist ) ; }
Returns a file store instance .
38,250
protected function getRedisStore ( Container $ container , array $ config , $ classWhitelist ) { return new Redis ( $ container -> get ( RedisConnectionManager :: class ) -> connection ( $ config [ 'configuration' ] ) , $ classWhitelist ) ; }
Returns a redis store instance .
38,251
protected function getStore ( Container $ container , array $ config , $ classWhitelist ) { $ config = $ config [ 'configurations' ] [ $ config [ 'configuration' ] ] ; switch ( $ config [ 'type' ] ) { case 'database' : return $ this -> getDatabaseStore ( $ container , $ config , $ classWhitelist ) ; break ; case 'file' : return $ this -> getFileStore ( $ container , $ config , $ classWhitelist ) ; break ; case 'null' : return $ this -> getNullStore ( $ container , $ config , $ classWhitelist ) ; break ; case 'redis' : return $ this -> getRedisStore ( $ container , $ config , $ classWhitelist ) ; break ; } }
Returns a session store instance .
38,252
public function setIdentifier ( string $ identifier ) : void { if ( ! in_array ( $ identifier , [ 'email' , 'username' , 'id' ] ) ) { throw new InvalidArgumentException ( vsprintf ( 'Invalid identifier [ %s ].' , [ $ identifier ] ) ) ; } $ this -> identifier = $ identifier ; }
Sets the user identifier .
38,253
protected function setAuthorizer ( $ user ) { if ( $ user !== false && $ this -> authorizer !== null && $ user instanceof AuthorizableInterface ) { $ user -> setAuthorizer ( $ this -> authorizer ) ; } return $ user ; }
Sets the authorizer .
38,254
public function getByActionToken ( string $ token ) { return $ this -> setAuthorizer ( $ this -> getModel ( ) -> where ( 'action_token' , '=' , $ token ) -> first ( ) ) ; }
Fetches a user by its action token .
38,255
public function getByAccessToken ( string $ token ) { return $ this -> setAuthorizer ( $ this -> getModel ( ) -> where ( 'access_token' , '=' , $ token ) -> first ( ) ) ; }
Fetches a user by its access token .
38,256
public function getByEmail ( string $ email ) { return $ this -> setAuthorizer ( $ this -> getModel ( ) -> where ( 'email' , '=' , $ email ) -> first ( ) ) ; }
Fetches a user by its email address .
38,257
public function getByUsername ( string $ username ) { return $ this -> setAuthorizer ( $ this -> getModel ( ) -> where ( 'username' , '=' , $ username ) -> first ( ) ) ; }
Fetches a user by its username .
38,258
public function getById ( int $ id ) { return $ this -> setAuthorizer ( $ this -> getModel ( ) -> where ( 'id' , '=' , $ id ) -> first ( ) ) ; }
Fetches a user by its id .
38,259
public function resize ( $ width , $ height = null , $ aspectRatio = Image :: RESIZE_IGNORE ) : Image { $ this -> processor -> resize ( $ width , $ height , $ aspectRatio ) ; return $ this ; }
Resizes the image to the chosen size .
38,260
public function crop ( $ width , $ height , $ x , $ y ) : Image { $ this -> processor -> crop ( $ width , $ height , $ x , $ y ) ; return $ this ; }
Crops the image .
38,261
public function watermark ( $ file , $ position = Image :: WATERMARK_TOP_LEFT , $ opacity = 100 ) : Image { if ( file_exists ( $ file ) === false ) { throw new RuntimeException ( vsprintf ( 'The watermark image [ %s ] does not exist.' , [ $ file ] ) ) ; } $ opacity = max ( min ( ( int ) $ opacity , 100 ) , 0 ) ; $ this -> processor -> watermark ( $ file , $ position , $ opacity ) ; return $ this ; }
Adds a watermark to the image .
38,262
public function brightness ( $ level = 50 ) : Image { $ level = min ( max ( $ level , - 100 ) , 100 ) ; $ this -> processor -> brightness ( $ level ) ; return $ this ; }
Adjust image brightness .
38,263
public function border ( $ color = '#000' , $ thickness = 5 ) : Image { $ this -> processor -> border ( $ color , $ thickness ) ; return $ this ; }
Adds a border to the image .
38,264
public function getImageBlob ( $ type = null , $ quality = 95 ) { return $ this -> processor -> getImageBlob ( $ type , $ this -> normalizeImageQuality ( $ quality ) ) ; }
Returns a string containing the image .
38,265
public function save ( $ file = null , $ quality = 95 ) : void { $ file = $ file ?? $ this -> image ; if ( file_exists ( $ file ) ) { if ( ! is_writable ( $ file ) ) { throw new RuntimeException ( vsprintf ( 'The file [ %s ] isn\'t writable.' , [ $ file ] ) ) ; } } else { $ pathInfo = pathinfo ( $ file ) ; if ( ! is_writable ( $ pathInfo [ 'dirname' ] ) ) { throw new RuntimeException ( vsprintf ( 'The directory [ %s ] isn\'t writable.' , [ $ pathInfo [ 'dirname' ] ] ) ) ; } } $ this -> processor -> save ( $ file , $ this -> normalizeImageQuality ( $ quality ) ) ; }
Saves image to file .
38,266
protected function getContenType ( ) : string { return $ this -> contentType ?? ( $ this -> fileSystem -> info ( $ this -> filePath ) -> getMimeType ( ) ?? 'application/octet-stream' ) ; }
Returns the content type .
38,267
protected function calculateRange ( string $ range ) { $ range = substr ( $ range , 6 ) ; $ range = explode ( '-' , $ range , 2 ) ; if ( count ( $ range ) !== 2 ) { return false ; } $ end = $ range [ 1 ] === '' ? $ this -> fileSize - 1 : $ range [ 1 ] ; if ( $ range [ 0 ] === '' ) { $ start = $ this -> fileSize - $ end ; $ end = $ this -> fileSize - 1 ; } else { $ start = $ range [ 0 ] ; } $ start = ( int ) $ start ; $ end = ( int ) $ end ; if ( $ start > $ end || $ end + 1 > $ this -> fileSize ) { return false ; } return [ 'start' => $ start , 'end' => $ end ] ; }
Calculates the content range that should be served .
38,268
protected function parseFunction ( string $ function , ? bool $ namedParameters = null ) : array { if ( strpos ( $ function , '(' ) === false ) { return [ $ function , [ ] ] ; } $ function = $ this -> splitFunctionAndParameters ( $ function ) ; if ( $ namedParameters === null ) { $ namedParameters = preg_match ( '/^"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*"\s*:/' , $ function [ 1 ] ) === 1 ; } $ parameters = json_decode ( ( $ namedParameters ? '{' . $ function [ 1 ] . '}' : '[' . $ function [ 1 ] . ']' ) , true ) ; if ( $ parameters === null && json_last_error ( ) !== JSON_ERROR_NONE ) { throw new RuntimeException ( 'Failed to decode function parameters.' ) ; } return [ $ function [ 0 ] , $ parameters ] ; }
Parses custom function calls .
38,269
protected function buildOptionsList ( array $ options ) : string { $ output = '' ; foreach ( $ options as $ key => $ option ) { $ output .= ( $ key + 1 ) . ') ' . $ option . PHP_EOL ; } return $ output . '> ' ; }
Returns a list of options .
38,270
protected function parseHint ( $ hint ) : string { if ( is_array ( $ hint ) ) { [ $ hint , $ alias ] = $ hint ; $ this -> aliases [ $ alias ] = $ hint ; } return $ hint ; }
Parse the hint parameter .
38,271
public function register ( $ hint , $ class , bool $ singleton = false ) : void { $ this -> hints [ $ this -> parseHint ( $ hint ) ] = [ 'class' => $ class , 'singleton' => $ singleton ] ; }
Register a type hint .
38,272
public function registerInstance ( $ hint , object $ instance ) : void { $ this -> instances [ $ this -> parseHint ( $ hint ) ] = $ instance ; }
Register a singleton instance .
38,273
protected function replaceInstances ( string $ hint ) : void { if ( isset ( $ this -> replacers [ $ hint ] ) ) { $ instance = $ this -> get ( $ hint ) ; foreach ( $ this -> replacers [ $ hint ] as $ replacer ) { $ replacer ( $ instance ) ; } } }
Replaces previously resolved instances .
38,274
public function onReplace ( string $ hint , callable $ replacer , ? string $ eventName = null ) : void { $ hint = $ this -> resolveAlias ( $ hint ) ; $ eventName === null ? ( $ this -> replacers [ $ hint ] [ ] = $ replacer ) : ( $ this -> replacers [ $ hint ] [ $ eventName ] = $ replacer ) ; }
Registers replacers .
38,275
public function replace ( string $ hint , $ class , bool $ singleton = false ) : void { $ hint = $ this -> resolveAlias ( $ hint ) ; if ( ! isset ( $ this -> hints [ $ hint ] ) ) { throw new ContainerException ( vsprintf ( 'Unable to replace [ %s ] as it hasn\'t been registered.' , [ $ hint ] ) ) ; } $ this -> hints [ $ hint ] [ 'class' ] = $ class ; if ( $ singleton ) { unset ( $ this -> instances [ $ hint ] ) ; } $ this -> replaceInstances ( $ hint ) ; }
Replaces a registered type hint .
38,276
public function replaceInstance ( string $ hint , object $ instance ) : void { $ hint = $ this -> resolveAlias ( $ hint ) ; if ( ! isset ( $ this -> instances [ $ hint ] ) ) { throw new ContainerException ( vsprintf ( 'Unable to replace [ %s ] as it hasn\'t been registered.' , [ $ hint ] ) ) ; } $ this -> instances [ $ hint ] = $ instance ; $ this -> replaceInstances ( $ hint ) ; }
Replaces a singleton instance .
38,277
protected function mergeParameters ( array $ reflectionParameters , array $ providedParameters ) : array { $ associativeReflectionParameters = [ ] ; foreach ( $ reflectionParameters as $ value ) { $ associativeReflectionParameters [ $ value -> getName ( ) ] = $ value ; } $ associativeProvidedParameters = [ ] ; foreach ( $ providedParameters as $ key => $ value ) { if ( is_int ( $ key ) ) { $ associativeProvidedParameters [ $ reflectionParameters [ $ key ] -> getName ( ) ] = $ value ; } else { $ associativeProvidedParameters [ $ key ] = $ value ; } } return array_replace ( $ associativeReflectionParameters , $ associativeProvidedParameters ) ; }
Merges the provided parameters with the reflection parameters .
38,278
protected function getDeclaringFunction ( ReflectionParameter $ parameter ) : string { $ declaringFunction = $ parameter -> getDeclaringFunction ( ) ; if ( $ declaringFunction -> isClosure ( ) ) { return 'Closure' ; } if ( ( $ class = $ parameter -> getDeclaringClass ( ) ) === null ) { return $ declaringFunction -> getName ( ) ; } return $ class -> getName ( ) . '::' . $ declaringFunction -> getName ( ) ; }
Returns the name of the declaring function .
38,279
protected function resolveParameters ( array $ reflectionParameters , array $ providedParameters , ? ReflectionClass $ class = null ) : array { if ( empty ( $ reflectionParameters ) ) { return array_values ( $ providedParameters ) ; } $ parameters = $ this -> mergeParameters ( $ reflectionParameters , $ providedParameters ) ; foreach ( $ parameters as $ key => $ parameter ) { if ( $ parameter instanceof ReflectionParameter ) { $ parameters [ $ key ] = $ this -> resolveParameter ( $ parameter , $ class ) ; } } return array_values ( $ parameters ) ; }
Resolve parameters .
38,280
protected function reflectionFactory ( string $ class , array $ parameters ) : object { $ class = new ReflectionClass ( $ class ) ; if ( ! $ class -> isInstantiable ( ) ) { throw new UnableToInstantiateException ( vsprintf ( 'Unable to create a [ %s ] instance.' , [ $ class -> getName ( ) ] ) ) ; } $ constructor = $ class -> getConstructor ( ) ; if ( $ constructor === null ) { return $ class -> newInstance ( ) ; } return $ class -> newInstanceArgs ( $ this -> resolveParameters ( $ constructor -> getParameters ( ) , $ parameters , $ class ) ) ; }
Creates a class instance using reflection .
38,281
public function factory ( $ class , array $ parameters = [ ] ) : object { if ( $ class instanceof Closure ) { $ instance = $ this -> closureFactory ( $ class , $ parameters ) ; } else { $ instance = $ this -> reflectionFactory ( $ class , $ parameters ) ; } if ( $ this -> isContainerAware ( $ instance ) ) { $ instance -> setContainer ( $ this ) ; } return $ instance ; }
Creates a class instance .
38,282
public function has ( string $ class ) : bool { $ class = $ this -> resolveAlias ( $ class ) ; return ( isset ( $ this -> hints [ $ class ] ) || isset ( $ this -> instances [ $ class ] ) ) ; }
Returns true if the class is registered in the container false if not .
38,283
public function isSingleton ( string $ class ) : bool { $ class = $ this -> resolveAlias ( $ class ) ; return isset ( $ this -> instances [ $ class ] ) || ( isset ( $ this -> hints [ $ class ] ) && $ this -> hints [ $ class ] [ 'singleton' ] === true ) ; }
Returns TRUE if a class has been registered as a singleton and FALSE if not .
38,284
public function get ( string $ class , array $ parameters = [ ] , bool $ reuseInstance = true ) : object { $ class = $ this -> resolveAlias ( $ class ) ; if ( $ reuseInstance && isset ( $ this -> instances [ $ class ] ) ) { return $ this -> instances [ $ class ] ; } $ instance = $ this -> factory ( $ this -> resolveHint ( $ class ) , $ parameters ) ; if ( $ reuseInstance && isset ( $ this -> hints [ $ class ] ) && $ this -> hints [ $ class ] [ 'singleton' ] ) { $ this -> instances [ $ class ] = $ instance ; } return $ instance ; }
Returns a class instance .
38,285
public function call ( callable $ callable , array $ parameters = [ ] ) { if ( is_array ( $ callable ) ) { $ reflection = new ReflectionMethod ( $ callable [ 0 ] , $ callable [ 1 ] ) ; } else { $ reflection = new ReflectionFunction ( $ callable ) ; } return $ callable ( ... $ this -> resolveParameters ( $ reflection -> getParameters ( ) , $ parameters ) ) ; }
Execute a callable and inject its dependencies .
38,286
public function get ( $ id , array $ columns = [ ] ) { if ( ! empty ( $ columns ) ) { $ this -> select ( $ columns ) ; } return $ this -> where ( $ this -> model -> getPrimaryKey ( ) , '=' , $ id ) -> first ( ) ; }
Returns a record using the value of its primary key .
38,287
public function including ( $ includes ) { if ( $ includes === false ) { $ this -> model -> setIncludes ( [ ] ) ; } else { $ includes = ( array ) $ includes ; $ currentIncludes = $ this -> model -> getIncludes ( ) ; if ( ! empty ( $ currentIncludes ) ) { $ withCriterion = array_filter ( array_keys ( $ includes ) , 'is_string' ) ; if ( ! empty ( $ withCriterion ) ) { foreach ( $ currentIncludes as $ key => $ value ) { if ( in_array ( $ value , $ withCriterion ) ) { unset ( $ currentIncludes [ $ key ] ) ; } } } $ includes = array_merge ( $ currentIncludes , $ includes ) ; } $ this -> model -> setIncludes ( array_unique ( $ includes , SORT_REGULAR ) ) ; } return $ this ; }
Adds relations to eager load .
38,288
public function excluding ( $ excludes ) { if ( $ excludes === true ) { $ this -> model -> setIncludes ( [ ] ) ; } else { $ excludes = ( array ) $ excludes ; $ includes = $ this -> model -> getIncludes ( ) ; foreach ( $ excludes as $ key => $ relation ) { if ( is_string ( $ relation ) && isset ( $ includes [ $ relation ] ) ) { unset ( $ includes [ $ relation ] , $ excludes [ $ key ] ) ; } } $ this -> model -> setIncludes ( array_udiff ( $ includes , $ excludes , function ( $ a , $ b ) { return $ a === $ b ? 0 : - 1 ; } ) ) ; } return $ this ; }
Removes relations to eager load .
38,289
protected function hydrateModel ( array $ result ) { $ model = $ this -> model -> getClass ( ) ; return new $ model ( $ result , true , false , true ) ; }
Returns a hydrated model .
38,290
protected function parseIncludes ( ) { $ includes = [ 'this' => [ ] , 'forward' => [ ] ] ; foreach ( $ this -> model -> getIncludes ( ) as $ include => $ criteria ) { if ( is_numeric ( $ include ) ) { $ include = $ criteria ; $ criteria = null ; } if ( ( $ position = strpos ( $ include , '.' ) ) === false ) { $ includes [ 'this' ] [ $ include ] = $ criteria ; } else { if ( $ criteria === null ) { $ includes [ 'forward' ] [ substr ( $ include , 0 , $ position ) ] [ ] = substr ( $ include , $ position + 1 ) ; } else { $ includes [ 'forward' ] [ substr ( $ include , 0 , $ position ) ] [ substr ( $ include , $ position + 1 ) ] = $ criteria ; } } } return $ includes ; }
Parses includes .
38,291
protected function loadIncludes ( array $ results ) : void { $ includes = $ this -> parseIncludes ( ) ; foreach ( $ includes [ 'this' ] as $ include => $ criteria ) { $ forward = $ includes [ 'forward' ] [ $ include ] ?? [ ] ; $ results [ 0 ] -> $ include ( ) -> eagerLoad ( $ results , $ include , $ criteria , $ forward ) ; } }
Load includes .
38,292
protected function hydrateModelsAndLoadIncludes ( $ results ) { $ hydrated = [ ] ; foreach ( $ results as $ result ) { $ hydrated [ ] = $ this -> hydrateModel ( $ result ) ; } $ this -> loadIncludes ( $ hydrated ) ; return $ hydrated ; }
Returns hydrated models .
38,293
public function first ( ) { $ result = $ this -> fetchFirst ( PDO :: FETCH_ASSOC ) ; if ( $ result !== false ) { return $ this -> hydrateModelsAndLoadIncludes ( [ $ result ] ) [ 0 ] ; } return false ; }
Returns a single record from the database .
38,294
public function all ( ) { $ results = $ this -> fetchAll ( false , PDO :: FETCH_ASSOC ) ; if ( ! empty ( $ results ) ) { $ results = $ this -> hydrateModelsAndLoadIncludes ( $ results ) ; } return $ this -> createResultSet ( $ results ) ; }
Returns a result set from the database .
38,295
public function scope ( string $ scope , ... $ arguments ) { $ this -> model -> { Str :: underscored2camel ( $ scope ) . 'Scope' } ( ... array_merge ( [ $ this ] , $ arguments ) ) ; return $ this ; }
Calls a scope method on the model .
38,296
public function registerConstraint ( string $ name , string $ constraint ) : Router { $ this -> constraints [ $ name ] = $ constraint ; return $ this ; }
Registers constraint .
38,297
protected function matches ( Route $ route , string $ path ) : bool { if ( preg_match ( $ route -> getRegex ( ) , $ path , $ parameters ) > 0 ) { $ filtered = [ ] ; foreach ( $ parameters as $ key => $ value ) { if ( is_string ( $ key ) ) { $ filtered [ $ key ] = $ value ; } } $ route -> setParameters ( $ filtered ) ; return true ; } return false ; }
Returns TRUE if the route matches the request path and FALSE if not .
38,298
protected function constraintFactory ( string $ constraint ) : ConstraintInterface { [ $ constraint , $ parameters ] = $ this -> parseFunction ( $ constraint ) ; if ( ! isset ( $ this -> constraints [ $ constraint ] ) ) { throw new RuntimeException ( vsprintf ( 'No constraint named [ %s ] has been registered.' , [ $ constraint ] ) ) ; } $ constraint = $ this -> container -> get ( $ this -> constraints [ $ constraint ] , $ parameters ) ; return $ constraint ; }
Constraint factory .
38,299
protected function constraintsAreSatisfied ( Route $ route ) : bool { foreach ( array_merge ( $ this -> globalConstraints , $ route -> getConstraints ( ) ) as $ constraint ) { if ( $ this -> constraintFactory ( $ constraint ) -> isSatisfied ( ) === false ) { return false ; } } return true ; }
Returns true if all the route constraints are satisfied and false if not .