Imbo\Http\Request\Request::getTransformations PHP Method

getTransformations() public method

Get image transformations from the request
public getTransformations ( ) : array
return array
    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);
            }
            foreach ($transformations as $transformation) {
                if (!is_string($transformation)) {
                    throw new InvalidArgumentException('Invalid transformation', 400);
                }
                // See if the transformation has any parameters
                $pos = strpos($transformation, ':');
                $urlParams = '';
                if ($pos === false) {
                    // No params exist
                    $name = $transformation;
                } else {
                    list($name, $urlParams) = explode(':', $transformation, 2);
                }
                // Initialize params for the transformation
                $params = [];
                // Loop through the parameter string and assign params to an array
                $offset = 0;
                $pattern = '#(\\w+)=(?:(.+?),\\w+=|(.+?$))#';
                while (preg_match($pattern, $urlParams, $matches, PREG_OFFSET_CAPTURE, $offset)) {
                    $offset = $matches[2][1];
                    $paramName = $matches[1][0];
                    $paramValue = isset($matches[3]) ? $matches[3][0] : $matches[2][0];
                    $params[$paramName] = $paramValue;
                }
                $this->transformations[] = ['name' => $name, 'params' => $params];
            }
        }
        return $this->transformations;
    }

Usage Example

Example #1
0
 /**
  * @expectedException Imbo\Exception\InvalidArgumentException
  * @expectedExceptionMessage Invalid transformation
  * @expectedExceptionCode 400
  * @covers Imbo\Http\Request\Request::getTransformations
  */
 public function testDoesNotGenerateWarningWhenTransformationIsNotAString()
 {
     $query = ['t' => [['flipHorizontally', 'flipVertically']]];
     $request = new Request($query);
     $request->getTransformations();
 }
All Usage Examples Of Imbo\Http\Request\Request::getTransformations