本文整理汇总了PHP中Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper::buildEnumValueClassName方法的典型用法代码示例。如果您正苦于以下问题:PHP ExtendHelper::buildEnumValueClassName方法的具体用法?PHP ExtendHelper::buildEnumValueClassName怎么用?PHP ExtendHelper::buildEnumValueClassName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper
的用法示例。
在下文中一共展示了ExtendHelper::buildEnumValueClassName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isDisabled
/**
* Checks if the given constraint is applied or not
*
* @param Options $options
* @param string|null $constraintName Can be: null, 'add', 'delete'
*
* @return bool
*/
protected function isDisabled($options, $constraintName = null)
{
/** @var ConfigIdInterface $configId */
$configId = $options['config_id'];
$className = $configId->getClassName();
if (empty($className)) {
return false;
}
$fieldName = $this->typeHelper->getFieldName($configId);
if (empty($fieldName)) {
return false;
}
$enumCode = $this->typeHelper->getEnumCode($className, $fieldName);
if (!empty($enumCode)) {
if ($options['config_is_new']) {
// a new field reuses public enum
return true;
}
if ($constraintName) {
$enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode);
if ($this->typeHelper->isImmutable('enum', $enumValueClassName, null, $constraintName)) {
// is immutable
return true;
}
}
}
return false;
}
示例2: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$defaultFieldOptions = ['multiple' => true];
$resolver->setDefaults(['dictionary_code' => null, 'class' => null, 'field_options' => $defaultFieldOptions]);
$resolver->setNormalizers(['class' => function (Options $options, $value) {
if ($value !== null) {
return $value;
}
if (empty($options['dictionary_code'])) {
throw new InvalidOptionsException('Either "class" or "dictionary_code" must option must be set.');
}
$class = ExtendHelper::buildEnumValueClassName($options['dictionary_code']);
if (!is_a($class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue', true)) {
throw new InvalidOptionsException(sprintf('"%s" must be a child of "%s"', $class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue'));
}
return $class;
}, 'field_options' => function (Options $options, $value) use(&$defaultFieldOptions) {
if (isset($options['class'])) {
$nullValue = null;
if ($options->has('null_value')) {
$nullValue = $options->get('null_value');
}
$value['choices'] = $this->getChoices($options['class'], $nullValue);
} else {
$value['choices'] = [];
}
return array_merge($defaultFieldOptions, $value);
}]);
}
示例3: configureOptions
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$defaultFieldOptions = ['multiple' => true];
$resolver->setDefaults(['enum_code' => null, 'class' => null, 'field_options' => $defaultFieldOptions, 'operator_choices' => [self::TYPE_IN => $this->translator->trans('oro.filter.form.label_type_in'), self::TYPE_NOT_IN => $this->translator->trans('oro.filter.form.label_type_not_in')]]);
$resolver->setNormalizer('class', function (Options $options, $value) {
if ($value !== null) {
return $value;
}
if (empty($options['enum_code'])) {
throw new InvalidOptionsException('Either "class" or "enum_code" must option must be set.');
}
$class = ExtendHelper::buildEnumValueClassName($options['enum_code']);
if (!is_a($class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue', true)) {
throw new InvalidOptionsException(sprintf('"%s" must be a child of "%s"', $class, 'Oro\\Bundle\\EntityExtendBundle\\Entity\\AbstractEnumValue'));
}
return $class;
});
// this normalizer allows to add/override field_options options outside
$resolver->setNormalizer('field_options', function (Options $options, $value) use(&$defaultFieldOptions) {
if (isset($options['class'])) {
$nullValue = null;
if ($options->offsetExists('null_value')) {
$nullValue = $options->offsetGet('null_value');
}
$value['choices'] = $this->getChoices($options['class'], $nullValue);
} else {
$value['choices'] = [];
}
return array_merge($defaultFieldOptions, $value);
});
}
示例4: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$internalRatings = $manager->getRepository(ExtendHelper::buildEnumValueClassName(Account::INTERNAL_RATING_CODE))->findAll();
/** @var \Oro\Bundle\UserBundle\Entity\User $accountOwner */
$accountOwner = $manager->getRepository('OroUserBundle:User')->findOneBy([]);
foreach ($this->accounts as $accountName => $accountData) {
/** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $accountGroup */
$accountGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $accountData['group']);
$account = new Account();
$account->setName($accountName)->setGroup($accountGroup)->setParent(null)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]);
$manager->persist($account);
$this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $account->getName(), $account);
if (isset($accountData['subsidiaries'])) {
foreach ($accountData['subsidiaries'] as $subsidiaryName => $subsidiaryData) {
/** @var \OroB2B\Bundle\AccountBundle\Entity\AccountGroup $subsidiaryGroup */
$subsidiaryGroup = $this->getReference(LoadAccountGroupDemoData::ACCOUNT_GROUP_REFERENCE_PREFIX . $subsidiaryData['group']);
$subsidiary = new Account();
$subsidiary->setName($subsidiaryName)->setGroup($subsidiaryGroup)->setParent($account)->setOrganization($accountOwner->getOrganization())->setOwner($accountOwner)->setInternalRating($internalRatings[array_rand($internalRatings)]);
$manager->persist($subsidiary);
$this->addReference(static::ACCOUNT_REFERENCE_PREFIX . $subsidiary->getName(), $subsidiary);
}
}
}
$manager->flush();
}
示例5: isReadOnly
/**
* Checks if the form type should be read-only or not
*
* @param Options $options
*
* @return bool
*/
protected function isReadOnly($options)
{
/** @var ConfigIdInterface $configId */
$configId = $options['config_id'];
$className = $configId->getClassName();
if (empty($className)) {
return false;
}
$fieldName = $this->typeHelper->getFieldName($configId);
if (empty($fieldName)) {
return false;
}
if ($this->typeHelper->isSystem($className, $fieldName)) {
// it is a system field
return true;
}
$enumCode = $this->typeHelper->getEnumCode($className, $fieldName);
if (!empty($enumCode)) {
if ($options['config_is_new']) {
// a new field reuses public enum
return true;
}
$enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode);
if ($this->typeHelper->isImmutable('enum', $enumValueClassName, null, 'public')) {
// is immutable
return true;
}
if ($this->typeHelper->hasOtherReferences($enumCode, $className, $fieldName)) {
// an enum is reused by other fields
return true;
}
}
return false;
}
示例6: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
/** @var AccountUser[] $accountUsers */
$accountUsers = $manager->getRepository('OroB2BCustomerBundle:AccountUser')->findAll();
$internalRatings = $manager->getRepository(ExtendHelper::buildEnumValueClassName(Customer::INTERNAL_RATING_CODE))->findAll();
$rootCustomer = null;
$firstLevelCustomer = null;
// create customer groups
$rootGroup = $this->createCustomerGroup('Root');
$firstLevelGroup = $this->createCustomerGroup('First');
$secondLevelGroup = $this->createCustomerGroup('Second');
$manager->persist($rootGroup);
$manager->persist($firstLevelGroup);
$manager->persist($secondLevelGroup);
// create customers
foreach ($accountUsers as $index => $accountUser) {
$customer = $accountUser->getCustomer();
switch ($index % 3) {
case 0:
$customer->setGroup($rootGroup);
$rootCustomer = $customer;
break;
case 1:
$customer->setGroup($firstLevelGroup)->setParent($rootCustomer);
$firstLevelCustomer = $customer;
break;
case 2:
$customer->setGroup($secondLevelGroup)->setParent($firstLevelCustomer);
break;
}
$customer->setInternalRating($internalRatings[array_rand($internalRatings)]);
}
$manager->flush();
}
示例7: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
/** @var UserManager $userManager */
$userManager = $this->container->get('oro_user.manager');
$admin = $userManager->findUserByEmail(LoadAdminUserData::DEFAULT_ADMIN_EMAIL);
$organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst();
/** @var Store $store */
$store = $this->getReference('store');
/** @var Channel $channel */
$channel = $this->getReference('default_channel');
/** @var Integration $integration */
$integration = $this->getReference('integration');
$className = ExtendHelper::buildEnumValueClassName('mage_subscr_status');
$enumRepo = $manager->getRepository($className);
foreach ($this->subscriberData as $data) {
$subscriber = new NewsletterSubscriber();
$date = new \DateTime();
$date->modify('-1 day');
/** @var AbstractEnumValue $status */
$status = $enumRepo->find($data['status']);
$subscriber->setEmail($data['email'])->setStatus($status)->setConfirmCode(uniqid())->setStore($store)->setOwner($admin)->setOrganization($organization)->setOriginId($data['originId'])->setChangeStatusAt($date)->setCreatedAt($date)->setUpdatedAt($date)->setChannel($integration)->setDataChannel($channel);
if (!empty($data['customer'])) {
/** @var Customer $customer */
$customer = $this->getReference($data['customer']);
$subscriber->setCustomer($customer);
}
$this->setReference($data['reference'], $subscriber);
$manager->persist($subscriber);
}
$manager->flush();
}
示例8: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
parent::load($manager);
$className = ExtendHelper::buildEnumValueClassName($this->getEnumCode());
/** @var AbstractEnumValue[] $enumData */
$enumData = $manager->getRepository($className)->findAll();
foreach ($enumData as $enumItem) {
$this->addReference($enumItem->getName(), $enumItem);
}
}
示例9: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(['enum_code' => null, 'class' => null, 'query_builder' => function (EntityRepository $repo) {
return $repo->createQueryBuilder('o')->orderBy('o.priority');
}, 'property' => 'name', 'multiple' => null]);
$resolver->setNormalizers(['class' => function (Options $options, $value) {
return !empty($value) ? $value : ExtendHelper::buildEnumValueClassName($options['enum_code']);
}, 'multiple' => function (Options $options, $value) {
return $value !== null ? $value : $this->configManager->getProvider('enum')->getConfig($options['class'])->is('multiple');
}]);
}
示例10: setDefaultOptions
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$defaultFieldOptions = ['multiple' => true];
$resolver->setDefaults(['enum_code' => null, 'class' => null, 'field_options' => $defaultFieldOptions]);
$resolver->setNormalizers(['class' => function (Options $options, $value) {
return $value !== null ? $value : ExtendHelper::buildEnumValueClassName($options['enum_code']);
}, 'field_options' => function (Options $options, $value) use(&$defaultFieldOptions) {
$value['choices'] = $options['class'] !== null ? $this->getChoices($options['class'], $options['null_value']) : [];
return array_merge($defaultFieldOptions, $value);
}]);
}
示例11: load
/**
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
$className = ExtendHelper::buildEnumValueClassName('lead_source');
/** @var EnumValueRepository $enumRepo */
$enumRepo = $manager->getRepository($className);
$priority = 1;
foreach ($this->data as $name => $isDefault) {
$enumOption = $enumRepo->createEnumValue($name, $priority++, $isDefault);
$manager->persist($enumOption);
}
$manager->flush();
}
示例12: load
/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager)
{
$className = ExtendHelper::buildEnumValueClassName('mage_subscr_status');
/** @var EnumValueRepository $enumValueRepository */
$enumValueRepository = $manager->getRepository($className);
$priority = 1;
foreach ($this->data as $id => $name) {
$enumOption = $enumValueRepository->createEnumValue($name, $priority++, false, $id);
$manager->persist($enumOption);
}
$manager->flush();
}
示例13: initSupportingEntities
protected function initSupportingEntities(ObjectManager $manager = null)
{
if ($manager) {
$this->em = $manager;
}
$this->users = $this->em->getRepository('OroUserBundle:User')->findAll();
$this->countries = $this->em->getRepository('OroAddressBundle:Country')->findAll();
$className = ExtendHelper::buildEnumValueClassName('lead_source');
$enumRepo = $manager->getRepository($className);
$this->sources = $enumRepo->findAll();
$this->channel = $this->channelBuilderFactory->createBuilder()->setChannelType(DefaultChannelData::B2B_CHANNEL_TYPE)->setStatus(Channel::STATUS_ACTIVE)->setEntities()->getChannel();
$manager->persist($this->channel);
$manager->flush($this->channel);
}
示例14: init
/**
* {@inheritdoc}
*/
public function init($name, array $params)
{
$params[FilterUtility::FRONTEND_TYPE_KEY] = 'dictionary';
if (isset($params['class'])) {
$params[FilterUtility::FORM_OPTIONS_KEY]['class'] = $params['class'];
unset($params['class']);
}
if (isset($params['enum_code'])) {
$params[FilterUtility::FORM_OPTIONS_KEY] = ['enum_code' => $params['enum_code'], 'class' => ExtendHelper::buildEnumValueClassName($params['enum_code'])];
$params['class'] = ExtendHelper::buildEnumValueClassName($params['enum_code']);
unset($params['enum_code']);
}
parent::init($name, $params);
}
示例15: preUpdate
/**
* {@inheritdoc}
*
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function preUpdate()
{
$enumConfigProvider = $this->configManager->getProvider('enum');
$extendConfigProvider = $this->configManager->getProvider('extend');
$entityConfigs = $extendConfigProvider->getConfigs();
foreach ($entityConfigs as $entityConfig) {
if (!$entityConfig->is('is_extend')) {
continue;
}
$fieldConfigs = $extendConfigProvider->getConfigs($entityConfig->getId()->getClassName());
foreach ($fieldConfigs as $fieldConfig) {
if (!$fieldConfig->in('state', [ExtendScope::STATE_NEW, ExtendScope::STATE_UPDATE])) {
continue;
}
/** @var FieldConfigId $fieldConfigId */
$fieldConfigId = $fieldConfig->getId();
$fieldType = $fieldConfigId->getFieldType();
if (!in_array($fieldType, ['enum', 'multiEnum'])) {
continue;
}
// prepare input parameters
$fieldOptions = [];
$enumFieldConfig = $enumConfigProvider->getConfig($fieldConfigId->getClassName(), $fieldConfigId->getFieldName());
$enumCode = $enumFieldConfig->get('enum_code');
$enumName = $enumFieldConfig->get('enum_name');
$isPublic = $enumFieldConfig->get('enum_public');
if (empty($enumCode) && $isPublic && empty($enumName)) {
throw new \LogicException(sprintf('Both "enum_code" and "enum_name" cannot be empty for a public enum. Field: %s::%s.', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName()));
}
if (empty($enumCode)) {
$enumCode = $enumName !== null ? ExtendHelper::buildEnumCode($enumName) : ExtendHelper::generateEnumCode($fieldConfigId->getClassName(), $fieldConfigId->getFieldName());
$fieldOptions['enum']['enum_code'] = $enumCode;
}
$isMultiple = $this->fieldTypeHelper->getUnderlyingType($fieldType) === RelationType::MANY_TO_MANY;
$enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode);
// create an entity is used to store enum values
$this->createEnumValueConfigEntityModel($enumValueClassName, $enumCode, $isMultiple, $isPublic);
// create a relation
if ($isMultiple) {
$fieldOptions['extend']['without_default'] = true;
$this->relationBuilder->addManyToManyRelation($entityConfig, $enumValueClassName, $fieldConfigId->getFieldName(), ['name'], ['name'], ['name'], $fieldOptions, $fieldType);
} else {
$this->relationBuilder->addManyToOneRelation($entityConfig, $enumValueClassName, $fieldConfigId->getFieldName(), 'name', $fieldOptions, $fieldType);
}
}
}
}