src/Graviton/AnalyticsBundle/Manager/ServiceManager.php
private function getServiceParameters(AnalyticModel $model)
    {
        $params = [];
        if (!is_array($model->getParams())) {
            return $params;
        }

        foreach ($model->getParams() as $param) {
            if (!isset($param['name'])) {
                throw new \LogicException("Incorrect spec (no name) of param in analytics route " . $model->getRoute());
            }

            $paramValue = $this->requestStack->getCurrentRequest()->query->get($param['name'], null);

            // default set?
            if (is_null($paramValue) && isset($param['default'])) {
                $paramValue = $param['default'];
            }

            // required missing?
            if (is_null($paramValue) && (isset($param['required']) && $param['required'] === true)) {
                throw new AnalyticUsageException(
                    sprintf(
                        "Missing parameter '%s' in analytics route '%s'",
                        $param['name'],
                        $model->getRoute()
                    )
                );
            }

            if (!is_null($param['type']) && !is_null($paramValue)) {
                switch ($param['type']) {
                    case "integer":
                        $paramValue = intval($paramValue);

                        // more than max? limit to max..
                        if (isset($param['max']) && is_numeric($param['max']) && intval($param['max']) < $paramValue) {
                            $paramValue = intval($param['max']);
                        }
                        break;
                    case "boolean":
                        $paramValue = boolval($paramValue);
                        break;
                    case "array":
                        $paramValue = explode(',', $paramValue);
                        break;
                    case "date":
                        $paramValue = new UTCDateTime($this->dateConverter->getDateTimeFromString($paramValue));
                        break;
                    case "regex":
                        $paramValue = new Regex($paramValue, 'i');
                        break;
                    case "mongoid":
                        $paramValue = new \MongoId($paramValue);
                        break;
                    case "array<integer>":
                        $paramValue = array_map('intval', explode(',', $paramValue));
                        break;
                    case "array<boolean>":
                        $paramValue = array_map('boolval', explode(',', $paramValue));
                        break;
                }
            }

            if (!is_null($paramValue)) {
                $params[$param['name']] = $paramValue;
            }
        }

        return $params;
    }
private function getServiceParameters(AnalyticModel $model)
    {
        $params = [];
        if (!is_array($model->getParams())) {
            return $params;
        }

        foreach ($model->getParams() as $param) {
            if (!isset($param['name'])) {
                throw new \LogicException("Incorrect spec (no name) of param in analytics route " . $model->getRoute());
            }

            $paramValue = $this->requestStack->getCurrentRequest()->query->get($param['name'], null);

            // default set?
            if (is_null($paramValue) && isset($param['default'])) {
                $paramValue = $param['default'];
            }

            // required missing?
            if (is_null($paramValue) && (isset($param['required']) && $param['required'] === true)) {
                throw new AnalyticUsageException(
                    sprintf(
                        "Missing parameter '%s' in analytics route '%s'",
                        $param['name'],
                        $model->getRoute()
                    )
                );
            }

            if (!is_null($param['type']) && !is_null($paramValue)) {
                switch ($param['type']) {
                    case "integer":
                        $paramValue = intval($paramValue);

                        // more than max? limit to max..
                        if (isset($param['max']) && is_numeric($param['max']) && intval($param['max']) < $paramValue) {
                            $paramValue = intval($param['max']);
                        }
                        break;
                    case "boolean":
                        $paramValue = boolval($paramValue);
                        break;
                    case "array":
                        $paramValue = explode(',', $paramValue);
                        break;
                    case "date":
                        $paramValue = new UTCDateTime($this->dateConverter->getDateTimeFromString($paramValue));
                        break;
                    case "regex":
                        $paramValue = new Regex($paramValue, 'i');
                        break;
                    case "mongoid":
                        $paramValue = new \MongoId($paramValue);
                        break;
                    case "array<integer>":
                        $paramValue = array_map('intval', explode(',', $paramValue));
                        break;
                    case "array<boolean>":
                        $paramValue = array_map('boolval', explode(',', $paramValue));
                        break;
                }
            }

            if (!is_null($paramValue)) {
                $params[$param['name']] = $paramValue;
            }
        }

        return $params;
    }
private function getServiceParameters ( AnalyticModel $ model ) { $ params = [ ] ; if ( ! is_array ( $ model -> getParams ( ) ) ) { return $ params ; } foreach ( $ model -> getParams ( ) as $ param ) { if ( ! isset ( $ param [ 'name' ] ) ) { throw new \ LogicException ( "Incorrect spec (no name) of param in analytics route " . $ model -> getRoute ( ) ) ; } $ paramValue = $ this -> requestStack -> getCurrentRequest ( ) -> query -> get ( $ param [ 'name' ] , null ) ; // default set? if ( is_null ( $ paramValue ) && isset ( $ param [ 'default' ] ) ) { $ paramValue = $ param [ 'default' ] ; } // required missing? if ( is_null ( $ paramValue ) && ( isset ( $ param [ 'required' ] ) && $ param [ 'required' ] === true ) ) { throw new AnalyticUsageException ( sprintf ( "Missing parameter '%s' in analytics route '%s'" , $ param [ 'name' ] , $ model -> getRoute ( ) ) ) ; } if ( ! is_null ( $ param [ 'type' ] ) && ! is_null ( $ paramValue ) ) { switch ( $ param [ 'type' ] ) { case "integer" : $ paramValue = intval ( $ paramValue ) ; // more than max? limit to max.. if ( isset ( $ param [ 'max' ] ) && is_numeric ( $ param [ 'max' ] ) && intval ( $ param [ 'max' ] ) < $ paramValue ) { $ paramValue = intval ( $ param [ 'max' ] ) ; } break ; case "boolean" : $ paramValue = boolval ( $ paramValue ) ; break ; case "array" : $ paramValue = explode ( ',' , $ paramValue ) ; break ; case "date" : $ paramValue = new UTCDateTime ( $ this -> dateConverter -> getDateTimeFromString ( $ paramValue ) ) ; break ; case "regex" : $ paramValue = new Regex ( $ paramValue , 'i' ) ; break ; case "mongoid" : $ paramValue = new \ MongoId ( $ paramValue ) ; break ; case "array<integer>" : $ paramValue = array_map ( 'intval' , explode ( ',' , $ paramValue ) ) ; break ; case "array<boolean>" : $ paramValue = array_map ( 'boolval' , explode ( ',' , $ paramValue ) ) ; break ; } } if ( ! is_null ( $ paramValue ) ) { $ params [ $ param [ 'name' ] ] = $ paramValue ; } } return $ params ; }
returns the params as passed from the user

@param AnalyticModel $model model

@return array the params, converted as specified
@throws AnalyticUsageException
returns the params as passed from the user