本文整理汇总了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());
}
示例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);
}
示例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']]);
}
}
示例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]);
}
示例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));
}
}
}
示例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;
}
示例7: testBuildEnumValueIdForInvalidEnumValueNameIgnoreException
/**
* @dataProvider buildEnumValueIdForInvalidEnumValueNameProvider
*/
public function testBuildEnumValueIdForInvalidEnumValueNameIgnoreException($enumValueName)
{
$this->assertSame('', ExtendHelper::buildEnumValueId($enumValueName, false));
}