idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
48,100
private function substractOne ( Sequence $ sequence , Period $ interval ) : self { if ( $ sequence -> isEmpty ( ) ) { return $ sequence ; } $ reducer = function ( Sequence $ sequence , Period $ period ) use ( $ interval ) { $ substract = $ period -> substract ( $ interval ) ; if ( ! $ substract -> isEmpty ( ) ) { $ seq...
Substract an Interval from a Sequence .
48,101
public function getTotalTimestampInterval ( ) : float { $ retval = 0 ; foreach ( $ this -> intervals as $ interval ) { $ retval += $ interval -> getTimestampInterval ( ) ; } return $ retval ; }
Returns the sum of all instances durations as expressed in seconds .
48,102
public function some ( callable $ predicate ) : bool { foreach ( $ this -> intervals as $ offset => $ interval ) { if ( true === $ predicate ( $ interval , $ offset ) ) { return true ; } } return false ; }
Tells whether some intervals in the current instance satisfies the predicate .
48,103
public function contains ( Period $ interval , Period ... $ intervals ) : bool { $ intervals [ ] = $ interval ; foreach ( $ intervals as $ period ) { if ( false === $ this -> indexOf ( $ period ) ) { return false ; } } return true ; }
Tells whether the given interval is present in the sequence .
48,104
public function indexOf ( Period $ interval ) { foreach ( $ this -> intervals as $ offset => $ period ) { if ( $ period -> equals ( $ interval ) ) { return $ offset ; } } return false ; }
Attempts to find the first offset attached to the submitted interval .
48,105
public function get ( int $ offset ) : Period { $ period = $ this -> intervals [ $ offset ] ?? null ; if ( null !== $ period ) { return $ period ; } throw new InvalidIndex ( sprintf ( '%s is an invalid offset in the current sequence' , $ offset ) ) ; }
Returns the interval specified at a given offset .
48,106
public function unshift ( Period $ interval , Period ... $ intervals ) : void { $ this -> intervals = array_merge ( [ $ interval ] , $ intervals , $ this -> intervals ) ; }
Adds new intervals at the front of the sequence .
48,107
public function push ( Period $ interval , Period ... $ intervals ) : void { $ this -> intervals = array_merge ( $ this -> intervals , [ $ interval ] , $ intervals ) ; }
Adds new intervals at the end of the sequence .
48,108
public function insert ( int $ offset , Period $ interval , Period ... $ intervals ) : void { if ( $ offset < 0 || $ offset > count ( $ this -> intervals ) ) { throw new InvalidIndex ( sprintf ( '%s is an invalid offset in the current sequence' , $ offset ) ) ; } array_unshift ( $ intervals , $ interval ) ; array_splic...
Inserts new intervals at the specified offset of the sequence .
48,109
public function set ( int $ offset , Period $ interval ) : void { $ this -> get ( $ offset ) ; $ this -> intervals [ $ offset ] = $ interval ; }
Updates the interval at the specify offset .
48,110
public function remove ( int $ offset ) : Period { $ interval = $ this -> get ( $ offset ) ; unset ( $ this -> intervals [ $ offset ] ) ; $ this -> intervals = array_values ( $ this -> intervals ) ; return $ interval ; }
Removes an interval from the sequence at the given offset and returns it .
48,111
public function filter ( callable $ predicate ) : self { $ intervals = array_filter ( $ this -> intervals , $ predicate , ARRAY_FILTER_USE_BOTH ) ; if ( $ intervals === $ this -> intervals ) { return $ this ; } return new self ( ... $ intervals ) ; }
Filters the sequence according to the given predicate .
48,112
public function sorted ( callable $ compare ) : self { $ intervals = $ this -> intervals ; usort ( $ intervals , $ compare ) ; if ( $ intervals === $ this -> intervals ) { return $ this ; } return new self ( ... $ intervals ) ; }
Returns an instance sorted according to the given comparison callable but does not maintain index association .
48,113
public function map ( callable $ func ) : self { $ intervals = [ ] ; foreach ( $ this -> intervals as $ offset => $ interval ) { $ intervals [ $ offset ] = $ func ( $ interval , $ offset ) ; } if ( $ intervals === $ this -> intervals ) { return $ this ; } $ mapped = new self ( ) ; $ mapped -> intervals = $ intervals ; ...
Returns an instance where the given function is applied to each element in the collection . The callable MUST return a Period object and takes a Period and its associated key as argument .
48,114
public function reduce ( callable $ func , $ carry = null ) { foreach ( $ this -> intervals as $ offset => $ interval ) { $ carry = $ func ( $ carry , $ interval , $ offset ) ; } return $ carry ; }
Iteratively reduces the sequence to a single value using a callback .
48,115
public static function create ( $ datepoint ) : self { if ( $ datepoint instanceof DateTimeInterface ) { return new self ( $ datepoint -> format ( 'Y-m-d H:i:s.u' ) , $ datepoint -> getTimezone ( ) ) ; } if ( false !== ( $ timestamp = filter_var ( $ datepoint , FILTER_VALIDATE_INT ) ) ) { return new self ( '@' . $ time...
Returns a position in time expressed as a DateTimeImmutable object .
48,116
public function abuts ( Period $ interval ) : bool { return $ this -> bordersOnEnd ( $ interval ) || $ this -> bordersOnStart ( $ interval ) ; }
Tells whether the datepoint abuts the interval .
48,117
public static function create ( $ duration ) : self { if ( $ duration instanceof Period ) { $ duration = $ duration -> getDateInterval ( ) ; } if ( $ duration instanceof DateInterval ) { $ new = new self ( 'PT0S' ) ; foreach ( $ duration as $ name => $ value ) { if ( property_exists ( $ new , $ name ) ) { $ new -> $ na...
Returns a continuous portion of time between two datepoints expressed as a DateInterval object .
48,118
public function adjustedTo ( $ reference_date ) : self { if ( ! $ reference_date instanceof DateTimeImmutable ) { $ reference_date = Datepoint :: create ( $ reference_date ) ; } $ duration = self :: create ( $ reference_date -> diff ( $ reference_date -> add ( $ this ) ) ) ; if ( $ duration == $ this ) { return $ this ...
Returns a new instance with recalculate properties according to a given datepoint .
48,119
public function verifyAndDecode ( $ jwt ) { $ tks = explode ( '.' , $ jwt ) ; if ( count ( $ tks ) !== 3 ) { throw new InvalidTokenException ( 'Wrong number of segments' ) ; } try { $ head_decoded = $ this -> decodeTokenSegment ( $ tks [ 0 ] ) ; $ body_decoded = $ this -> decodeTokenSegment ( $ tks [ 1 ] ) ; } catch ( ...
Verify and decode a JWT .
48,120
public function get_authorize_link ( $ response_type , $ redirect_uri , $ connection = null , $ state = null , array $ additional_params = [ ] ) { $ additional_params [ 'response_type' ] = $ response_type ; $ additional_params [ 'redirect_uri' ] = $ redirect_uri ; $ additional_params [ 'client_id' ] = $ this -> client_...
Builds and returns the authorization URL .
48,121
public function get_samlp_link ( $ client_id = null , $ connection = '' ) { return sprintf ( 'https://%s/samlp/%s?connection=%s' , $ this -> domain , empty ( $ client_id ) ? $ this -> client_id : $ client_id , $ connection ) ; }
Build and return a SAMLP link .
48,122
public function get_samlp_metadata_link ( $ client_id = null ) { return sprintf ( 'https://%s/samlp/metadata/%s' , $ this -> domain , empty ( $ client_id ) ? $ this -> client_id : $ client_id ) ; }
Build and return a SAMLP metadata link .
48,123
public function get_wsfed_link ( $ client_id = null , array $ params = [ ] ) { return sprintf ( 'https://%s/wsfed/%s?%s' , $ this -> domain , empty ( $ client_id ) ? $ this -> client_id : $ client_id , Psr7 \ build_query ( $ params ) ) ; }
Build and return a WS - Federation link
48,124
public function get_logout_link ( $ returnTo = null , $ client_id = null , $ federated = false ) { $ params = [ ] ; if ( $ returnTo !== null ) { $ params [ 'returnTo' ] = $ returnTo ; } if ( $ client_id !== null ) { $ params [ 'client_id' ] = $ client_id ; } if ( $ federated ) { $ params [ 'federated' ] = '' ; } return...
Builds and returns a logout URL to terminate an SSO session .
48,125
public function email_passwordless_start ( $ email , $ type , array $ authParams = [ ] ) { $ data = [ 'client_id' => $ this -> client_id , 'connection' => 'email' , 'send' => $ type , 'email' => $ email , ] ; if ( ! empty ( $ authParams ) ) { $ data [ 'authParams' ] = $ authParams ; } return $ this -> apiClient -> post...
Start passwordless login process for email
48,126
public function sms_passwordless_start ( $ phone_number ) { $ data = [ 'client_id' => $ this -> client_id , 'connection' => 'sms' , 'phone_number' => $ phone_number , ] ; return $ this -> apiClient -> post ( ) -> passwordless ( ) -> start ( ) -> withHeader ( new ContentType ( 'application/json' ) ) -> withBody ( json_e...
Start passwordless login process for SMS .
48,127
public function refresh_token ( $ refresh_token , array $ options = [ ] ) { if ( empty ( $ refresh_token ) ) { throw new ApiException ( 'Refresh token cannot be blank' ) ; } if ( ! isset ( $ options [ 'client_secret' ] ) ) { $ options [ 'client_secret' ] = $ this -> client_secret ; } if ( empty ( $ options [ 'client_se...
Use a refresh token grant to get new tokens .
48,128
public function dbconnections_signup ( $ email , $ password , $ connection ) { $ data = [ 'client_id' => $ this -> client_id , 'email' => $ email , 'password' => $ password , 'connection' => $ connection , ] ; return $ this -> apiClient -> post ( ) -> dbconnections ( ) -> signup ( ) -> withHeader ( new ContentType ( 'a...
Create a new user using active authentication . This endpoint only works for database connections .
48,129
public function dbconnections_change_password ( $ email , $ connection , $ password = null ) { $ data = [ 'client_id' => $ this -> client_id , 'email' => $ email , 'connection' => $ connection , ] ; if ( $ password !== null ) { $ data [ 'password' ] = $ password ; } return $ this -> apiClient -> post ( ) -> dbconnectio...
Send a change password email . This endpoint only works for database connections .
48,130
protected function setApiClient ( ) { $ apiDomain = "https://{$this->domain}" ; $ client = new ApiClient ( [ 'domain' => $ apiDomain , 'basePath' => '/' , 'guzzleOptions' => $ this -> guzzleOptions ] ) ; $ this -> apiClient = $ client ; }
Set an ApiClient for use in this object
48,131
public function impersonate ( $ access_token , $ user_id , $ protocol , $ impersonator_id , $ client_id , array $ additionalParameters = [ ] ) { $ data = [ 'protocol' => $ protocol , 'impersonator_id' => $ impersonator_id , 'client_id' => $ client_id , 'additionalParameters' => $ additionalParameters , ] ; return $ thi...
Obtain an impersonation URL to login as another user . Impersonation functionality may be disabled by default for your tenant .
48,132
public function authorize_with_accesstoken ( $ access_token , $ connection , $ scope = 'openid' , array $ additional_params = [ ] ) { $ data = array_merge ( $ additional_params , [ 'client_id' => $ this -> client_id , 'access_token' => $ access_token , 'connection' => $ connection , 'scope' => $ scope , ] ) ; return $ ...
Authorize using an access token
48,133
public function authorize_with_ro ( $ username , $ password , $ scope = 'openid' , $ connection = null , $ id_token = null , $ device = null ) { $ data = [ 'client_id' => $ this -> client_id , 'username' => $ username , 'password' => $ password , 'scope' => $ scope , ] ; if ( $ device !== null ) { $ data [ 'device' ] =...
DEPRECATED - This endpoint is part of the legacy authentication pipeline and has been replaced in favor of the Password Grant . For more information on the latest authentication pipeline refer to Introducing OIDC Conformant Authentication .
48,134
public function get ( $ id , $ audience = null ) { $ request = $ this -> apiClient -> get ( ) -> addPath ( 'client-grants' ) ; if ( $ audience !== null ) { $ request = $ request -> withParam ( 'audience' , $ audience ) ; } return $ request -> call ( ) ; }
Get a Client Grant .
48,135
public function getSessionKeyName ( $ key ) { $ key_name = $ key ; if ( ! empty ( $ this -> session_base_name ) ) { $ key_name = $ this -> session_base_name . '_' . $ key_name ; } return $ key_name ; }
Constructs a session key name .
48,136
public function addPath ( $ name , $ argument = null ) { $ this -> path [ ] = $ name ; if ( $ argument !== null ) { $ this -> path [ ] = $ argument ; } return $ this ; }
Add a path and an optional argument to this request .
48,137
public function getParams ( ) { if ( empty ( $ this -> params ) ) { return '' ; } $ params = array_map ( function ( $ key , $ value ) { return "$key=$value" ; } , array_keys ( $ this -> params ) , $ this -> params ) ; return '?' . implode ( '&' , $ params ) ; }
Output a URL
48,138
public function generate ( array $ scopes , $ lifetime = self :: DEFAULT_LIFETIME , $ secret_encoded = true ) { $ time = time ( ) ; $ payload = [ 'iat' => $ time , 'scopes' => $ scopes , 'exp' => $ time + $ lifetime , 'aud' => $ this -> audience , ] ; $ payload [ 'jti' ] = md5 ( json_encode ( $ payload ) ) ; $ secret =...
Create the ID token .
48,139
public function exchangeCode ( ) { $ code = isset ( $ _GET [ 'code' ] ) ? $ _GET [ 'code' ] : ( isset ( $ _POST [ 'code' ] ) ? $ _POST [ 'code' ] : null ) ; if ( ! isset ( $ code ) ) { $ this -> debugInfo ( 'No code found in _GET or _POST params.' ) ; return false ; } $ this -> debugInfo ( 'Code: ' . $ code ) ; $ auth_...
Exchanges the code from the URI parameters for an access token id token and user info
48,140
public function getUser ( ) { if ( $ this -> user === null ) { $ this -> exchangeCode ( ) ; } if ( ! is_array ( $ this -> user ) ) { return null ; } return $ this -> user ; }
Requests user info to Auth0 server .
48,141
final protected function generateUrl ( $ domain_key , $ path = '/' ) { $ base_domain = self :: $ URL_MAP [ $ domain_key ] ; $ base_domain = str_replace ( '{domain}' , $ this -> domain , $ base_domain ) ; if ( $ path [ 0 ] === '/' ) { $ path = substr ( $ path , 1 ) ; } return $ base_domain . $ path ; }
Constructs an API URL .
48,142
public function method ( $ method ) { $ method = strtolower ( $ method ) ; $ builder = new RequestBuilder ( [ 'domain' => $ this -> domain , 'basePath' => $ this -> basePath , 'method' => $ method , 'guzzleOptions' => $ this -> guzzleOptions , 'returnType' => $ this -> returnType , ] ) ; $ builder -> withHeaders ( $ th...
Create a new RequestBuilder . Similar to the above but does not use a magic method .
48,143
public function setEnvProperty ( $ name , $ version ) { if ( ! isset ( $ this -> data [ 'env' ] ) || ! is_array ( $ this -> data [ 'env' ] ) ) { $ this -> data [ 'env' ] = [ ] ; } $ this -> data [ 'env' ] [ $ name ] = $ version ; }
Add an optional env property for SDK telemetry .
48,144
public static function Extend ( InformationHeaders $ headers ) { $ new_headers = new InformationHeaders ; $ old_headers = $ headers -> get ( ) ; if ( ! empty ( $ old_headers [ 'env' ] ) && is_array ( $ old_headers [ 'env' ] ) ) { $ new_headers -> setEnvironmentData ( $ old_headers [ 'env' ] ) ; } $ new_headers -> setEn...
Extend an existing InformationHeaders object . Used in dependant modules to set a new SDK name and version but keep existing PHP SDK data .
48,145
public function validate ( $ state ) { $ valid = $ this -> store -> get ( self :: STATE_NAME ) == $ state ; $ this -> store -> delete ( self :: STATE_NAME ) ; return $ valid ; }
Perform validation of the returned state with the previously generated state .
48,146
public function login ( $ state = null , $ connection = null , array $ additionalParams = [ ] ) { $ params = [ ] ; if ( $ this -> audience ) { $ params [ 'audience' ] = $ this -> audience ; } if ( $ this -> scope ) { $ params [ 'scope' ] = $ this -> scope ; } if ( $ state === null ) { $ state = $ this -> stateHandler -...
Redirect to the hosted login page for a specific client
48,147
public function exchange ( ) { $ code = $ this -> getAuthorizationCode ( ) ; if ( ! $ code ) { return false ; } $ state = $ this -> getState ( ) ; if ( ! $ this -> stateHandler -> validate ( $ state ) ) { throw new CoreException ( 'Invalid state' ) ; } if ( $ this -> user ) { throw new CoreException ( 'Can\'t initializ...
Exchange authorization code for access ID and refresh tokens
48,148
public function renewTokens ( ) { if ( ! $ this -> accessToken ) { throw new CoreException ( 'Can\'t renew the access token if there isn\'t one valid' ) ; } if ( ! $ this -> refreshToken ) { throw new CoreException ( 'Can\'t renew the access token if there isn\'t a refresh token available' ) ; } $ response = $ this -> ...
Renews the access token and ID token using an existing refresh token . Scope offline_access must be declared in order to obtain refresh token for later token renewal .
48,149
public function setUser ( array $ user ) { if ( in_array ( 'user' , $ this -> persistantMap ) ) { $ this -> store -> set ( 'user' , $ user ) ; } $ this -> user = $ user ; return $ this ; }
Set the user property to a userinfo array and if configured persist
48,150
public function setAccessToken ( $ accessToken ) { if ( in_array ( 'access_token' , $ this -> persistantMap ) ) { $ this -> store -> set ( 'access_token' , $ accessToken ) ; } $ this -> accessToken = $ accessToken ; return $ this ; }
Sets and persists the access token .
48,151
public function setIdToken ( $ idToken ) { $ jwtVerifier = new JWTVerifier ( [ 'valid_audiences' => ! empty ( $ this -> idTokenAud ) ? $ this -> idTokenAud : [ $ this -> clientId ] , 'supported_algs' => $ this -> idTokenAlg ? [ $ this -> idTokenAlg ] : [ 'HS256' , 'RS256' ] , 'authorized_iss' => $ this -> idTokenIss ? ...
Sets validates and persists the ID token .
48,152
public function setRefreshToken ( $ refreshToken ) { if ( in_array ( 'refresh_token' , $ this -> persistantMap ) ) { $ this -> store -> set ( 'refresh_token' , $ refreshToken ) ; } $ this -> refreshToken = $ refreshToken ; return $ this ; }
Sets and persists the refresh token .
48,153
protected function getAuthorizationCode ( ) { $ code = null ; if ( $ this -> responseMode === 'query' && isset ( $ _GET [ 'code' ] ) ) { $ code = $ _GET [ 'code' ] ; } else if ( $ this -> responseMode === 'form_post' && isset ( $ _POST [ 'code' ] ) ) { $ code = $ _POST [ 'code' ] ; } return $ code ; }
Get the authorization code from POST or GET depending on response_mode
48,154
protected function getState ( ) { $ state = null ; if ( $ this -> responseMode === 'query' && isset ( $ _GET [ 'state' ] ) ) { $ state = $ _GET [ 'state' ] ; } else if ( $ this -> responseMode === 'form_post' && isset ( $ _POST [ 'state' ] ) ) { $ state = $ _POST [ 'state' ] ; } return $ state ; }
Get the state from POST or GET depending on response_mode
48,155
public function logout ( ) { $ this -> deleteAllPersistentData ( ) ; $ this -> accessToken = null ; $ this -> user = null ; $ this -> idToken = null ; $ this -> refreshToken = null ; }
Delete any persistent data and clear out all stored properties
48,156
protected function convertCertToPem ( $ cert ) { $ output = '-----BEGIN CERTIFICATE-----' . PHP_EOL ; $ output .= chunk_split ( $ cert , 64 , PHP_EOL ) ; $ output .= '-----END CERTIFICATE-----' . PHP_EOL ; return $ output ; }
Convert a certificate to PEM format .
48,157
public function requestJwkX5c ( $ jwks_url , $ kid = null ) { $ cache_key = $ jwks_url . '|' . $ kid ; $ x5c = $ this -> cache -> get ( $ cache_key ) ; if ( ! is_null ( $ x5c ) ) { return $ x5c ; } $ jwks = $ this -> requestJwks ( $ jwks_url ) ; $ jwk = $ this -> findJwk ( $ jwks , $ kid ) ; if ( $ this -> subArrayHasE...
Fetch x509 cert for RS256 token decoding .
48,158
private function findJwk ( array $ jwks , $ kid = null ) { if ( $ this -> subArrayHasEmptyFirstItem ( $ jwks , 'keys' ) ) { return null ; } if ( ! $ kid ) { return $ jwks [ 'keys' ] [ 0 ] ; } foreach ( $ jwks [ 'keys' ] as $ key ) { if ( isset ( $ key [ 'kid' ] ) && $ key [ 'kid' ] === $ kid ) { return $ key ; } } retu...
Get a JWK from a JWKS using a key ID if provided .
48,159
public function fetchKeys ( $ iss ) { $ url = "{$iss}.well-known/jwks.json" ; if ( ( $ secret = $ this -> cache -> get ( $ url ) ) === null ) { $ secret = [ ] ; $ request = new RequestBuilder ( [ 'domain' => $ iss , 'basePath' => '.well-known/jwks.json' , 'method' => 'GET' , 'guzzleOptions' => $ this -> guzzleOptions ]...
Appends the default JWKS path to a token issuer to return all keys from a JWKS .
48,160
public function getRgba ( ) { $ rgba = $ this -> hexToRgb ( $ this -> hexString ) ; $ rgba [ ] = $ this -> alpha ; return $ rgba ; }
Get RGBA array
48,161
public function hexToRgb ( $ hex ) { $ hex = ltrim ( $ hex , '#' ) ; if ( strlen ( $ hex ) == 3 ) { $ r = hexdec ( substr ( $ hex , 0 , 1 ) . substr ( $ hex , 0 , 1 ) ) ; $ g = hexdec ( substr ( $ hex , 1 , 1 ) . substr ( $ hex , 1 , 1 ) ) ; $ b = hexdec ( substr ( $ hex , 2 , 1 ) . substr ( $ hex , 2 , 1 ) ) ; } else ...
Convert hex string to RGB
48,162
public function decode ( $ bytes ) { $ bytes -> setPosition ( 0 ) ; $ blocks = $ this -> decodeToBlocks ( $ bytes ) ; return $ this -> expandBlocks ( $ blocks ) ; }
Decode GIF into array of data for easy use in PHP userland .
48,163
public function apply ( & $ image , $ filter ) { if ( $ image -> isAnimated ( ) ) { return $ this ; } $ image = $ filter -> apply ( $ image ) ; return $ this ; }
Apply a filter to the image . See Filters section for a list of available filters .
48,164
public function compare ( $ image1 , $ image2 ) { if ( is_string ( $ image1 ) ) { $ image1 = Image :: createFromFile ( $ image1 ) ; $ this -> flatten ( $ image1 ) ; } if ( is_string ( $ image2 ) ) { $ image2 = Image :: createFromFile ( $ image2 ) ; $ this -> flatten ( $ image2 ) ; } $ hash = new DifferenceHash ( ) ; $ ...
Compare two images and returns a hamming distance . A value of 0 indicates a likely similar picture . A value between 1 and 10 is potentially a variation . A value greater than 10 is likely a different image .
48,165
public function draw ( & $ image , $ drawingObject ) { if ( $ image -> isAnimated ( ) ) { return $ this ; } $ image = $ drawingObject -> draw ( $ image ) ; return $ this ; }
Draw a DrawingObject on the image . See Drawing Objects section .
48,166
public function flip ( & $ image , $ mode ) { if ( $ mode === 'h' ) { $ image -> getCore ( ) -> flopImage ( ) ; } else if ( $ mode === 'v' ) { $ image -> getCore ( ) -> flipImage ( ) ; } else { throw new \ Exception ( sprintf ( 'Unsupported mode "%s"' , $ mode ) ) ; } return $ this ; }
Flip or mirrors the image .
48,167
public function isAvailable ( ) { if ( false === extension_loaded ( 'imagick' ) || false === class_exists ( 'Imagick' ) || false === class_exists ( 'ImagickDraw' ) || false === class_exists ( 'ImagickPixel' ) || false === class_exists ( 'ImagickPixelIterator' ) ) { return false ; } return true ; }
Checks if the editor is available on the current PHP install .
48,168
public function opacity ( & $ image , $ opacity ) { if ( $ image -> isAnimated ( ) ) { return $ this ; } $ opacity = ( $ opacity > 1 ) ? 1 : $ opacity ; $ opacity = ( $ opacity < 0 ) ? 0 : $ opacity ; $ image -> getCore ( ) -> setImageOpacity ( $ opacity ) ; return $ this ; }
Sets the image to the specified opacity level where 1 . 0 is fully opaque and 0 . 0 is fully transparent .
48,169
public function resize ( & $ image , $ newWidth , $ newHeight , $ mode = 'fit' ) { switch ( $ mode ) { case 'exact' : $ this -> resizeExact ( $ image , $ newWidth , $ newHeight ) ; break ; case 'fill' : $ this -> resizeFill ( $ image , $ newWidth , $ newHeight ) ; break ; case 'exactWidth' : $ this -> resizeExactWidth ...
Wrapper function for the resizeXXX family of functions . Resize image given width height and mode .
48,170
public function resizeExact ( & $ image , $ newWidth , $ newHeight ) { $ this -> _resize ( $ image , $ newWidth , $ newHeight ) ; return $ this ; }
Resize image to exact dimensions ignoring aspect ratio . Useful if you want to force exact width and height .
48,171
public function resizeExactHeight ( & $ image , $ newHeight ) { $ width = $ image -> getWidth ( ) ; $ height = $ image -> getHeight ( ) ; $ ratio = $ width / $ height ; $ resizeHeight = $ newHeight ; $ resizeWidth = $ newHeight * $ ratio ; $ this -> _resize ( $ image , $ resizeWidth , $ resizeHeight ) ; return $ this ;...
Resize image to exact height . Width is auto calculated . Useful for creating row of images with the same height .
48,172
public function resizeExactWidth ( & $ image , $ newWidth ) { $ width = $ image -> getWidth ( ) ; $ height = $ image -> getHeight ( ) ; $ ratio = $ width / $ height ; $ resizeWidth = $ newWidth ; $ resizeHeight = round ( $ newWidth / $ ratio ) ; $ this -> _resize ( $ image , $ resizeWidth , $ resizeHeight ) ; return $ ...
Resize image to exact width . Height is auto calculated . Useful for creating column of images with the same width .
48,173
public function resizeFill ( & $ image , $ newWidth , $ newHeight ) { $ width = $ image -> getWidth ( ) ; $ height = $ image -> getHeight ( ) ; $ ratio = $ width / $ height ; $ optimumWidth = $ newWidth ; $ optimumHeight = round ( $ newWidth / $ ratio ) ; if ( ( $ optimumWidth < $ newWidth ) or ( $ optimumHeight < $ ne...
Resize image to fill all the space in the given dimension . Excess parts are cropped .
48,174
public function resizeFit ( & $ image , $ newWidth , $ newHeight ) { $ width = $ image -> getWidth ( ) ; $ height = $ image -> getHeight ( ) ; $ ratio = $ width / $ height ; $ resizeWidth = $ newWidth ; $ resizeHeight = round ( $ newWidth / $ ratio ) ; if ( ( $ resizeWidth > $ newWidth ) or ( $ resizeHeight > $ newHeig...
Resize image to fit inside the given dimension . No part of the image is lost .
48,175
private function _entropy ( $ hist ) { $ entropy = 0 ; $ hist_size = array_sum ( $ hist [ 'r' ] ) + array_sum ( $ hist [ 'g' ] ) + array_sum ( $ hist [ 'b' ] ) ; foreach ( $ hist [ 'r' ] as $ p ) { $ p = $ p / $ hist_size ; $ entropy += $ p * log ( $ p , 2 ) ; } foreach ( $ hist [ 'g' ] as $ p ) { $ p = $ p / $ hist_si...
Calculate entropy based on histogram .
48,176
private function _smartCrop ( $ oldImage , $ cropW , $ cropH ) { $ image = clone $ oldImage ; $ this -> resizeFit ( $ image , 30 , 30 ) ; $ origW = $ oldImage -> getWidth ( ) ; $ origH = $ oldImage -> getHeight ( ) ; $ resizeW = $ image -> getWidth ( ) ; $ resizeH = $ image -> getHeight ( ) ; $ smallCropW = round ( ( $...
Crop based on entropy .
48,177
public static function createFromCore ( $ imagick ) { return new self ( $ imagick , '' , $ imagick -> getImageWidth ( ) , $ imagick -> getImageHeight ( ) , $ imagick -> getImageFormat ( ) ) ; }
Create an Image from an instance of Imagick .
48,178
public static function detectAvailableEditor ( $ editorList = null ) { if ( null === $ editorList ) { $ editorList = self :: $ editorList ; } foreach ( $ editorList as $ editorName ) { if ( 'Imagick' === $ editorName ) { $ editorInstance = new ImagickEditor ( ) ; } else { $ editorInstance = new GdEditor ( ) ; } if ( tr...
Detects and return the name of the first supported editor which can either be Imagick or Gd .
48,179
public static function createFilter ( $ filterName ) { $ editorName = self :: detectAvailableEditor ( ) ; $ p = func_get_args ( ) ; if ( 'Imagick' === $ editorName ) { switch ( $ filterName ) { case 'Blur' : return new ImagickBlur ( ( array_key_exists ( 1 , $ p ) ? $ p [ 1 ] : 1 ) ) ; case 'Brightness' : return new Ima...
Create a filter . Detects available editor to use .
48,180
public function blob ( $ type = 'PNG' ) { $ type = strtoupper ( $ type ) ; if ( ImageType :: GIF == $ type ) { imagegif ( $ this -> gd ) ; } else if ( ImageType :: JPEG == $ type ) { imagejpeg ( $ this -> gd ) ; } else if ( ImageType :: PNG == $ type ) { imagepng ( $ this -> gd ) ; } else if ( ImageType :: WBMP == $ ty...
Output a binary raw dump of an image in a specified format .
48,181
public static function createFromFile ( $ imageFile ) { if ( ! file_exists ( $ imageFile ) ) { throw new \ Exception ( sprintf ( 'Could not open "%s". File does not exist.' , $ imageFile ) ) ; } $ type = self :: _guessType ( $ imageFile ) ; if ( ImageType :: GIF == $ type ) { return self :: _createGif ( $ imageFile ) ;...
Create Image from image file .
48,182
public static function createFromCore ( $ gd ) { return new self ( $ gd , '' , imagesx ( $ gd ) , imagesy ( $ gd ) , ImageType :: UNKNOWN ) ; }
Create an Image from a GD resource . The file type defaults to unknown .
48,183
private static function _createGif ( $ imageFile ) { $ gift = new GifHelper ( ) ; $ bytes = $ gift -> open ( $ imageFile ) ; $ animated = $ gift -> isAnimated ( $ bytes ) ; $ blocks = '' ; if ( $ animated ) { $ blocks = $ gift -> decode ( $ bytes ) ; } $ gd = @ imagecreatefromgif ( $ imageFile ) ; if ( ! $ gd ) { throw...
Load a GIF image .
48,184
private static function _createJpeg ( $ imageFile ) { $ gd = @ imagecreatefromjpeg ( $ imageFile ) ; if ( ! $ gd ) { throw new \ Exception ( sprintf ( 'Could not open "%s". Not a valid %s file.' , $ imageFile , ImageType :: JPEG ) ) ; } return new self ( $ gd , $ imageFile , imagesx ( $ gd ) , imagesy ( $ gd ) , ImageT...
Load a JPEG image .
48,185
private static function _createPng ( $ imageFile ) { $ gd = @ imagecreatefrompng ( $ imageFile ) ; if ( ! $ gd ) { throw new \ Exception ( sprintf ( 'Could not open "%s". Not a valid %s file.' , $ imageFile , ImageType :: PNG ) ) ; } $ image = new self ( $ gd , $ imageFile , imagesx ( $ gd ) , imagesy ( $ gd ) , ImageT...
Load a PNG image .
48,186
private static function _createWbmp ( $ imageFile ) { $ gd = @ imagecreatefromwbmp ( $ imageFile ) ; if ( ! $ gd ) { throw new \ Exception ( sprintf ( 'Could not open "%s". Not a valid %s file.' , $ imageFile , ImageType :: WBMP ) ) ; } return new self ( $ gd , $ imageFile , imagesx ( $ gd ) , imagesy ( $ gd ) , ImageT...
Load a WBMP image .
48,187
private function _getImageTypeFromFileName ( $ imageFile ) { $ ext = strtolower ( ( string ) pathinfo ( $ imageFile , PATHINFO_EXTENSION ) ) ; if ( 'jpg' === $ ext or 'jpeg' === $ ext ) { return ImageType :: JPEG ; } else if ( 'gif' === $ ext ) { return ImageType :: GIF ; } else if ( 'png' === $ ext ) { return ImageTyp...
Get image type base on file extension .
48,188
public function hash ( $ image , $ editor ) { $ width = 8 ; $ height = 8 ; $ image = clone $ image ; $ editor -> resizeExact ( $ image , $ width , $ height ) ; $ gd = $ image -> getCore ( ) ; $ pixels = array ( ) ; for ( $ y = 0 ; $ y < $ height ; $ y ++ ) { for ( $ x = 0 ; $ x < $ width ; $ x ++ ) { $ rgba = imagecolo...
Generate and get the average hash of the image .
48,189
public function getXY ( $ canvasWidth , $ canvasHeight , $ imageWidth , $ imageHeight ) { if ( self :: TOP_LEFT === $ this -> position ) { $ x = 0 ; $ y = 0 ; } else if ( self :: TOP_CENTER === $ this -> position ) { $ x = ( int ) round ( ( $ canvasWidth / 2 ) - ( $ imageWidth / 2 ) ) ; $ y = 0 ; } else if ( self :: TO...
Translate the textual position + offsets into x y values .
48,190
public static function isTemporalType ( $ type ) { return in_array ( $ type , [ self :: DATE , self :: TIME , self :: TIMESTAMP , self :: BU_DATE , self :: BU_TIMESTAMP , ] ) ; }
Returns whether or not the given type is a temporal type .
48,191
public static function isTextType ( $ mappingType ) { return in_array ( $ mappingType , [ self :: CHAR , self :: VARCHAR , self :: LONGVARCHAR , self :: CLOB , self :: DATE , self :: TIME , self :: TIMESTAMP , self :: BU_DATE , self :: BU_TIMESTAMP , self :: JSON , ] ) ; }
Returns whether or not the given type is a text type .
48,192
public static function isNumericType ( $ mappingType ) { return in_array ( $ mappingType , [ self :: SMALLINT , self :: TINYINT , self :: INTEGER , self :: BIGINT , self :: FLOAT , self :: DOUBLE , self :: NUMERIC , self :: DECIMAL , self :: REAL , ] ) ; }
Returns whether or not the given type is a numeric type .
48,193
public function getParentClass ( ) { $ parentClass = $ this -> getBehaviorContent ( 'parentClass' ) ; return null === $ parentClass ? ( $ this -> getTable ( ) -> getBaseQueryClass ( ) != "" ? $ this -> getTable ( ) -> getBaseQueryClass ( ) : 'ModelCriteria' ) : $ parentClass ; }
Returns parent class name that extends TableQuery Object if is set this class must extends ModelCriteria for be compatible
48,194
protected function isDeleteCascadeEmulationNeeded ( ) { $ table = $ this -> getTable ( ) ; if ( ( ! $ this -> getPlatform ( ) -> supportsNativeDeleteTrigger ( ) || $ this -> getBuildProperty ( 'generator.objectModel.emulateForeignKeyConstraints' ) ) && count ( $ table -> getReferrers ( ) ) > 0 ) { foreach ( $ table -> ...
Whether the platform in use requires ON DELETE CASCADE emulation and whether there are references to this table .
48,195
protected function isDeleteSetNullEmulationNeeded ( ) { $ table = $ this -> getTable ( ) ; if ( ( ! $ this -> getPlatform ( ) -> supportsNativeDeleteTrigger ( ) || $ this -> getBuildProperty ( 'generator.objectModel.emulateForeignKeyConstraints' ) ) && count ( $ table -> getReferrers ( ) ) > 0 ) { foreach ( $ table -> ...
Whether the platform in use requires ON DELETE SETNULL emulation and whether there are references to this table .
48,196
protected function addConstructor ( & $ script ) { $ this -> addConstructorComment ( $ script ) ; $ this -> addConstructorOpen ( $ script ) ; $ this -> addConstructorBody ( $ script ) ; $ this -> addConstructorClose ( $ script ) ; }
Adds the constructor for this object .
48,197
protected function addConstructorOpen ( & $ script ) { $ table = $ this -> getTable ( ) ; $ script .= " public function __construct(\$dbName = '" . $ table -> getDatabase ( ) -> getName ( ) . "', \$modelName = '" . addslashes ( $ this -> getNewStubObjectBuilder ( $ table ) -> getFullyQualifiedClassName ( ) ) . "', \...
Adds the function declaration for the constructor
48,198
public function getSequenceName ( Table $ table ) { $ result = null ; if ( $ table -> getIdMethod ( ) == IdMethod :: NATIVE ) { $ idMethodParams = $ table -> getIdMethodParameters ( ) ; if ( empty ( $ idMethodParams ) ) { $ result = null ; foreach ( $ table -> getColumns ( ) as $ col ) { if ( $ col -> isAutoIncrement (...
Override to provide sequence names that conform to postgres standard when no id - method - parameter specified .
48,199
private function getBehaviorLocator ( ) { if ( null === $ this -> behaviorLocator ) { $ config = $ this -> getGeneratorConfig ( ) ; if ( null !== $ config ) { $ this -> behaviorLocator = $ config -> getBehaviorLocator ( ) ; if ( null === $ this -> behaviorLocator ) { $ this -> behaviorLocator = new BehaviorLocator ( ) ...
Returns the behavior locator .