Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

Commit

Permalink
Implemented DependentMappingDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
fprochazka committed Sep 11, 2014
1 parent a386d19 commit aaac049
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/Doctrine/Search/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\Search\Mapping;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Search\SearchManager;
use Doctrine\Search\Configuration;
use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
Expand Down Expand Up @@ -66,6 +67,15 @@ protected function initialize()
$this->driver = $this->config->getMetadataDriverImpl();
$this->evm = $this->sm->getEventManager();
$this->initialized = true;

$om = $this->sm->getObjectManager();
if ($this->driver instanceof DependentMappingDriver && $om instanceof ObjectManager) {
$parentMetadataFactory = $om->getMetadataFactory();
if ($parentMetadataFactory instanceof AbstractClassMetadataFactory) {
$parentMetadataFactory->initialize();
$this->driver->setParentDriver($parentMetadataFactory->getDriver());
}
}
}

/**
Expand Down
41 changes: 41 additions & 0 deletions lib/Doctrine/Search/Mapping/DependentMappingDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\Search\Mapping;

use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;



/**
* If a driver implements this interface,
* it should delegate the getAllClassNames method to the parent driver.
*
* @author Filip Procházka <[email protected]>
*/
interface DependentMappingDriver
{

/**
* @param MappingDriver $driver
* @return void
*/
public function setParentDriver(MappingDriver $driver);

}
38 changes: 37 additions & 1 deletion lib/Doctrine/Search/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
namespace Doctrine\Search\Mapping\Driver;

use Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Search\Mapping\Annotations as Search;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Search\Exception\Driver as DriverException;
use Doctrine\Search\Mapping\DependentMappingDriver;



/**
* The AnnotationDriver reads the mapping metadata from docblock annotations.
Expand All @@ -31,7 +35,7 @@
* @since 1.0
* @author Mike Lohmann <[email protected]>
*/
class AnnotationDriver extends AbstractAnnotationDriver
class AnnotationDriver extends AbstractAnnotationDriver implements DependentMappingDriver
{
/**
* {@inheritDoc}
Expand Down Expand Up @@ -59,7 +63,18 @@ class AnnotationDriver extends AbstractAnnotationDriver
'Doctrine\\Search\\Mapping\\Annotations\\SolrField',
);

/**
* @var MappingDriver
*/
private $parentDriver;

/**
* @param MappingDriver $driver
*/
public function setParentDriver(MappingDriver $driver)
{
$this->parentDriver = $driver;
}

/**
* @param string $className
Expand Down Expand Up @@ -207,4 +222,25 @@ private function addValuesToMetadata(array $reflectedClassProperties, ClassMetad

return $metadata;
}

public function getAllClassNames()
{
if ($this->classNames !== NULL) {
return $this->classNames;
}

if ($this->parentDriver === NULL) {
return parent::getAllClassNames();
}

$classes = array();
foreach ($this->parentDriver->getAllClassNames() as $className) {
if (!$this->isTransient($className)) {
$classes[] = $className;
}
}

return $this->classNames = $classes;
}

}

0 comments on commit aaac049

Please sign in to comment.