Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8512729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:21:43+00:00 2026-06-11T04:21:43+00:00

I am right now working with the Doctrine 2 stuff and landed upon the

  • 0

I am right now working with the Doctrine 2 stuff and landed upon the Doctrine modules for validations like ObjectExists.php and NoObjectExists.php.

My question is that from the original code which can be found here.

    /**
     * Constructor
     *
     * @param array $options required keys are `object_repository`, which must be an instance of
     * Doctrine\Common\Persistence\ObjectRepository, and `fields`, with either
     * a string or an array of strings representing the fields to be matched by the validator.
     * @throws \Zend\Validator\Exception\InvalidArgumentException
     */
    public function __construct(array $options)
    {
        if (!isset($options['object_repository']) || !$options['object_repository'] instanceof ObjectRepository) {
            if (!array_key_exists('object_repository', $options)) {
                $provided = 'nothing';
            } else {
                if (is_object($options['object_repository'])) {
                    $provided = get_class($options['object_repository']);
                } else {
                    $provided = getType($options['object_repository']);
                }
            }

            throw new Exception\InvalidArgumentException(sprintf(
                'Option "object_repository" is required and must be an instance of'
                    . ' Doctrine\Common\Persistence\ObjectRepository, %s given',
                $provided
            ));
        }

        $this->objectRepository = $options['object_repository'];

        if (!isset($options['fields'])) {
            throw new Exception\InvalidArgumentException(
                'Key `fields` must be provided and be a field or a list of fields to be used when searching for'
                    . ' existing instances'
            );
        }

        $this->fields = $options['fields'];
        $this->validateFields();

        parent::__construct($options);
    }

I cannot get the fact that here it is mentioned “$options required keys are object_repository, which must be an instance of Doctrine\Common\Persistence\ObjectRepository“

Since Doctrine\Common\Persistence\ObjectRepository is an interface, how should I decode that statement?

Or in other words how can I call this constructor of ObjectsExists class and pass object_repository, which must be an instance of Doctrine\Common\Persistence\ObjectRepository?

Can somebody throw some light on this, I’m getting into this stuff, so do not be harsh on my question.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:21:45+00:00Added an answer on June 11, 2026 at 4:21 am

    Since Doctrine\Common\Persistence\ObjectRepository is an interface you cannot instantiate it but you can implement it.

    class MyObjectRepository implements Doctrine\Common\Persistence\ObjectRepository
    {
        // ...
    }
    

    Now every instance of MyObjectRepository will met the object_repository requirement of ObjectsExists.

    new ObjectsExists(array(
        'object_repository' => new MyObjectRepository(),
        // ...
    ));
    

    More about instanceof:

    instanceof is used to determine whether a PHP variable is an instantiated object of a certain class.

    instanceof can also be used to determine whether a variable is an instantiated object of a class that inherits from a parent class.

    instanceof can also be used to determine whether a variable is an instantiated object of a class that implements an interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I'm working on PHP. I am using the Doctrine ORM and the
Right now I am working on one Real Estate Website, In that website I
Right now I'm working on a program that throws up a bunch of separate
Im working right now on a program that can divide, add, ect, but, im
Right now I'm working on an archive browsing application that lets users navigate through
Right now I'm working on a project that extensively uses 64bit unsigned integers in
Right now I am working on a project that issues IDs consisting of both
I'm working on an app right now that was working fine until I started
Right now I am working with a text file that happens to have all
Right now I'm working with an ASP.NET website that automatically generates images and stores

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.