当前位置: 首页>>代码示例>>PHP>>正文


PHP RegistryInterface::getAliasNamespace方法代码示例

本文整理汇总了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);
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:41,代码来源:KunstmaanGenerator.php

示例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);
 }
开发者ID:GMBN,项目名称:DoctrineFixturesGeneratorBundle,代码行数:40,代码来源:DoctrineFixtureGenerator.php


注:本文中的Symfony\Bridge\Doctrine\RegistryInterface::getAliasNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。