本文整理匯總了PHP中Sylius\Component\Resource\Metadata\MetadataInterface::getClass方法的典型用法代碼示例。如果您正苦於以下問題:PHP MetadataInterface::getClass方法的具體用法?PHP MetadataInterface::getClass怎麽用?PHP MetadataInterface::getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sylius\Component\Resource\Metadata\MetadataInterface
的用法示例。
在下文中一共展示了MetadataInterface::getClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$reflection = new \ReflectionClass($metadata->getClass('model'));
$translatableInterface = 'Sylius\\Component\\Translation\\Model\\TranslatableInterface';
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName());
$repositoryClass = $translatable ? 'Sylius\\Bundle\\TranslationBundle\\Doctrine\\ORM\\TranslatableResourceRepository' : 'Sylius\\Bundle\\ResourceBundle\\Doctrine\\ORM\\EntityRepository';
if ($container->hasParameter($repositoryClassParameterName)) {
$repositoryClass = $container->getParameter($repositoryClassParameterName);
}
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$definition = new Definition($repositoryClass);
$definition->setArguments(array(new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)));
if ($metadata->hasParameter('translation')) {
$repositoryReflection = new \ReflectionClass($repositoryClass);
$translatableRepositoryInterface = 'Sylius\\Component\\Translation\\Repository\\TranslatableResourceRepositoryInterface';
$translationConfig = $metadata->getParameter('translation');
if (interface_exists($translatableRepositoryInterface) && $repositoryReflection->implementsInterface($translatableRepositoryInterface)) {
if (isset($translationConfig['fields'])) {
$definition->addMethodCall('setTranslatableFields', array($translationConfig['fields']));
}
}
}
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例2: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$reflection = new \ReflectionClass($metadata->getClass('model'));
$translatableInterface = TranslatableInterface::class;
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName());
$repositoryClass = $translatable ? TranslatableResourceRepository::class : EntityRepository::class;
if ($container->hasParameter($repositoryClassParameterName)) {
$repositoryClass = $container->getParameter($repositoryClassParameterName);
}
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
if ($metadata->hasParameter('translation')) {
$translatableRepositoryInterface = TranslatableResourceRepositoryInterface::class;
$translationConfig = $metadata->getParameter('translation');
if (interface_exists($translatableRepositoryInterface) && $repositoryReflection->implementsInterface($translatableRepositoryInterface)) {
if (isset($translationConfig['fields'])) {
$definition->addMethodCall('setTranslatableFields', [$translationConfig['fields']]);
}
}
}
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例3: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$modelClass = $metadata->getClass('model');
$repositoryClass = in_array(TranslatableInterface::class, class_implements($modelClass)) ? TranslatableRepository::class : new Parameter('sylius.mongodb.odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
$unitOfWorkDefinition->setFactory([new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'])->setPublic(false);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $unitOfWorkDefinition, $this->getClassMetadataDefinition($metadata)]);
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例4: addFactory
/**
* @param ContainerBuilder $container
* @param MetadataInterface $metadata
*/
protected function addFactory(ContainerBuilder $container, MetadataInterface $metadata)
{
$factoryClass = $metadata->getClass('factory');
$modelClass = $metadata->getClass('model');
$definition = new Definition($factoryClass);
$definitionArgs = [$modelClass];
if (in_array(TranslatableFactoryInterface::class, class_implements($factoryClass))) {
$decoratedDefinition = new Definition(Factory::class);
$decoratedDefinition->setArguments($definitionArgs);
$definitionArgs = [$decoratedDefinition, new Reference('sylius.translation_locale_provider')];
}
$definition->setArguments($definitionArgs);
$container->setDefinition($metadata->getServiceId('factory'), $definition);
}
示例5: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$modelClass = $metadata->getClass('model');
$reflection = new \ReflectionClass($modelClass);
$translatableInterface = 'Sylius\\Component\\Translation\\Model\\TranslatableInterface';
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
$repositoryClass = $translatable ? 'Sylius\\Bundle\\TranslationBundle\\Doctrine\\ODM\\MongoDB\\TranslatableResourceRepository' : new Parameter('sylius.mongodb_odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
$unitOfWorkDefinition->setFactory(array(new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'))->setPublic(false);
$definition = new Definition($repositoryClass);
$definition->setArguments(array(new Reference($metadata->getServiceId('manager')), $unitOfWorkDefinition, $this->getClassMetadataDefinition($modelClass)));
return $definition;
}
示例6: build
/**
* {@inheritdoc}
*/
public function build(MetadataInterface $metadata, FormBuilderInterface $formBuilder, array $options)
{
$classMetadata = $this->entityManager->getClassMetadata($metadata->getClass('model'));
if (1 < count($classMetadata->identifier)) {
throw new \RuntimeException('The default form factory does not support entity classes with multiple primary keys.');
}
$fields = (array) $classMetadata->fieldNames;
if (!$classMetadata->isIdentifierNatural()) {
$fields = array_diff($fields, $classMetadata->identifier);
}
foreach ($fields as $fieldName) {
$options = [];
if (in_array($fieldName, ['createdAt', 'updatedAt', 'deletedAt'])) {
continue;
}
if (Type::DATETIME === $classMetadata->getTypeOfField($fieldName)) {
$options = ['widget' => 'single_text'];
}
$formBuilder->add($fieldName, null, $options);
}
foreach ($classMetadata->getAssociationMappings() as $fieldName => $associationMapping) {
if (ClassMetadataInfo::ONE_TO_MANY !== $associationMapping['type']) {
$formBuilder->add($fieldName, null, ['property' => 'id']);
}
}
}
示例7: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$modelClass = $metadata->getClass('model');
$reflection = new \ReflectionClass($modelClass);
$translatableInterface = TranslatableInterface::class;
$translatable = interface_exists($translatableInterface) && $reflection->implementsInterface($translatableInterface);
$repositoryClass = $translatable ? TranslatableResourceRepository::class : new Parameter('sylius.mongodb_odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$unitOfWorkDefinition = new Definition('Doctrine\\ODM\\MongoDB\\UnitOfWork');
$unitOfWorkDefinition->setFactory([new Reference($this->getManagerServiceId($metadata)), 'getUnitOfWork'])->setPublic(false);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $unitOfWorkDefinition, $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例8:
function it_returns_specific_metadata_by_model_class(MetadataInterface $metadata1, MetadataInterface $metadata2)
{
$metadata1->getAlias()->willReturn('app.product');
$metadata1->getClass('model')->willReturn('App\\Model\\Product');
$metadata2->getAlias()->willReturn('app.order');
$metadata2->getClass('model')->willReturn('App\\Model\\Order');
$this->add($metadata1);
$this->add($metadata2);
$this->getByClass('App\\Model\\Order')->shouldReturn($metadata2);
}
示例9: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$repositoryClass = new Parameter('sylius.phpcr_odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$definition = new Definition($repositoryClass);
$definition->setArguments(array(new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)));
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例10: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName());
$repositoryClass = EntityRepository::class;
if ($container->hasParameter($repositoryClassParameterName)) {
$repositoryClass = $container->getParameter($repositoryClassParameterName);
}
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]);
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例11: getFormType
/**
* @return string|null
*/
public function getFormType()
{
$form = $this->parameters->get('form');
if (isset($form['type'])) {
return $form['type'];
}
if (is_string($form)) {
return $form;
}
$form = $this->metadata->getClass('form');
if (is_string($form)) {
return $form;
}
return sprintf('%s_%s', $this->metadata->getApplicationName(), $this->metadata->getName());
}
示例12: build
/**
* {@inheritdoc}
*/
public function build(MetadataInterface $metadata, FormBuilderInterface $formBuilder, array $options)
{
$classMetadata = $this->documentManager->getClassMetadata($metadata->getClass('model'));
// the field mappings should only contain standard value mappings
foreach ($classMetadata->fieldMappings as $fieldName) {
if ($fieldName === $classMetadata->uuidFieldName) {
continue;
}
if ($fieldName === $classMetadata->nodename) {
continue;
}
$options = [];
$mapping = $classMetadata->mappings[$fieldName];
if ($mapping['nullable'] === false) {
$options['required'] = true;
}
$formBuilder->add($fieldName, null, $options);
}
}
示例13: addRepository
/**
* {@inheritdoc}
*/
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata)
{
$repositoryClass = new Parameter('sylius.phpcr_odm.repository.class');
if ($metadata->hasClass('repository')) {
$repositoryClass = $metadata->getClass('repository');
}
$repositoryReflection = new \ReflectionClass($repositoryClass);
$definition = new Definition($repositoryClass);
$definition->setArguments([new Reference($metadata->getServiceId('manager')), $this->getClassMetadataDefinition($metadata)]);
$definition->setLazy(!$repositoryReflection->isFinal());
if ($metadata->hasParameter('translation')) {
$translationConfig = $metadata->getParameter('translation');
if (in_array(TranslatableRepositoryInterface::class, class_implements($repositoryClass))) {
if (isset($translationConfig['fields'])) {
$definition->addMethodCall('setTranslatableFields', [$translationConfig['fields']]);
}
}
}
$container->setDefinition($metadata->getServiceId('repository'), $definition);
}
示例14: addForms
/**
* @param ContainerBuilder $container
* @param MetadataInterface $metadata
*/
protected function addForms(ContainerBuilder $container, MetadataInterface $metadata)
{
foreach ($metadata->getClass('form') as $formName => $formClass) {
$suffix = 'default' === $formName ? '' : sprintf('_%s', $formName);
$alias = sprintf('%s_%s%s', $metadata->getApplicationName(), $metadata->getName(), $suffix);
$definition = new Definition($formClass);
switch ($formName) {
case 'choice':
$definition->setArguments([$metadata->getClass('model'), $metadata->getDriver(), $alias]);
break;
default:
$validationGroupsParameterName = sprintf('%s.validation_groups.%s%s', $metadata->getApplicationName(), $metadata->getName(), $suffix);
$validationGroups = new Parameter($validationGroupsParameterName);
if (!$container->hasParameter($validationGroupsParameterName)) {
$validationGroups = ['Default'];
}
$definition->setArguments([$metadata->getClass('model'), $validationGroups]);
break;
}
$definition->addTag('form.type', ['alias' => $alias]);
$container->setParameter(sprintf('%s.form.type.%s%s.class', $metadata->getApplicationName(), $metadata->getName(), $suffix), $formClass);
$container->setDefinition(sprintf('%s.form.type.%s%s', $metadata->getApplicationName(), $metadata->getName(), $suffix), $definition);
}
if (!$container->hasDefinition(sprintf('%s.form.type.%s', $metadata->getApplicationName(), $metadata->getName()))) {
$this->addDefaultForm($container, $metadata);
}
}
示例15:
function it_throws_unknown_driver_exception_when_constructing_with_invalid_driver(MetadataInterface $metadata)
{
$metadata->getClass('model')->willReturn('CountryModel');
$metadata->getDriver()->willReturn('badDriver');
$this->shouldThrow(UnknownDriverException::class)->during('getParent');
}