本文整理汇总了PHP中Symfony\Component\HttpKernel\Bundle\BundleInterface类的典型用法代码示例。如果您正苦于以下问题:PHP BundleInterface类的具体用法?PHP BundleInterface怎么用?PHP BundleInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BundleInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: 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();
}
}
示例3: testLoadedServices
/**
* @covers ::build
* @dataProvider loadedServicesProvider
*/
public function testLoadedServices(BundleInterface $bundle, array $expected_service_definitions)
{
$container = new ContainerBuilder();
$bundle->build($container);
$definitions = $container->getDefinitions();
foreach ($definitions as $id => $def) {
/* @var $def \Symfony\Component\DependencyInjection\Definition */
$class = $def->getClass();
$expected_service_definitions_count = count($expected_service_definitions);
for ($i = 0; $i < $expected_service_definitions_count; $i++) {
if ($id === $expected_service_definitions[$i]) {
unset($expected_service_definitions[$i]);
break;
}
}
// reset indice
$expected_service_definitions = array_values($expected_service_definitions);
// found a resource we didn't expect
if (count($expected_service_definitions) === $expected_service_definitions_count) {
$this->fail('Test did not expect service definition to be loaded: ' . $id . ' with class ' . $class);
}
// test this later because fixing this failure can lead to the previous
if (!class_exists($class)) {
$this->fail(sprintf('Could not load class %s for definition %s', $class, $id));
}
}
$this->assertEmpty($expected_service_definitions, 'Service definition(s) missing: ' . implode(',', $expected_service_definitions));
}
示例4: installBundleAssets
/**
* {@inheritdoc}
*/
public function installBundleAssets(BundleInterface $bundle, $targetDir, $symlinkMask)
{
$this->output->writeln(sprintf('Installing assets for <comment>%s</comment>', $bundle->getNamespace(), $targetDir));
$effectiveSymlinkMask = $this->assetsInstaller->installBundleAssets($bundle, $targetDir, $symlinkMask);
$this->output->writeln($this->provideResultComment($symlinkMask, $effectiveSymlinkMask));
return $effectiveSymlinkMask;
}
示例5: getSkeletonDirs
protected function getSkeletonDirs(BundleInterface $bundle = null)
{
$skeletonDirs = array();
if (isset($bundle) && is_dir($dir = $bundle->getPath() . '/Resources/SensioGeneratorBundle/skeleton')) {
$skeletonDirs[] = $dir;
}
if (is_dir($dir = $this->getContainer()->get('kernel')->getRootdir() . '/Resources/SensioGeneratorBundle/skeleton')) {
$skeletonDirs[] = $dir;
}
$bundleDirs = $this->getContainer()->get('kernel')->locateResource('@SensioGeneratorBundle/Resources/skeleton', null, false);
$sensioGeneratorSkeletonPath = dirname(__DIR__) . '/Resources/skeleton';
/*
* Assert: $bundleDirs is an array that contains $sensioGeneratorSkeletonPath and maybe some more
* Since $skeletonDirs is a prioritized list we want to exclude $sensioGeneratorSkeletonPath from $bundleDirs
* now and make sure it is added at the end of the list.
*/
foreach ($bundleDirs as $dir) {
if ($dir != $sensioGeneratorSkeletonPath) {
$skeletonDirs[] = $dir;
}
}
$skeletonDirs[] = $sensioGeneratorSkeletonPath;
$skeletonDirs[] = __DIR__ . '/../Resources';
return $skeletonDirs;
}
示例6: generateServiceId
public function generateServiceId(BundleInterface $bundle, $className)
{
$namespace = $bundle->getNamespace();
$alias = $bundle->getAlias();
$bundleClass = substr($className, strlen($namespace) + 1);
return sprintf('%s.%s', $alias, $this->makeParentDirAsClassifier($bundleClass));
}
示例7: 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));
}
示例8: isClassInBundle
/**
* @param string $class
* @param BundleInterface $bundle
*
* @return boolean
*/
public function isClassInBundle($class, BundleInterface $bundle)
{
if (false === $class instanceof \ReflectionClass) {
$class = $this->reflection->createFromClass($class);
}
return true === strpos($class->getNamespaceName(), $bundle->getNamespace());
}
示例9: 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);
}
示例10: 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()));
}
示例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: 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())));
}
示例13: generateExceptionClass
protected function generateExceptionClass(BundleInterface $bundle, $target)
{
if (!is_dir(dirname($target))) {
mkdir(dirname($target));
}
$this->renderFile('form/form_exception.php.twig', $target, ['namespace' => $bundle->getNamespace()]);
}
示例14: findAdminControllerClasses
public function findAdminControllerClasses(BundleInterface $bundle)
{
$directory = $bundle->getPath() . '/Controller/Admin';
$namespace = $bundle->getNamespace() . '\\Controller\\Admin';
$interface = AdminControllerInterface::class;
$classes = $this->findClassesImplementingInterface($directory, $namespace, $interface);
return $classes;
}
示例15:
function it_locates_resource(PathCheckerInterface $pathChecker, KernelInterface $kernel, BundleInterface $bundle)
{
$bundle->getName()->willReturn("Bundle");
$bundle->getPath()->willReturn("/app/bundle");
$kernel->getBundle("Bundle", false)->willReturn([$bundle]);
$pathChecker->processPaths(Argument::type('array'), Argument::type('array'), [])->shouldBeCalled()->willReturn("/app/bundle/resource");
$this->locateResource("@Bundle/Resources/resource", [])->shouldReturn("/app/bundle/resource");
}