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


PHP ExtendHelper::buildEnumValueId方法代码示例

本文整理汇总了PHP中Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper::buildEnumValueId方法的典型用法代码示例。如果您正苦于以下问题:PHP ExtendHelper::buildEnumValueId方法的具体用法?PHP ExtendHelper::buildEnumValueId怎么用?PHP ExtendHelper::buildEnumValueId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper的用法示例。


在下文中一共展示了ExtendHelper::buildEnumValueId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCreateEnumValueWithoutId

 public function testCreateEnumValueWithoutId()
 {
     $result = $this->repo->createEnumValue('Test Value 1', 1, true);
     $this->assertInstanceOf(self::ENUM_VALUE_CLASS_NAME, $result);
     $this->assertEquals(ExtendHelper::buildEnumValueId('Test Value 1'), $result->getId());
     $this->assertEquals('Test Value 1', $result->getName());
     $this->assertEquals(1, $result->getPriority());
     $this->assertTrue($result->isDefault());
 }
开发者ID:ramunasd,项目名称:platform,代码行数:9,代码来源:EnumValueRepositoryTest.php

示例2: createEnumValue

 /**
  * Creates an entity represents an enum value
  *
  * @param string      $name     The enum value name
  * @param int         $priority An number used to sort enum values on UI.
  *                              Values with less priority is rendered at the top
  * @param boolean     $default  Determines if this value is selected by default for new records
  * @param string|null $id       The enum value identifier. If not specified it is generated
  *                              automatically based on the given name. Usually it is the same as name,
  *                              but spaces are replaced with underscore and result is converted to lower case.
  *                              As the id length is limited to 32 characters, in case if the name is longer then
  *                              some hashing function is used to generate the id.
  *
  * @return AbstractEnumValue
  *
  * @throws \InvalidArgumentException
  */
 public function createEnumValue($name, $priority, $default, $id = null)
 {
     if (empty($name)) {
         throw new \InvalidArgumentException('$name must not be empty.');
     }
     if (empty($id)) {
         $id = ExtendHelper::buildEnumValueId($name);
     } elseif (strlen($id) > ExtendHelper::MAX_ENUM_VALUE_ID_LENGTH) {
         throw new \InvalidArgumentException(sprintf('$id length must be less or equal %d characters. id: %s.', ExtendHelper::MAX_ENUM_VALUE_ID_LENGTH, $id));
     }
     $enumValueClassName = $this->getClassName();
     return new $enumValueClassName($id, $name, $priority, $default);
 }
开发者ID:northdakota,项目名称:platform,代码行数:30,代码来源:EnumValueRepository.php

示例3: validate

 /**
  * {@inheritdoc}
  */
 public function validate($entity, Constraint $constraint)
 {
     if ($entity instanceof EnumValueEntity) {
         $entity = $entity->toArray();
     }
     if (!is_array($entity)) {
         throw new UnexpectedTypeException($entity, 'Oro\\Bundle\\EntityExtendBundle\\Model\\EnumValue|array');
     }
     if (!empty($entity['id']) || empty($entity['label'])) {
         return;
     }
     $valueId = ExtendHelper::buildEnumValueId($entity['label'], false);
     if (empty($valueId)) {
         $this->context->addViolationAt('[label]', $constraint->message, ['{{ value }}' => $entity['label']]);
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:19,代码来源:EnumValueValidator.php

示例4: postSetData

 /**
  * POST_SET_DATA event handler
  *
  * @param FormEvent $event
  */
 public function postSetData(FormEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     $constraints = [new Assert\NotBlank(), new Assert\Length(['max' => 255])];
     if (empty($data['id'])) {
         $callback = function ($value, ExecutionContextInterface $context) {
             if (!empty($value)) {
                 $id = ExtendHelper::buildEnumValueId($value, false);
                 if (empty($id)) {
                     $context->addViolation(self::INVALID_NAME_MESSAGE, ['{{ value }}' => $value]);
                 }
             }
         };
         $constraints[] = new Assert\Callback([$callback]);
     }
     $form->add('label', 'text', ['required' => true, 'constraints' => $constraints]);
 }
开发者ID:northdakota,项目名称:platform,代码行数:23,代码来源:EnumValueType.php

示例5: fillEnumValues

 /**
  * @param QueryBag $queries
  * @param array    $optionSets
  */
 protected function fillEnumValues(QueryBag $queries, array &$optionSets)
 {
     foreach ($optionSets as &$optionSet) {
         $query = sprintf('INSERT INTO %s (id, name, priority, is_default) ' . 'VALUES (:id, :name, :priority, :is_default)', $optionSet['enum_table_name']);
         foreach ($optionSet['values'] as &$option) {
             $option['enum_value_id'] = ExtendHelper::buildEnumValueId($option['label']);
             $params = ['id' => $option['enum_value_id'], 'name' => $option['label'], 'priority' => $option['priority'], 'is_default' => $option['is_default']];
             $types = ['id' => 'string', 'name' => 'string', 'priority' => 'integer', 'is_default' => 'boolean'];
             $queries->addPostQuery(new ParametrizedSqlMigrationQuery($query, $params, $types));
         }
     }
 }
开发者ID:snorchel,项目名称:platform,代码行数:16,代码来源:MigrateOptionSetsToEnums.php

示例6: generateEnumValueId

 /**
  * @param string   $name
  * @param string[] $existingIds
  *
  * @return string
  */
 protected function generateEnumValueId($name, array $existingIds)
 {
     $id = ExtendHelper::buildEnumValueId($name);
     if (in_array($id, $existingIds, true)) {
         $prefix = substr($id, 0, ExtendHelper::MAX_ENUM_VALUE_ID_LENGTH - 6) . '_';
         $counter = 1;
         $id = $prefix . $counter;
         while (in_array($id, $existingIds, true)) {
             $counter++;
             $id = $prefix . $counter;
         }
     }
     return $id;
 }
开发者ID:sagikazarmark,项目名称:platform,代码行数:20,代码来源:EnumSynchronizer.php

示例7: testBuildEnumValueIdForInvalidEnumValueNameIgnoreException

 /**
  * @dataProvider buildEnumValueIdForInvalidEnumValueNameProvider
  */
 public function testBuildEnumValueIdForInvalidEnumValueNameIgnoreException($enumValueName)
 {
     $this->assertSame('', ExtendHelper::buildEnumValueId($enumValueName, false));
 }
开发者ID:snorchel,项目名称:platform,代码行数:7,代码来源:ExtendHelperTest.php


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