本文整理汇总了PHP中Symfony\Bridge\Doctrine\RegistryInterface::getAliasNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP RegistryInterface::getAliasNamespace方法的具体用法?PHP RegistryInterface::getAliasNamespace怎么用?PHP RegistryInterface::getAliasNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Bridge\Doctrine\RegistryInterface
的用法示例。
在下文中一共展示了RegistryInterface::getAliasNamespace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateEntity
/**
* Generate the entity PHP code.
*
* @param BundleInterface $bundle
* @param string $name
* @param array $fields
* @param string $namePrefix
* @param string $dbPrefix
* @param string|null $extendClass
*
* @return array
* @throws \RuntimeException
*/
protected function generateEntity(BundleInterface $bundle, $name, $fields, $namePrefix, $dbPrefix, $extendClass = null)
{
// configure the bundle (needed if the bundle does not contain any Entities yet)
$config = $this->registry->getManager(null)->getConfiguration();
$config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity\\' . $namePrefix), $config->getEntityNamespaces()));
$entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $namePrefix . '\\' . $name;
$entityPath = $bundle->getPath() . '/Entity/' . $namePrefix . '/' . str_replace('\\', '/', $name) . '.php';
if (file_exists($entityPath)) {
throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
}
$class = new ClassMetadataInfo($entityClass, new UnderscoreNamingStrategy());
foreach ($fields as $fieldSet) {
foreach ($fieldSet as $fieldArray) {
foreach ($fieldArray as $field) {
if (array_key_exists('joinColumn', $field)) {
$class->mapManyToOne($field);
} elseif (array_key_exists('joinTable', $field)) {
$class->mapManyToMany($field);
} else {
$class->mapField($field);
}
}
}
}
$class->setPrimaryTable(array('name' => strtolower($dbPrefix . strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $name))) . 's'));
$entityCode = $this->getEntityGenerator($extendClass)->generateEntityClass($class);
return array($entityCode, $entityPath);
}
示例2: generate
/**
* Generate Fixture from bundle name, entity name, fixture name and ids
*
* @param BundleInterface $bundle
* @param string $entity
* @param string $name
* @param array $ids
* @param string|null $connectionName
*/
public function generate(BundleInterface $bundle, $entity, $name, array $ids, $order, $connectionName = null)
{
// configure the bundle (needed if the bundle does not contain any Entities yet)
$config = $this->registry->getManager($connectionName)->getConfiguration();
$config->setEntityNamespaces(array_merge(array($bundle->getName() => $bundle->getNamespace() . '\\Entity'), $config->getEntityNamespaces()));
$fixtureFileName = $this->getFixtureFileName($entity, $name, $ids);
$entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
$fixturePath = $bundle->getPath() . '/DataFixtures/ORM/' . $fixtureFileName . '.php';
$bundleNameSpace = $bundle->getNamespace();
if (file_exists($fixturePath)) {
throw new \RuntimeException(sprintf('Fixture "%s" already exists.', $fixtureFileName));
}
$class = new ClassMetadataInfo($entityClass);
$fixtureGenerator = $this->getFixtureGenerator();
$fixtureGenerator->setFixtureName($fixtureFileName);
$fixtureGenerator->setBundleNameSpace($bundleNameSpace);
$fixtureGenerator->setMetadata($class);
$fixtureGenerator->setFixtureOrder($order);
/** @var EntityManager $em */
$em = $this->registry->getManager($connectionName);
$repo = $em->getRepository($class->rootEntityName);
if (empty($ids)) {
$items = $repo->findAll();
} else {
$items = $repo->findById($ids);
}
$fixtureGenerator->setItems($items);
$fixtureCode = $fixtureGenerator->generateFixtureClass($class);
$this->filesystem->mkdir(dirname($fixturePath));
file_put_contents($fixturePath, $fixtureCode);
}