idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
16,400
protected function getCacheDir ( $ user , $ imageIdentifier ) { $ userPath = str_pad ( $ user , 3 , '0' , STR_PAD_LEFT ) ; return sprintf ( '%s/%s/%s/%s/%s/%s/%s/%s/%s' , $ this -> getPath ( ) , $ userPath [ 0 ] , $ userPath [ 1 ] , $ userPath [ 2 ] , $ user , $ imageIdentifier [ 0 ] , $ imageIdentifier [ 1 ] , $ image...
Get the path to the current image cache dir
16,401
protected function getCacheFilePath ( Request $ request ) { $ hash = $ this -> getCacheKey ( $ request ) ; $ dir = $ this -> getCacheDir ( $ request -> getUser ( ) , $ request -> getImageIdentifier ( ) ) ; return sprintf ( '%s/%s/%s/%s/%s' , $ dir , $ hash [ 0 ] , $ hash [ 1 ] , $ hash [ 2 ] , $ hash ) ; }
Get the absolute path to response in the cache
16,402
public function generate ( ) { $ strong = false ; $ i = 0 ; while ( ! $ strong && $ this -> maxTries > $ i ++ ) { $ data = openssl_random_pseudo_bytes ( 32 , $ strong ) ; } if ( ! $ strong ) { throw new RuntimeException ( 'Could not generate private key' ) ; } $ key = rtrim ( base64_encode ( $ data ) , '=' ) ; return s...
Generate a private key
16,403
public function addLoaders ( array $ loaders ) { foreach ( $ loaders as $ loader ) { if ( is_string ( $ loader ) ) { $ loader = new $ loader ( ) ; } if ( ! $ loader instanceof InputLoaderInterface ) { $ name = is_object ( $ loader ) ? get_class ( $ loader ) : ( string ) $ loader ; throw new InvalidArgumentException ( '...
Add a list of input loaders to the manager .
16,404
public function registerLoader ( InputLoaderInterface $ loader ) { foreach ( $ loader -> getSupportedMimeTypes ( ) as $ mime => $ extensions ) { if ( ! isset ( $ this -> loaders [ $ mime ] ) ) { $ this -> loaders [ $ mime ] = [ ] ; } if ( ! isset ( $ this -> mimeTypeToExtension [ $ mime ] ) ) { $ this -> mimeTypeToExte...
Register a specific input loader for the manager to use .
16,405
public function load ( $ mime , $ blob ) { if ( ! isset ( $ this -> loaders [ $ mime ] ) ) { return null ; } foreach ( $ this -> loaders [ $ mime ] as $ loader ) { $ result = $ loader -> load ( $ this -> imagick , $ blob , $ mime ) ; if ( $ result !== false ) { $ iccProfiles = $ this -> imagick -> getImageProfiles ( 'i...
Load a binary blob as an image .
16,406
public function autoRotate ( EventInterface $ event ) { $ event -> getTransformationManager ( ) -> getTransformation ( 'autoRotate' ) -> setImage ( $ event -> getRequest ( ) -> getImage ( ) ) -> transform ( [ ] ) ; }
Autorotate images when new images are added to Imbo
16,407
public function returnMetadata ( $ returnMetadata = null ) { if ( $ returnMetadata === null ) { return $ this -> returnMetadata ; } $ this -> returnMetadata = ( bool ) $ returnMetadata ; return $ this ; }
Set or get the returnMetadata flag
16,408
public function imageIdentifiers ( array $ imageIdentifiers = null ) { if ( $ imageIdentifiers === null ) { return $ this -> imageIdentifiers ; } $ this -> imageIdentifiers = $ imageIdentifiers ; return $ this ; }
Set or get the imageIdentifiers filter
16,409
public function sort ( array $ sort = null ) { if ( $ sort === null ) { return $ this -> sort ; } $ sortData = [ ] ; foreach ( $ sort as $ field ) { $ field = trim ( $ field ) ; $ dir = 'asc' ; if ( empty ( $ field ) ) { throw new RuntimeException ( 'Badly formatted sort' , 400 ) ; } if ( strpos ( $ field , ':' ) !== f...
Set or get the sort data
16,410
private function getPublicKeyDetails ( $ publicKey ) { if ( isset ( $ this -> publicKeys [ $ publicKey ] ) ) { return $ this -> publicKeys [ $ publicKey ] ; } $ pubkeyInfo = $ this -> getAclCollection ( ) -> findOne ( [ 'publicKey' => $ publicKey , ] ) ; if ( ! $ pubkeyInfo ) { return [ ] ; } $ data = $ this -> bsonToA...
Get details for a given public key
16,411
private function getAclCollection ( ) { if ( $ this -> aclCollection === null ) { try { $ this -> aclCollection = $ this -> getMongoClient ( ) -> selectCollection ( $ this -> params [ 'databaseName' ] , 'accesscontrol' ) ; } catch ( MongoException $ e ) { throw new DatabaseException ( 'Could not select collection' , 50...
Get the ACL mongo collection
16,412
private function getGroupsCollection ( ) { if ( $ this -> aclGroupCollection === null ) { try { $ this -> aclGroupCollection = $ this -> getMongoClient ( ) -> selectCollection ( $ this -> params [ 'databaseName' ] , 'accesscontrolgroup' ) ; } catch ( MongoException $ e ) { throw new DatabaseException ( 'Could not selec...
Get the resource groups mongo collection
16,413
protected function calculateSize ( array $ params , array $ imageSize ) { $ maxWidth = ! empty ( $ params [ 'width' ] ) ? ( int ) $ params [ 'width' ] : 0 ; $ maxHeight = ! empty ( $ params [ 'height' ] ) ? ( int ) $ params [ 'height' ] : 0 ; $ sourceWidth = $ imageSize [ 'width' ] ; $ sourceHeight = $ imageSize [ 'hei...
Calculate the output size based on the specified parameters
16,414
public function getTransformation ( $ name ) { if ( isset ( $ this -> handlers [ $ name ] ) ) { return $ this -> handlers [ $ name ] ; } else if ( ! isset ( $ this -> transformations [ $ name ] ) || ! $ this -> transformations [ $ name ] ) { return false ; } $ transformation = $ this -> transformations [ $ name ] ; if ...
Get the transformation registered for the given transformation name
16,415
public function applyTransformations ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ image = $ event -> getResponse ( ) -> getModel ( ) ; $ presets = $ event -> getConfig ( ) [ 'transformationPresets' ] ; foreach ( $ request -> getTransformations ( ) as $ transformation ) { if ( isset ( $ presets...
Apply image transformations
16,416
public function adjustImageTransformations ( EventInterface $ event ) { if ( ! $ event -> hasArgument ( 'ratio' ) ) { return ; } $ request = $ event -> getRequest ( ) ; $ transformations = $ request -> getTransformations ( ) ; $ ratio = $ event -> getArgument ( 'ratio' ) ; $ transformationIndex = $ event -> getArgument...
Adjust image transformations
16,417
protected function triggerTransformation ( $ name , array $ params , EventInterface $ event ) { $ transformation = $ this -> getTransformation ( $ name ) ; if ( ! $ transformation ) { throw new TransformationException ( 'Transformation "' . $ name . '" not registered' , 400 ) ; } $ transformation -> setImage ( $ event ...
Trigger transformation with the given name with the given parameters
16,418
private function drawPoiRectangle ( $ poi , $ color , $ borderSize , $ imageWidth , $ imageHeight ) { $ rect = new ImagickDraw ( ) ; $ rect -> setStrokeColor ( $ color ) ; $ rect -> setFillColor ( $ color ) ; $ rect -> setStrokeAntialias ( false ) ; $ x1 = max ( 0 , $ poi [ 'x' ] - $ borderSize ) ; $ x2 = min ( $ image...
Draw rectangle around a POI
16,419
private function getPoisFromMetadata ( ) { $ metadata = $ this -> event -> getDatabase ( ) -> getMetadata ( $ this -> image -> getUser ( ) , $ this -> image -> getImageIdentifier ( ) ) ; return isset ( $ metadata [ 'poi' ] ) ? $ metadata [ 'poi' ] : [ ] ; }
Fetch POIs from metadata for the image
16,420
public function populate ( EventInterface $ event ) { $ image = $ event -> getRequest ( ) -> getImage ( ) ; $ imagick = $ this -> getImagick ( ) ; $ imagick -> readImageBlob ( $ image -> getBlob ( ) ) ; $ properties = $ imagick -> getImageProperties ( ) ; foreach ( $ properties as $ key => $ value ) { unset ( $ propert...
Read exif data from incoming image
16,421
public function save ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ database = $ event -> getDatabase ( ) ; $ user = $ request -> getUser ( ) ; $ imageIdentifier = $ request -> getImage ( ) -> getImageIdentifier ( ) ; try { $ database -> updateMetadata ( $ user , $ imageIdentifier , $ this -> pr...
Save metadata to database
16,422
protected function filterProperties ( array $ properties ) { $ tags = array_fill_keys ( $ this -> allowedTags , 1 ) ; if ( empty ( $ tags ) || isset ( $ tags [ '*' ] ) ) { return $ properties ; } $ filtered = [ ] ; foreach ( $ properties as $ key => $ value ) { if ( isset ( $ tags [ $ key ] ) ) { $ filtered [ $ key ] =...
Filter out any unwanted properties
16,423
protected function parseProperties ( array $ rawProperties ) { if ( isset ( $ rawProperties [ 'exif:GPSLatitude' ] ) && isset ( $ rawProperties [ 'exif:GPSLongitude' ] ) ) { $ rawProperties [ 'gps:location' ] = [ $ this -> parseGpsCoordinate ( $ rawProperties [ 'exif:GPSLongitude' ] , $ rawProperties [ 'exif:GPSLongitu...
Parse an array of properties into a storable format
16,424
public function subscribe ( EventInterface $ event ) { $ resources = Resource :: getAllResources ( ) ; if ( $ this -> params [ 'additionalResources' ] ) { $ resources = array_merge ( $ resources , $ this -> params [ 'additionalResources' ] ) ; } $ events = [ ] ; foreach ( $ resources as $ resource ) { $ events [ $ reso...
Figure out which resources we have available and subscribe to them
16,425
public function checkAccess ( EventInterface $ event ) { if ( $ event -> hasArgument ( 'skipAccessControl' ) && $ event -> getArgument ( 'skipAccessControl' ) === true ) { return ; } $ request = $ event -> getRequest ( ) ; $ aclAdapter = $ event -> getAccessControl ( ) ; $ resource = $ event -> getName ( ) ; $ publicKe...
Check if the public key used has access to this resource for this user
16,426
public function loadGroups ( EventInterface $ event ) { $ query = new GroupQuery ( ) ; $ params = $ event -> getRequest ( ) -> query ; if ( $ params -> has ( 'page' ) ) { $ query -> page ( $ params -> get ( 'page' ) ) ; } if ( $ params -> has ( 'limit' ) ) { $ query -> limit ( $ params -> get ( 'limit' ) ) ; } $ respon...
Load groups from the configured access control adapter
16,427
public function getRules ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ publicKey = $ request -> getRoute ( ) -> get ( 'publickey' ) ; $ accessControl = $ event -> getAccessControl ( ) ; $ keyExists = $ accessControl -> publicKeyExists ( $ publicKey ) ; if ( ! $ keyExists ) { throw new RuntimeEx...
Get access rules for the specified public key
16,428
public function addRules ( EventInterface $ event ) { $ accessControl = $ event -> getAccessControl ( ) ; if ( ! ( $ accessControl instanceof MutableAdapterInterface ) ) { throw new ResourceException ( 'Access control adapter is immutable' , 405 ) ; } $ request = $ event -> getRequest ( ) ; $ publicKey = $ request -> g...
Add access rules for the specified public key
16,429
private function isStringArray ( $ values ) { if ( ! is_array ( $ values ) ) { return false ; } return array_reduce ( $ values , function ( $ res , $ value ) { return $ res && is_string ( $ value ) ; } , true ) ; }
Checks if this is an array containing only strings
16,430
private function validateRule ( EventInterface $ event , array $ rule ) { $ acl = $ event -> getAccessControl ( ) ; $ allowedProperties = [ 'resources' , 'group' , 'users' ] ; $ unknownProperties = array_diff ( array_keys ( $ rule ) , $ allowedProperties ) ; if ( ! empty ( $ unknownProperties ) ) { throw new RuntimeExc...
Validate the contents of an access rule .
16,431
public function chooseVariation ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; $ user = $ request -> getUser ( ) ; $ imageIdentifier = $ request -> getImageIdentifier ( ) ; $ transformations = $ request -> getTransformations ( ) ; if ( ! $ transformations ...
Choose an image variation based on the transformations and the original size of the image
16,432
public function deleteVariations ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ user = $ request -> getUser ( ) ; $ imageIdentifier = $ request -> getImageIdentifier ( ) ; try { $ this -> database -> deleteImageVariations ( $ user , $ imageIdentifier ) ; } catch ( DatabaseException $ e ) { trigg...
Delete all image variations attached to an image
16,433
private function configureDatabase ( array $ config ) { if ( ! isset ( $ config [ 'database' ] ) || ! isset ( $ config [ 'database' ] [ 'adapter' ] ) ) { throw new InvalidArgumentException ( 'Missing database adapter configuration for the image variations event listener' , 500 ) ; } $ config = $ config [ 'database' ] ;...
Configure the database adapter
16,434
private function configureStorage ( array $ config ) { if ( ! isset ( $ config [ 'storage' ] ) || ! isset ( $ config [ 'storage' ] [ 'adapter' ] ) ) { throw new InvalidArgumentException ( 'Missing storage adapter configuration for the image variations event listener' , 500 ) ; } $ config = $ config [ 'storage' ] ; if (...
Configure the storage adapter
16,435
private function signatureIsValid ( $ httpMethod , $ url , $ publicKey , $ privateKey , $ timestamp , $ signature ) { $ data = $ httpMethod . '|' . $ url . '|' . $ publicKey . '|' . $ timestamp ; if ( $ signature === hash_hmac ( $ this -> algorithm , $ data , $ privateKey ) ) { return true ; } return false ; }
Check if the signature is valid
16,436
private function timestampHasExpired ( $ timestamp ) { $ year = substr ( $ timestamp , 0 , 4 ) ; $ month = substr ( $ timestamp , 5 , 2 ) ; $ day = substr ( $ timestamp , 8 , 2 ) ; $ hour = substr ( $ timestamp , 11 , 2 ) ; $ minute = substr ( $ timestamp , 14 , 2 ) ; $ second = substr ( $ timestamp , 17 , 2 ) ; $ time...
Check if the timestamp has expired
16,437
public function loadUser ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; $ user = $ request -> getUser ( ) ; $ database = $ event -> getDatabase ( ) ; $ numImages = $ database -> getNumImages ( $ user ) ; $ lastModified = $ database -> getLastModified ( [ $...
Load user data
16,438
private function calculateCrop ( array $ parameters , array $ imageSize ) { $ focalX = $ parameters [ 'poi' ] [ 0 ] ; $ focalY = $ parameters [ 'poi' ] [ 1 ] ; $ sourceWidth = $ imageSize [ 'width' ] ; $ sourceHeight = $ imageSize [ 'height' ] ; $ sourceRatio = $ sourceWidth / $ sourceHeight ; $ targetWidth = $ paramet...
Calculate the coordinates and size of the crop area
16,439
private function getPoiFromMetadata ( ) { if ( $ this -> metadata === null ) { $ metadata = $ this -> event -> getDatabase ( ) -> getMetadata ( $ this -> image -> getUser ( ) , $ this -> image -> getImageIdentifier ( ) ) ; $ poi = isset ( $ metadata [ 'poi' ] [ 0 ] ) ? $ metadata [ 'poi' ] [ 0 ] : false ; if ( $ poi &&...
Fetch POI from metadata for the image
16,440
private function validateParameters ( array $ params ) { if ( empty ( $ params [ 'width' ] ) || empty ( $ params [ 'height' ] ) ) { throw new TransformationException ( 'Both width and height needs to be specified' , 400 ) ; } $ poi = empty ( $ params [ 'poi' ] ) ? null : explode ( ',' , $ params [ 'poi' ] ) ; if ( ! $ ...
Validate parameters and return a normalized parameter array
16,441
public static function buildFromParseUrlParts ( array $ parts ) { $ url = '' ; $ url .= isset ( $ parts [ 'scheme' ] ) ? $ parts [ 'scheme' ] : 'http' ; $ url .= '://' ; if ( isset ( $ parts [ 'user' ] ) ) { $ url .= $ parts [ 'user' ] ; if ( isset ( $ parts [ 'pass' ] ) ) { $ url .= ':' . $ parts [ 'pass' ] ; } $ url ...
Generate a URL from an array with similar structure as returned from parse_url .
16,442
public function createShortUrl ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ image = $ request -> getContent ( ) ; if ( empty ( $ image ) ) { throw new InvalidArgumentException ( 'Missing JSON data' , 400 ) ; } else { $ image = json_decode ( $ image , true ) ; if ( $ image === null || json_last...
Add a short URL to the database
16,443
public function deleteImageShortUrls ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ user = $ request -> getUser ( ) ; $ imageIdentifier = $ request -> getImageIdentifier ( ) ; $ event -> getDatabase ( ) -> deleteShortUrls ( $ user , $ imageIdentifier ) ; if ( $ event -> getName ( ) === 'shorturl...
Delete all short URLs for a given image
16,444
private function getShortUrlId ( $ len = 7 ) { $ chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' ; $ charsLen = 62 ; $ key = '' ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ key .= $ chars [ mt_rand ( ) % $ charsLen ] ; } return $ key ; }
Method for generating short URL keys
16,445
public function getRule ( EventInterface $ event ) { $ acl = $ event -> getAccessControl ( ) ; $ request = $ event -> getRequest ( ) ; $ publicKey = $ request -> getRoute ( ) -> get ( 'publickey' ) ; $ accessRuleId = $ request -> getRoute ( ) -> get ( 'accessRuleId' ) ; $ keyExists = $ acl -> publicKeyExists ( $ public...
Get an access control rule specified by ID
16,446
public function deleteRule ( EventInterface $ event ) { $ acl = $ event -> getAccessControl ( ) ; if ( ! ( $ acl instanceof MutableAdapterInterface ) ) { throw new ResourceException ( 'Access control adapter is immutable' , 405 ) ; } $ request = $ event -> getRequest ( ) ; $ publicKey = $ request -> getRoute ( ) -> get...
Delete the specified access control rule
16,447
public function getExpandedAclList ( array $ accessList ) { $ entries = [ ] ; foreach ( $ accessList as $ publicKey => $ privateKey ) { if ( is_array ( $ privateKey ) ) { throw new InvalidArgumentException ( 'A public key can only have a single private key (as of 2.0.0)' ) ; } $ entries [ ] = [ 'publicKey' => $ publicK...
Converts public = > private key pairs into the array format accepted by ArrayAdapter
16,448
private function isAllowed ( $ ip ) { if ( in_array ( '*' , $ this -> params [ 'allow' ] ) ) { return true ; } if ( $ this -> isIPv6 ( $ ip ) ) { $ list = array_filter ( $ this -> params [ 'allow' ] , [ $ this , 'isIPv6' ] ) ; } else { $ list = array_filter ( $ this -> params [ 'allow' ] , [ $ this , 'isIPv4' ] ) ; } f...
See if an IP address is allowed
16,449
private function cidrMatch ( $ ip , $ range ) { if ( $ this -> isIPv6 ( $ ip ) ) { return $ this -> cidr6Match ( $ ip , $ range ) ; } else { return $ this -> cidr4Match ( $ ip , $ range ) ; } }
Check if an IP address is in a subnet
16,450
private function cidr6Match ( $ ip , $ range ) { list ( $ subnet , $ mask ) = explode ( '/' , $ range ) ; $ ip = inet_pton ( $ ip ) ; $ subnet = inet_pton ( $ subnet ) ; $ mask = $ this -> getBinaryMask ( ( int ) $ mask ) ; return ( $ ip & $ mask ) === $ subnet ; }
Check an IPv6 address is in a subnet
16,451
private function getBinaryMask ( $ mask ) { $ hexMask = str_repeat ( 'f' , $ mask / 4 ) ; switch ( $ mask % 4 ) { case 1 : $ hexMask .= '8' ; break ; case 2 : $ hexMask .= 'c' ; break ; case 3 : $ hexMask .= 'e' ; break ; } $ hexMask = str_pad ( $ hexMask , 32 , '0' ) ; return hex2bin ( $ hexMask ) ; }
Fetch the binary representation of a mask
16,452
private function expandIPv6 ( $ ip ) { $ hex = strtolower ( bin2hex ( inet_pton ( $ ip ) ) ) ; return substr ( preg_replace ( '/([a-f0-9]{4})/' , '$1:' , $ hex ) , 0 , - 1 ) ; }
Expand a short IPv6
16,453
private function expandIPv6InFilters ( & $ ip ) { if ( $ this -> isIPv6 ( $ ip ) ) { if ( ( $ pos = strpos ( $ ip , '/' ) ) !== false ) { $ mask = substr ( $ ip , $ pos ) ; $ ip = $ this -> expandIPv6 ( substr ( $ ip , 0 , $ pos ) ) . $ mask ; } else { $ ip = $ this -> expandIPv6 ( $ ip ) ; } } }
Expand all IPv6 addresses in a filter
16,454
public function populateImagickInstance ( EventInterface $ event ) { $ event -> getInputLoaderManager ( ) -> setImagick ( $ this -> imagick ) ; $ event -> getOutputConverterManager ( ) -> setImagick ( $ this -> imagick ) ; }
Set the Imagick instance in the loader manager and the output converter manager
16,455
public function route ( Request $ request ) { $ httpMethod = $ request -> getMethod ( ) ; if ( $ httpMethod === 'BREW' ) { throw new RuntimeException ( 'I\'m a teapot!' , 418 ) ; } if ( ! isset ( self :: $ supportedHttpMethods [ $ httpMethod ] ) ) { throw new RuntimeException ( 'Unsupported HTTP method: ' . $ httpMetho...
Route the current request
16,456
public function subscribe ( EventInterface $ event ) { $ events = [ ] ; foreach ( $ this -> params [ 'allowedMethods' ] as $ resource => $ methods ) { foreach ( $ methods as $ method ) { $ eventName = $ resource . '.' . strtolower ( $ method ) ; $ events [ $ eventName ] = [ 'invoke' => 1000 ] ; } $ eventName = $ resour...
Subscribe to events based on configuration parameters
16,457
public function setExposedHeaders ( EventInterface $ event ) { if ( ! $ this -> requestAllowed ) { return ; } $ headers = [ 'X-Imbo-ImageIdentifier' ] ; foreach ( $ event -> getResponse ( ) -> headers as $ header => $ value ) { if ( strpos ( $ header , 'x-imbo' ) === 0 ) { $ headers [ ] = implode ( '-' , array_map ( 'u...
Right before the response is sent to the client whitelist all included Imbo - headers in the Access - Control - Expose - Headers - header
16,458
public function options ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; $ origin = $ request -> headers -> get ( 'Origin' ) ; $ response -> setStatusCode ( 204 ) ; $ event -> getResponse ( ) -> setVary ( 'Origin' , false ) ; if ( ! $ origin || ! $ this -> o...
Handle the OPTIONS requests
16,459
public function invoke ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ resource = ( string ) $ request -> getRoute ( ) ; $ method = $ request -> getMethod ( ) ; $ allowed = $ this -> params [ 'allowedMethods' ] ; if ( ! isset ( $ allowed [ $ resource ] ) || ! in_array ( $ method , $ allowed [ $ r...
Handle other requests
16,460
private function originIsAllowed ( $ origin ) { if ( in_array ( '*' , $ this -> params [ 'allowedOrigins' ] ) ) { return true ; } if ( in_array ( $ origin , $ this -> params [ 'allowedOrigins' ] ) ) { return true ; } return false ; }
Check if the given origin is defined as an allowed origin
16,461
private function checkRequiredParams ( array $ params , array $ required ) { foreach ( $ required as $ param ) { if ( ! isset ( $ params [ $ param ] ) ) { throw new TransformationException ( 'Missing required parameter: ' . $ param , 400 ) ; } } }
Check that all params are present
16,462
private function blur ( array $ params , $ adaptive = false ) { $ this -> checkRequiredParams ( $ params , [ 'radius' , 'sigma' ] ) ; $ radius = ( float ) $ params [ 'radius' ] ; $ sigma = ( float ) $ params [ 'sigma' ] ; try { if ( $ adaptive ) { $ this -> imagick -> adaptiveBlurImage ( $ radius , $ sigma ) ; } else {...
Add Gaussian or adaptive blur to the image
16,463
private function motionBlur ( array $ params ) { $ this -> checkRequiredParams ( $ params , [ 'radius' , 'sigma' , 'angle' ] ) ; $ radius = ( float ) $ params [ 'radius' ] ; $ sigma = ( float ) $ params [ 'sigma' ] ; $ angle = ( float ) $ params [ 'angle' ] ; try { $ this -> imagick -> motionBlurImage ( $ radius , $ si...
Add motion blur to the image
16,464
private function radialBlur ( array $ params ) { $ this -> checkRequiredParams ( $ params , [ 'angle' ] ) ; $ angle = ( float ) $ params [ 'angle' ] ; try { $ this -> imagick -> radialBlurImage ( $ angle ) ; } catch ( ImagickException $ e ) { throw new TransformationException ( $ e -> getMessage ( ) , 400 , $ e ) ; } $...
Add radial blur to the image
16,465
public function checkTransformationCount ( EventInterface $ event ) { $ transformations = $ event -> getRequest ( ) -> getTransformations ( ) ; if ( $ this -> transformationLimit && ( count ( $ transformations ) > $ this -> transformationLimit ) ) { throw new ResourceException ( 'Too many transformations applied to res...
Check the number of transformations in a request and generate a 403 if there s an excessive number of transformations .
16,466
public function toArray ( $ document ) { if ( $ this -> isBSONModel ( $ document ) ) { $ document = $ document -> getArrayCopy ( ) ; } else if ( ! is_array ( $ document ) ) { return $ document ; } $ result = [ ] ; foreach ( $ document as $ key => $ value ) { if ( $ this -> isBSONModel ( $ value ) ) { $ value = $ this -...
Convert to array recursively
16,467
public function addConverters ( array $ converters ) { foreach ( $ converters as $ converter ) { if ( is_string ( $ converter ) ) { $ converter = new $ converter ( ) ; } if ( ! $ converter instanceof OutputConverterInterface ) { $ name = is_object ( $ converter ) ? get_class ( $ converter ) : ( string ) $ converter ; t...
Add a list of converters to the available output converters .
16,468
public function registerConverter ( OutputConverterInterface $ converter ) { foreach ( $ converter -> getSupportedMimeTypes ( ) as $ mimeType => $ extensions ) { if ( ! is_array ( $ extensions ) ) { $ extensions = [ $ extensions ] ; } if ( ! isset ( $ this -> convertersByMimeType [ $ mimeType ] ) ) { $ this -> converte...
Register a single output converter with the manager to make it available inside Imbo .
16,469
public function getMimeTypeFromExtension ( $ extension ) { return isset ( $ this -> extensionToMimeType [ $ extension ] ) ? $ this -> extensionToMimeType [ $ extension ] : null ; }
Look up the mime type of a given extension .
16,470
public function getExtensionFromMimeType ( $ mimeType ) { return isset ( $ this -> mimeTypeToExtension [ $ mimeType ] ) ? $ this -> mimeTypeToExtension [ $ mimeType ] : null ; }
Look up the extension for a given mime type .
16,471
private function askForResources ( InputInterface $ input , OutputInterface $ output ) { $ question = new ChoiceQuestion ( 'Which resources should the public key have access to? ' , [ self :: RESOURCES_READ_ONLY , self :: RESOURCES_READ_WRITE , self :: RESOURCES_ALL , self :: RESOURCES_SPECIFIC , self :: RESOURCES_CUST...
Ask user which resources the public key should have access to
16,472
private function askForSpecificResources ( InputInterface $ input , OutputInterface $ output ) { $ resources = Resource :: getAllResources ( ) ; sort ( $ resources ) ; $ question = new ChoiceQuestion ( 'Which resources should the public key have access to? (comma-separated) ' , $ resources ) ; $ question -> setMultisel...
Ask user which specific resources the public key should have access to
16,473
private function askForCustomResources ( InputInterface $ input , OutputInterface $ output ) { $ question = new Question ( 'Which custom resources should the public key have access to?' . PHP_EOL . '(comma-separated) ' ) ; $ question -> setValidator ( function ( $ answer ) { $ resources = array_filter ( array_map ( 'tr...
Ask the user which custom resources the public key should have access to
16,474
private function askForAnotherAclRule ( InputInterface $ input , OutputInterface $ output ) { return $ this -> getHelper ( 'question' ) -> ask ( $ input , $ output , new ConfirmationQuestion ( 'Create more ACL-rules for this public key? (y/N) ' , false ) ) ; }
Ask the user if she wants to add more ACL - rules
16,475
private function getAclAdapter ( ) { $ config = $ this -> getConfig ( ) ; $ accessControl = $ config [ 'accessControl' ] ; if ( is_callable ( $ accessControl ) && ! ( $ accessControl instanceof AdapterInterface ) ) { $ accessControl = $ accessControl ( ) ; } if ( ! $ accessControl instanceof AdapterInterface ) { throw ...
Get the configured ACL adapter and ensure it is mutable
16,476
public function format ( EventInterface $ event ) { $ response = $ event -> getResponse ( ) ; $ model = $ response -> getModel ( ) ; if ( $ response -> getStatusCode ( ) === 204 || ! $ model ) { return ; } $ request = $ event -> getRequest ( ) ; if ( $ model instanceof Model \ Image ) { $ outputConverterManager = $ eve...
Response send hook
16,477
private function expandImage ( $ color , $ borderWidth , $ borderHeight ) { $ this -> imageWidth = $ this -> image -> getWidth ( ) ; $ this -> imageHeight = $ this -> image -> getHeight ( ) ; $ original = clone $ this -> imagick ; $ this -> imagick -> clear ( ) ; $ this -> imagick -> newImage ( $ this -> imageWidth + (...
Expand the image so that we can fit the width and height of the borders specified on each side than copy the original image to the center of the canvas .
16,478
public function fixIfNoneMatchHeader ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ ifNoneMatch = $ request -> headers -> get ( 'if-none-match' , false ) ; if ( $ ifNoneMatch && strlen ( $ ifNoneMatch ) > 34 ) { $ ifNoneMatch = trim ( $ ifNoneMatch , '"' ) ; $ request -> headers -> set ( 'if-non...
Clean up a possibly tainted If - None - Match request header
16,479
public function setETag ( EventInterface $ event ) { $ response = $ event -> getResponse ( ) ; $ request = $ event -> getRequest ( ) ; $ routesWithETags = [ 'user' => true , 'images' => true , 'image' => true , 'metadata' => true , 'globalshorturl' => true , ] ; $ currentRoute = ( string ) $ request -> getRoute ( ) ; i...
Set the correct ETag for the response
16,480
public function addEventHandler ( $ name , $ handler , array $ params = [ ] ) { if ( is_string ( $ handler ) ) { $ this -> eventHandlers [ $ name ] = [ 'handler' => $ handler , 'params' => $ params , ] ; } else { $ this -> eventHandlers [ $ name ] = $ handler ; } return $ this ; }
Register an event handler
16,481
public function addCallbacks ( $ name , array $ events , array $ users = [ ] ) { $ defaultPriority = 0 ; foreach ( $ events as $ event => $ callback ) { if ( ! isset ( $ this -> callbacks [ $ event ] ) ) { $ this -> callbacks [ $ event ] = new PriorityQueue ( ) ; } if ( is_string ( $ callback ) ) { $ this -> callbacks ...
Add one or more callbacks
16,482
public function getHandlerInstance ( $ name ) { if ( is_array ( $ this -> eventHandlers [ $ name ] ) ) { $ className = $ this -> eventHandlers [ $ name ] [ 'handler' ] ; $ params = $ this -> eventHandlers [ $ name ] [ 'params' ] ; $ handler = new $ className ( $ params ? : null ) ; foreach ( $ this -> initializers as $...
Get a handler instance
16,483
public function trigger ( $ eventName , array $ params = [ ] ) { $ event = clone $ this -> event ; $ event -> setName ( $ eventName ) ; foreach ( $ params as $ key => $ value ) { $ event -> setArgument ( $ key , $ value ) ; } $ user = $ event -> getRequest ( ) -> getUser ( ) ; foreach ( $ this -> getListenersForEvent (...
Trigger a given event
16,484
private function getListenersForEvent ( $ event ) { $ listeners = [ ] ; foreach ( $ this -> getEventNameParts ( $ event ) as $ name ) { if ( isset ( $ this -> callbacks [ $ name ] ) ) { foreach ( clone $ this -> callbacks [ $ name ] as $ listener ) { $ listeners [ ] = $ listener ; } } } return $ listeners ; }
Get all listeners that listens for an event including wildcard listeners
16,485
private function getEventNameParts ( $ event ) { $ parts = [ '*' ] ; $ offset = 0 ; while ( $ offset = strpos ( $ event , '.' , $ offset + 1 ) ) { $ parts [ ] = substr ( $ event , 0 , $ offset ) . '.*' ; } $ parts [ ] = $ event ; return $ parts ; }
Get all parts of an event name
16,486
private function triggersFor ( $ user = null , array $ filter = [ ] ) { if ( empty ( $ user ) || empty ( $ filter ) ) { return true ; } $ filter = array_merge ( [ 'whitelist' => [ ] , 'blacklist' => [ ] ] , $ filter ) ; $ whitelist = array_flip ( $ filter [ 'whitelist' ] ) ; $ blacklist = array_flip ( $ filter [ 'black...
Check if a listener will trigger for a given user
16,487
private function denormalizeMetadata ( array $ data ) { $ result = [ ] ; foreach ( $ data as $ key => $ value ) { $ keys = explode ( $ this -> metadataNamespaceSeparator , $ key ) ; $ tmp = & $ result ; foreach ( $ keys as $ i => $ key ) { if ( ! isset ( $ tmp [ $ key ] ) ) { $ tmp [ $ key ] = null ; } $ tmp = & $ tmp ...
De - normalize metadata
16,488
protected function getQuantumRange ( ) { if ( is_callable ( [ $ this -> imagick , 'getQuantumRange' ] ) ) { $ quantumRange = $ this -> imagick -> getQuantumRange ( ) ; } else { $ quantumRange = Imagick :: getQuantumRange ( ) ; } return $ quantumRange [ 'quantumRangeLong' ] ; }
Get the quantum range of an image
16,489
public function populate ( EventInterface $ event ) { $ image = $ event -> getRequest ( ) -> getImage ( ) ; $ this -> imagick -> readImageBlob ( $ image -> getBlob ( ) ) ; $ this -> imagick -> setImageFormat ( '8bimtext' ) ; $ data = $ this -> imagick -> getImageBlob ( ) ; preg_match_all ( '/^8BIM#2(\d{3})#(.+?)=/m' , ...
Read 8BIM data from incoming image
16,490
public function setHeaders ( EventInterface $ event ) { $ method = $ event -> getRequest ( ) -> getMethod ( ) ; if ( $ method !== 'GET' && $ method !== 'HEAD' ) { return ; } $ response = $ event -> getResponse ( ) ; $ headers = $ event -> getResponse ( ) -> headers ; if ( $ headers -> get ( 'Cache-Control' ) !== 'publi...
Right before the response is sent to the client check if any HTTP cache control headers have explicity been set for this response . If not apply the configured defaults .
16,491
protected function getClient ( ) { if ( $ this -> client === null ) { $ params = [ 'credentials' => [ 'key' => $ this -> params [ 'key' ] , 'secret' => $ this -> params [ 'secret' ] , ] , 'version' => $ this -> params [ 'version' ] , ] ; if ( $ this -> params [ 'region' ] ) { $ params [ 'region' ] = $ this -> params [ ...
Get the S3Client instance
16,492
public function getPublicKey ( ) { return ( $ this -> headers -> get ( 'X-Imbo-PublicKey' , null ) ? : $ this -> query -> get ( 'publicKey' , null ) ? : ( $ this -> route ? $ this -> route -> get ( 'user' ) : null ) ) ; }
Get the public key found in the request
16,493
public function getUsers ( ) { $ routeUser = $ this -> getUser ( ) ; $ queryUsers = $ this -> query -> get ( 'users' , [ ] ) ; if ( ! $ routeUser && ! $ queryUsers ) { return [ ] ; } elseif ( ! $ queryUsers ) { return [ $ routeUser ] ; } elseif ( ! $ routeUser ) { return $ queryUsers ; } return array_merge ( [ $ routeU...
Get users specified in the request
16,494
public function getTransformations ( ) { if ( $ this -> transformations === null ) { $ this -> transformations = [ ] ; $ transformations = $ this -> query -> get ( 't' , [ ] ) ; if ( ! is_array ( $ transformations ) ) { throw new InvalidArgumentException ( 'Transformations must be specifed as an array' , 400 ) ; } fore...
Get image transformations from the request
16,495
public function getRawUri ( ) { $ query = $ this -> server -> get ( 'QUERY_STRING' ) ; if ( ! empty ( $ query ) ) { $ query = '?' . urldecode ( $ query ) ; } return $ this -> getSchemeAndHttpHost ( ) . $ this -> getBaseUrl ( ) . $ this -> getPathInfo ( ) . $ query ; }
Get the URI without the Symfony normalization applied to the query string un - encoded
16,496
public function addHeader ( EventInterface $ event ) { $ request = $ event -> getRequest ( ) ; $ response = $ event -> getResponse ( ) ; $ user = $ request -> getUser ( ) ; $ imageIdentifier = $ response -> getModel ( ) -> getImageIdentifier ( ) ; $ response -> headers -> set ( $ this -> header , [ 'imbo;image;' . $ us...
Add the HashTwo header to the response
16,497
public function setError ( Model \ Error $ error ) { $ errorMessage = $ error -> getErrorMessage ( ) ; $ this -> headers -> add ( [ 'X-Imbo-Error-Message' => $ errorMessage , 'X-Imbo-Error-InternalCode' => $ error -> getImboErrorCode ( ) , 'X-Imbo-Error-Date' => $ error -> getDate ( ) -> format ( 'D, d M Y H:i:s' ) . '...
Set an error model and update some parts of the response object
16,498
public function getGroup ( EventInterface $ event ) { $ route = $ event -> getRequest ( ) -> getRoute ( ) ; $ groupName = $ route -> get ( 'group' ) ; $ adapter = $ event -> getAccessControl ( ) ; if ( ! $ adapter -> groupExists ( $ groupName ) ) { throw new ResourceException ( 'Resource group not found' , 404 ) ; } $ ...
Get the resources associated with a specific group
16,499
public function addGroup ( EventInterface $ event ) { $ accessControl = $ event -> getAccessControl ( ) ; if ( ! ( $ accessControl instanceof MutableAdapterInterface ) ) { throw new ResourceException ( 'Access control adapter is immutable' , 405 ) ; } $ request = $ event -> getRequest ( ) ; $ route = $ request -> getRo...
Add resources to a group