Skip to content

Some non corresponding between 'zf-content-validation' and 'zf-rest' #1

@weierophinney

Description

@weierophinney

There is a some non corresponding between 'zf-content-validation' and 'zf-rest'.
In PUT request when sent router identifier as query parameter zf-content-validation understood as entity because in ContentValidationListener.php isCollection() there is also check return (null === $request->getQuery($identifierName, null)); on line 547.

/**
     * Does the request represent a collection?
     *
     * @param string $serviceName
     * @param array $data
     * @param RouteMatch|V2RouteMatch $matches
     * @param HttpRequest $request
     * @return bool
     */
    protected function isCollection($serviceName, $data, $matches, HttpRequest $request)
    {
        if (! array_key_exists($serviceName, $this->restControllers)) {
            return false;
        }
        if ($request->isPost() && (empty($data) || ArrayUtils::isHashTable($data))) {
            return false;
        }
        $identifierName = $this->restControllers[$serviceName];
        if ($matches->getParam($identifierName) !== null) {
            return false;
        }
        return (null === $request->getQuery($identifierName, null));
    }

and run validation for entity, but in Resource called collectin method replaceList() and not update(), because in RestController.php getIdentifier() check router identifier only in param and not query.

/**
     * Retrieve the identifier, if any
     *
     * Attempts to see if an identifier was passed in the URI,
     * returning it if found. Otherwise, returns a boolean false.
     *
     * @param  \Zend\Mvc\Router\RouteMatch $routeMatch
     * @param  \Zend\Http\Request $request
     * @return false|mixed
     */
    protected function getIdentifier($routeMatch, $request)
    {
        $identifier = $this->getIdentifierName();
        $id = $routeMatch->getParam($identifier, false);
        if ($id !== null) {
            return $id;
        }
        return false;
    }

Same non corresponding also in GET, DELETE and PATCH requests.


Originally posted by @ruzann at zfcampus/zf-content-validation#107

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions