निर्देशिका द्वारा फिक्स्चर को तोड़ने का एक विकल्प कस्टम फ़िक्स्चर क्लास का उपयोग करना है। आपका स्थिरता कक्षाएं तो इस वर्ग का विस्तार करने और वातावरण यह वास्तव में लोड किया जाएगा निर्दिष्ट करना होगा
<?php
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Provides support for environment specific fixtures.
*
* This container aware, abstract data fixture is used to only allow loading in
* specific environments. The environments the data fixture will be loaded in is
* determined by the list of environment names returned by `getEnvironments()`.
*
* > The fixture will still be shown as having been loaded by the Doctrine
* > command, `doctrine:fixtures:load`, despite not having been actually
* > loaded.
*
* @author Kevin Herrera <[email protected]>
*/
abstract class AbstractDataFixture implements ContainerAwareInterface, FixtureInterface
{
/**
* The dependency injection container.
*
* @var ContainerInterface
*/
protected $container;
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
/** @var KernelInterface $kernel */
$kernel = $this->container->get('kernel');
if (in_array($kernel->getEnvironment(), $this->getEnvironments())) {
$this->doLoad($manager);
}
}
/**
* {@inheritDoc}
*/
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* Performs the actual fixtures loading.
*
* @see \Doctrine\Common\DataFixtures\FixtureInterface::load()
*
* @param ObjectManager $manager The object manager.
*/
abstract protected function doLoad(ObjectManager $manager);
/**
* Returns the environments the fixtures may be loaded in.
*
* @return array The name of the environments.
*/
abstract protected function getEnvironments();
}
आपका जुड़नार इस तरह लग रही अंत होगा:।
<?php
namespace Vendor\Bundle\ExampleBundle\DataFixtures\ORM;
use AbstractDataFixture;
use Doctrine\Common\Persistence\ObjectManager;
/**
* Loads data only on "prod".
*/
class ExampleData extends AbstractDataFixture
{
/**
* @override
*/
protected function doLoad(ObjectManager $manager)
{
// ... snip ...
}
/**
* @override
*/
protected function getEnvironments()
{
return array('prod');
}
}
मुझे विश्वास है कि यह दोनों के साथ काम करना चाहिए ओआरएम एक ओडीएम डेटा फिक्स्चर।
स्रोत
2014-01-16 18:14:38
यह प्रतिभाशाली है! – ferdynator
आप पर्यावरण को कंसोल से कैसे परिभाषित करते हैं? 'Php ऐप/कंसोल स्थिरता का उपयोग करना: लोड --env = prod'? – xDaizu
खुद का जवाब: यश, 'php ऐप/कंसोल स्थिरता: लोड --env = prod' जो प्रदत्त समाधान के साथ काम करता है :) – xDaizu