本文整理汇总了PHP中Symfony\Component\HttpKernel\Bundle\BundleInterface::getPath方法的典型用法代码示例。如果您正苦于以下问题:PHP BundleInterface::getPath方法的具体用法?PHP BundleInterface::getPath怎么用?PHP BundleInterface::getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Bundle\BundleInterface
的用法示例。
在下文中一共展示了BundleInterface::getPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateRestRouting
public function generateRestRouting(BundleInterface $bundle, $controller)
{
$file = $bundle->getPath() . '/Resources/config/routing.rest.yml';
if (file_exists($file)) {
$content = file_get_contents($file);
} elseif (!is_dir($dir = $bundle->getPath() . '/Resources/config')) {
mkdir($dir);
}
$resource = $bundle->getNamespace() . "\\Controller\\" . $controller . 'Controller';
$name = strtolower(preg_replace('/([A-Z])/', '_\\1', $bundle->getName() . $controller . '_rest'));
$name_prefix = strtolower(preg_replace('/([A-Z])/', '_\\1', $bundle->getName() . '_api_'));
if (!isset($content)) {
$content = '';
} else {
$yml = new Yaml();
$route = $yml->parse($content);
if (isset($route[$name])) {
return false;
}
}
$content .= sprintf("\n%s:\n type: rest\n resource: %s\n name_prefix: %s\n", $name, $resource, $name_prefix);
$flink = fopen($file, 'w');
if ($flink) {
$write = fwrite($flink, $content);
if ($write) {
fclose($flink);
} else {
throw new \RunTimeException(sprintf('We cannot write into file "%s", has that file the correct access level?', $file));
}
} else {
throw new \RunTimeException(sprintf('Problems with generating file "%s", did you gave write access to that directory?', $file));
}
}
示例2: generate
/**
* Generates the datatable class if it does not exist.
*
* @param BundleInterface $bundle The bundle in which to create the class
* @param string $entity The entity relative class name
* @param array $fields The datatable fields
* @param boolean $clientSide The client side flag
* @param string $ajaxUrl The ajax url
* @param boolean $bootstrap3 The bootstrap3 flag
* @param boolean $admin The admin flag
*
* @throws RuntimeException
*/
public function generate(BundleInterface $bundle, $entity, array $fields, $clientSide, $ajaxUrl, $bootstrap3, $admin)
{
$parts = explode("\\", $entity);
$entityClass = array_pop($parts);
$this->className = $entityClass . 'Datatable';
$dirPath = $bundle->getPath() . '/Datatables';
if (true === $admin) {
$this->className = $entityClass . 'AdminDatatable';
$dirPath = $bundle->getPath() . '/Datatables/Admin';
}
$this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Datatable.php';
if (true === $admin) {
$this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'AdminDatatable.php';
}
if (file_exists($this->classPath)) {
throw new RuntimeException(sprintf('Unable to generate the %s datatable class as it already exists under the %s file', $this->className, $this->classPath));
}
$parts = explode('\\', $entity);
array_pop($parts);
// set ajaxUrl
if (false === $clientSide) {
// server-side
if (!$ajaxUrl) {
$this->ajaxUrl = strtolower($entityClass) . '_results';
} else {
$this->ajaxUrl = $ajaxUrl;
}
}
$routePref = strtolower($entityClass);
if (true === $admin) {
$routePref = DatatablesRoutingLoader::PREF . strtolower($entityClass);
$bootstrap3 = true;
}
$this->renderFile('class.php.twig', $this->classPath, array('namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'entity_class' => $entityClass, 'bundle' => $bundle->getName(), 'datatable_class' => $this->className, 'datatable_name' => $admin ? strtolower($entityClass) . '_admin_datatable' : strtolower($entityClass) . '_datatable', 'fields' => $fields, 'client_side' => (bool) $clientSide, 'ajax_url' => $admin ? DatatablesRoutingLoader::PREF . $this->ajaxUrl : $this->ajaxUrl, 'bootstrap3' => (bool) $bootstrap3, 'admin' => (bool) $admin, 'route_pref' => $routePref));
}
示例3: generate
/**
* @param BundleInterface $bundle The bundle
* @param string $entity The entity name
* @param string $format The format
* @param array $fields The fields
* @param boolean $withRepository With repository
* @param string $prefix A prefix
*
* @throws \RuntimeException
*/
public function generate(BundleInterface $bundle, $entity, $format, array $fields, $withRepository, $prefix)
{
// 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'), $config->getEntityNamespaces()));
$entityClass = $this->registry->getAliasNamespace($bundle->getName()) . '\\' . $entity;
$entityPath = $bundle->getPath() . '/Entity/' . str_replace('\\', '/', $entity) . '.php';
if (file_exists($entityPath)) {
throw new \RuntimeException(sprintf('Entity "%s" already exists.', $entityClass));
}
$class = new ClassMetadataInfo($entityClass);
if ($withRepository) {
$entityClass = preg_replace('/\\\\Entity\\\\/', '\\Repository\\', $entityClass, 1);
$class->customRepositoryClassName = $entityClass . 'Repository';
}
foreach ($fields as $field) {
$class->mapField($field);
}
$class->setPrimaryTable(array('name' => $prefix . $this->getTableNameFromEntityName($entity)));
$entityGenerator = $this->getEntityGenerator();
$entityCode = $entityGenerator->generateEntityClass($class);
$mappingPath = $mappingCode = false;
$this->filesystem->mkdir(dirname($entityPath));
file_put_contents($entityPath, $entityCode);
if ($mappingPath) {
$this->filesystem->mkdir(dirname($mappingPath));
file_put_contents($mappingPath, $mappingCode);
}
if ($withRepository) {
$path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
$this->getRepositoryGenerator()->writeEntityRepositoryClass($class->customRepositoryClassName, $path);
}
$this->addGeneratedEntityClassLoader($entityClass, $entityPath);
}
示例4: generate
/**
* @param \Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
* @param string $document
* @param array $fields
* @param Boolean $withRepository
* @throws \RuntimeException
*/
public function generate(BundleInterface $bundle, $document, array $fields, $withRepository)
{
$config = $this->documentManager->getConfiguration();
$config->addDocumentNamespace($bundle->getName(), $bundle->getNamespace() . '\\Document');
$documentClass = $config->getDocumentNamespace($bundle->getName()) . '\\' . $document;
$documentPath = $bundle->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php';
if (file_exists($documentPath)) {
throw new \RuntimeException(sprintf('Document "%s" already exists.', $documentClass));
}
$class = new ClassMetadataInfo($documentClass);
if ($withRepository) {
$class->setCustomRepositoryClass($documentClass . 'Repository');
}
$class->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$class->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
foreach ($fields as $field) {
$class->mapField($field);
}
$documentGenerator = $this->getDocumentGenerator();
$documentCode = $documentGenerator->generateDocumentClass($class);
$this->filesystem->mkdir(dirname($documentPath));
file_put_contents($documentPath, rtrim($documentCode) . PHP_EOL, LOCK_EX);
if ($withRepository) {
$path = $bundle->getPath() . str_repeat('/..', substr_count(get_class($bundle), '\\'));
$this->getRepositoryGenerator()->writeDocumentRepositoryClass($class->customRepositoryClassName, $path);
}
}
示例5: getClasses
/**
* @param $dirs
* @param array $classes
* @param array $excludeClasses
* @param string $pattern
* @return array
*/
protected function getClasses($dirs, $classes = array(), $excludeClasses = array(), $pattern = '*.php')
{
$basePath = $this->bundle->getPath();
$dirs = array_map(function ($dir) use($basePath) {
return $basePath . '/' . $dir;
}, $dirs);
$allClasses = $this->classFinder->findClasses($dirs, $basePath, $this->bundle->getNamespace(), $pattern);
$allClasses = array_unique(array_merge($classes, $allClasses));
return array_filter($allClasses, function ($class) use($excludeClasses) {
return !in_array($class, $excludeClasses);
});
}
示例6: findGeneratorYamlInBundle
/**
* Find templates in the given bundle.
*
* @param BundleInterface $bundle The bundle where to look for templates
*
* @return array of yaml paths
*/
private function findGeneratorYamlInBundle(BundleInterface $bundle)
{
$yamls = array();
if (!file_exists($bundle->getPath() . '/Resources/config')) {
return $yamls;
}
$finder = new Finder();
$finder->files()->name('generator.yml')->name('*-generator.yml')->in($bundle->getPath() . '/Resources/config');
foreach ($finder as $file) {
$yamls[$file->getRealPath()] = $file->getRealPath();
}
return $yamls;
}
示例7: generate
public function generate(BundleInterface $bundle, $controller, $routeFormat, $templateFormat, array $actions = array())
{
$dir = $bundle->getPath();
$controllerFile = $dir . '/Controller/' . $controller . 'Controller.php';
if (file_exists($controllerFile)) {
throw new \RuntimeException(sprintf('Controller "%s" already exists', $controller));
}
// seeRoute
$bundleShortName = substr($bundle->getName(), strlen('Webobs'), strlen($bundle->getName()) - (strlen('Bundle') + strlen('Webobs')));
$seeRoute = 'webobs_' . strtolower($bundleShortName) . '_' . strtolower($controller) . '_see';
$parameters = array('namespace' => $bundle->getNamespace(), 'bundle' => $bundle->getName(), 'format' => array('routing' => $routeFormat, 'templating' => $templateFormat), 'entity' => $controller, 'seeRoute' => $seeRoute);
foreach ($actions as $i => $action) {
// get the actioname without the sufix Action (for the template logical name)
$actions[$i]['basename'] = $action['name'];
$params = $parameters;
$params['action'] = $actions[$i];
// create a template
$template = $actions[$i]['template'];
if ('default' == $template) {
$template = $bundle->getName() . ':' . $controller . ':' . $action['name'] . '.html.' . $templateFormat;
}
$this->generateRouting($bundle, $controller, $actions[$i], $routeFormat);
}
$parameters['actions'] = $actions;
$this->renderFile('controller/Controller.php.twig', $controllerFile, $parameters);
$this->renderFile('controller/ControllerTest.php.twig', $dir . '/Tests/Controller/' . $controller . 'ControllerTest.php', $parameters);
}
示例8: updateDependencyInjectionXml
/**
* <parameters>
* <parameter key="app.project.module.class">AppBundle\Module\ProjectModule</parameter>
* </parameters>
* <service id="app.project.module" class="%app.project.module.class%">
* <tag name="clastic.module" node_module="true" alias="project" />
* <tag name="clastic.node_form" build_service="app.project.module.form_build" />
* </service>.
*
* @param BundleInterface $bundle
* @param array $data
*/
private function updateDependencyInjectionXml(BundleInterface $bundle, array $data)
{
$file = $bundle->getPath() . '/Resources/config/services.xml';
$xml = simplexml_load_file($file);
$parameters = $xml->parameters ? $xml->parameters : $xml->addChild('parameters');
$services = $xml->services ? $xml->services : $xml->addChild('services');
$moduleServiceName = sprintf('%s.%s.module', $data['bundle_alias'], $data['identifier']);
$moduleParameter = $parameters->addChild('parameter', sprintf('%s\\Module\\%sModule', $data['namespace'], $data['module']));
$moduleParameter->addAttribute('key', sprintf('%s.class', $moduleServiceName));
$formExtensionParameter = $parameters->addChild('parameter', sprintf('%s\\Form\\Module\\%sFormExtension', $data['namespace'], $data['module']));
$formExtensionParameter->addAttribute('key', sprintf('%s.form_extension.class', $moduleServiceName));
$moduleService = $services->addChild('service');
$moduleService->addAttribute('id', sprintf('%s.%s.module', $data['bundle_alias'], $data['identifier']));
$moduleService->addAttribute('class', sprintf('%%%s.class%%', $moduleServiceName));
$moduleTag = $moduleService->addChild('tag');
$moduleTag->addAttribute('name', 'clastic.module');
$moduleTag->addAttribute('node_module', 'true');
$moduleTag->addAttribute('alias', $data['identifier']);
$formExtensionTag = $moduleService->addChild('tag');
$formExtensionTag->addAttribute('name', 'clastic.node_form');
$formExtensionTag->addAttribute('build_service', sprintf('%s.form_extension', $moduleServiceName));
$formExtensionService = $services->addChild('service');
$formExtensionService->addAttribute('id', sprintf('%s.form_extension', $moduleServiceName));
$formExtensionService->addAttribute('class', sprintf('%%%s.form_extension.class%%', $moduleServiceName));
$xml->saveXML($file);
}
示例9: 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);
}
示例10: getPrefix
/**
* Gets the prefix of the asset with the given bundle
*
* @param BundleInterface $bundle Bundle to fetch in
*
* @throws \InvalidArgumentException
* @return string Prefix
*/
public function getPrefix(BundleInterface $bundle)
{
if (!is_dir($bundle->getPath() . '/Resources/public')) {
throw new \InvalidArgumentException(sprintf('Bundle %s does not have Resources/public folder', $bundle->getName()));
}
return sprintf('/bundles/%s', preg_replace('/bundle$/', '', strtolower($bundle->getName())));
}
示例11: generate
/**
* Generates the entity form class if it does not exist.
*
* @param BundleInterface $bundle The bundle in which to create the class
* @param string $entity The entity relative class name
* @param ClassMetadataInfo $metadata The entity metadata class
*/
public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
{
$parts = explode('\\', $entity);
$entityClass = array_pop($parts);
$this->className = $entityClass.'Type';
$dirPath = $bundle->getPath().'/Form';
$this->classPath = $dirPath.'/'.str_replace('\\', '/', $entity).'Type.php';
if (file_exists($this->classPath)) {
throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
}
if (count($metadata->identifier) > 1) {
throw new \RuntimeException('The form generator does not support entity classes with multiple primary keys.');
}
$parts = explode('\\', $entity);
array_pop($parts);
$this->renderFile($this->skeletonDir, 'FormType.php', $this->classPath, array(
'dir' => $this->skeletonDir,
'fields' => $this->getFieldsFromMetadata($metadata),
'namespace' => $bundle->getNamespace(),
'entity_namespace' => implode('\\', $parts),
'form_class' => $this->className,
));
}
示例12: generate
/**
* Generates the entity form class if it does not exist.
*
* @param BundleInterface $bundle The bundle in which to create the class
* @param string $entity The entity relative class name
* @param ClassMetadataInfo $metadata The entity metadata class
*/
public function generate(BundleInterface $bundle, $entity, $fields, $options = null, $search = false)
{
$parts = explode('\\', $entity);
$entityClass = array_pop($parts);
$this->className = $entityClass . 'Type';
$dirPath = $bundle->getPath() . '/Form';
if ($search) {
$className = $entityClass . 'SearchType';
$this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'SearchType.php';
} else {
$className = $entityClass . 'Type';
$this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'Type.php';
}
if (file_exists($this->classPath)) {
unlink($this->classPath);
//throw new \RuntimeException(sprintf('Unable to generate the %s form class as it already exists under the %s file', $this->className, $this->classPath));
}
$choice = false;
foreach ($fields as $field) {
if ($field['fragment'] == 'choice') {
$choice = true;
}
}
$parts = explode('\\', $entity);
array_pop($parts);
$this->renderFile($this->skeletonDir, 'FormType_tab.php', $this->classPath, array('dir' => $this->skeletonDir, 'fields' => $fields, 'namespace' => $bundle->getNamespace(), 'entity_namespace' => implode('\\', $parts), 'form_class' => $className, 'form_type_name' => strtolower(str_replace('\\', '_', $bundle->getNamespace()) . ($parts ? '_' : '') . implode('_', $parts) . '_' . $this->className), 'entityName' => $entityClass, 'choice' => $choice, 'options' => $options));
}
示例13: exportTranslations
/**
* Export the translations from a given path
*
* @param BundleInterface $bundle
* @param string $locale
* @param string $outputDir
* @param bool $excel
* @return array
*/
private function exportTranslations(BundleInterface $bundle, $locale, $outputDir, $excel = false)
{
// if the bundle does not have a translation dir, continue to the next one
$translationPath = sprintf('%s%s', $bundle->getPath(), '/Resources/translations');
if (!is_dir($translationPath)) {
return array();
}
// create a catalogue, and load the messages
$catalogue = new MessageCatalogue($locale);
/** @var \Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader $loader */
$loader = $this->getContainer()->get('translation.loader');
$loader->loadMessages($translationPath, $catalogue);
// export in desired format
if ($excel) {
// check if the PHPExcel library is installed
if (!class_exists('PHPExcel')) {
throw new \RuntimeException('PHPExcel library is not installed. Please do so if you want to export translations as Excel file.');
}
$dumper = new ExcelFileDumper();
} else {
$dumper = new CsvFileDumper();
}
/** @var DumperInterface $dumper */
return $dumper->dump($catalogue, array('path' => $outputDir, 'bundleName' => $bundle->getName()));
}
示例14: generate
/**
* Generates the entity form class if it does not exist.
*
* @param BundleInterface $bundle The bundle in which to create the class
* @param string $entity The entity relative class name
* @param ClassMetadataInfo $metadata The entity metadata class
*/
public function generate(BundleInterface $bundle, $entity, ClassMetadataInfo $metadata)
{
if (is_null($this->src)) {
$this->src = $bundle->getPath();
}
$this->entity = $entity;
$dirPath = $this->src . '/Form/Type';
$this->classPath = $dirPath . '/' . str_replace('\\', '/', $entity) . 'FormType.php';
if (count($metadata->identifier) > 1) {
throw new \RuntimeException('The form generator does not support entity classes with multiple primary keys.');
}
$fields = $this->getFieldsFromMetadata($metadata);
$maxColumnNameSize = 0;
foreach ($fields as $field) {
$maxColumnNameSize = max($field['columnNameSize'] + 2, $maxColumnNameSize);
}
$options = array('fields' => $fields, 'form_class' => $entity . 'FormType', 'form_label' => $entity, 'max_column_name_size' => $maxColumnNameSize);
$this->tplOptions = array_merge($this->tplOptions, $options);
$this->generateForm();
$this->generateServices();
if ($this->getContainer()->getParameter('dev_generator_tool.generate_translation')) {
$g = new TranslationGenerator($this->filesystem, sprintf('%s/Resources/translations', $this->src), $entity, $fields);
$g->generate();
}
}
示例15: generateSectionConfig
/**
* Update the page section config files
*/
private function generateSectionConfig()
{
if (count($this->sections) > 0) {
$dir = $this->bundle->getPath() . '/Resources/config/pageparts/';
foreach ($this->sections as $section) {
$data = Yaml::parse($dir . $section);
if (!array_key_exists('types', $data)) {
$data['types'] = array();
}
$class = $this->bundle->getNamespace() . '\\Entity\\PageParts\\' . $this->entity;
$found = false;
foreach ($data['types'] as $type) {
if ($type['class'] == $class) {
$found = true;
}
}
if (!$found) {
$data['types'][] = array('name' => str_replace('PagePart', '', $this->entity), 'class' => $class);
}
$ymlData = Yaml::dump($data, $inline = 2, $indent = 4, $exceptionOnInvalidType = false, $objectSupport = false);
file_put_contents($dir . $section, $ymlData);
}
$this->assistant->writeLine('Updating ' . $this->entity . ' section config: <info>OK</info>');
}
}