public function validate($value, Constraint $constraint)
    {
        if (!$value) {
            return;
        }

        $fileHistory = $this->em->getRepository('JbFileUploaderBundle:FileHistory')->find($value);
        if (!$fileHistory) {
            return;
        }

        // No userid associated with file. Every one can use it.
        if (!$fileHistory->getUserId()) {
            return;
        }

        // No token. Violation as there is a user id associate with file.
        $token = $this->tokenStorage->getToken();
        if (!$token) {
            return $this->createViolation($value, $constraint);
        }

        // No user. Violation as there is a user id associate with file.
        $user = $token->getUser();
        if (!$user) {
            return $this->createViolation($value, $constraint);
        }

        if ($user->getId() !== $fileHistory->getUserId()) {
            return $this->createViolation($value, $constraint);
        }

        return;
    }
public function validate($value, Constraint $constraint)
    {
        if (!$value) {
            return;
        }

        $fileHistory = $this->em->getRepository('JbFileUploaderBundle:FileHistory')->find($value);
        if (!$fileHistory) {
            return;
        }

        // No userid associated with file. Every one can use it.
        if (!$fileHistory->getUserId()) {
            return;
        }

        // No token. Violation as there is a user id associate with file.
        $token = $this->tokenStorage->getToken();
        if (!$token) {
            return $this->createViolation($value, $constraint);
        }

        // No user. Violation as there is a user id associate with file.
        $user = $token->getUser();
        if (!$user) {
            return $this->createViolation($value, $constraint);
        }

        if ($user->getId() !== $fileHistory->getUserId()) {
            return $this->createViolation($value, $constraint);
        }

        return;
    }
public function validate ( $ value , Constraint $ constraint ) { if ( ! $ value ) { return ; } $ fileHistory = $ this -> em -> getRepository ( 'JbFileUploaderBundle:FileHistory' ) -> find ( $ value ) ; if ( ! $ fileHistory ) { return ; } // No userid associated with file. Every one can use it. if ( ! $ fileHistory -> getUserId ( ) ) { return ; } // No token. Violation as there is a user id associate with file. $ token = $ this -> tokenStorage -> getToken ( ) ; if ( ! $ token ) { return $ this -> createViolation ( $ value , $ constraint ) ; } // No user. Violation as there is a user id associate with file. $ user = $ token -> getUser ( ) ; if ( ! $ user ) { return $ this -> createViolation ( $ value , $ constraint ) ; } if ( $ user -> getId ( ) !== $ fileHistory -> getUserId ( ) ) { return $ this -> createViolation ( $ value , $ constraint ) ; } return ; }
Validate that the submitted file is owned by the authenticated user

@param string $value
@param Constraint $constraint
Validate that the submitted file is owned by the authenticated user