Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weierophinney opened this issue Dec 31, 2019 · 1 comment

Comments

@weierophinney
Copy link
Contributor

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

@ruzann
Copy link
Contributor

ruzann commented Apr 17, 2023

@weierophinney do you have any updates regarding this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants