本文整理汇总了PHP中Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigProvider::filter方法的具体用法?PHP ConfigProvider::filter怎么用?PHP ConfigProvider::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider
的用法示例。
在下文中一共展示了ConfigProvider::filter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTemplateVariables
/**
* Return available in template variables
*
* @param string $entityName
* @return array
*/
public function getTemplateVariables($entityName)
{
$userClassName = $this->getUser() ? get_class($this->getUser()) : false;
$allowedData = array('entity' => array(), 'user' => array());
$ids = $this->configProvider->getIds();
foreach ($ids as $entityConfigId) {
// export variables of asked entity and current user entity class
$className = $entityConfigId->getClassName();
if ($className == $entityName || $className == $userClassName) {
$fields = $this->configProvider->filter(function (ConfigInterface $config) {
return $config->is('available_in_template');
}, $className);
$fields = array_values(array_map(function (ConfigInterface $field) {
return $field->getId()->getFieldName();
}, $fields));
switch ($className) {
case $entityName:
$allowedData['entity'] = $fields;
break;
case $userClassName:
$allowedData['user'] = $fields;
break;
}
if ($entityName == $userClassName) {
$allowedData['user'] = $allowedData['entity'];
}
}
}
return $allowedData;
}
示例2: resolve
/**
* {@inheritdoc}
*/
public function resolve(Route $route, RouteCollectionAccessor $routes)
{
if ($route->getOption('group') !== self::ROUTE_GROUP) {
return;
}
if ($this->hasAttribute($route, self::ACTIVITY_PLACEHOLDER)) {
$activities = array_map(function (ConfigInterface $config) {
// convert to entity alias
return $this->entityAliasResolver->getPluralAlias($config->getId()->getClassName());
}, $this->groupingConfigProvider->filter(function (ConfigInterface $config) {
// filter activity entities
$groups = $config->get('groups');
return !empty($groups) && in_array(ActivityScope::GROUP_ACTIVITY, $groups, true);
}));
if (!empty($activities)) {
$activities = $this->adjustRoutes($route, $routes, $activities);
if (!empty($activities)) {
$route->setRequirement(self::ACTIVITY_ATTRIBUTE, implode('|', $activities));
}
}
$this->completeRouteRequirements($route);
} elseif ($this->hasAttribute($route, self::ENTITY_PLACEHOLDER)) {
$this->completeRouteRequirements($route);
}
}
示例3: getEntityActivityContactFields
/**
* @param object $entity
*
* @return ConfigInterface[]
*/
protected function getEntityActivityContactFields($entity)
{
$fields = array_keys(ActivityScope::$fieldsConfiguration);
return $this->extendProvider->filter(function (ConfigInterface $config) use($fields) {
/** @var FieldConfigId $fieldConfigId */
$fieldConfigId = $config->getId();
return in_array($fieldConfigId->getFieldName(), $fields);
}, ClassUtils::getClass($entity));
}
示例4: getSupportedActivities
/**
* @return string[]
*/
protected function getSupportedActivities()
{
if (null === $this->supportedActivities) {
$this->supportedActivities = array_map(function (ConfigInterface $config) {
// convert to entity alias
return $this->entityAliasResolver->getPluralAlias($config->getId()->getClassName());
}, $this->groupingConfigProvider->filter(function (ConfigInterface $config) {
// filter activity entities
$groups = $config->get('groups');
return !empty($groups) && in_array(ActivityScope::GROUP_ACTIVITY, $groups, true);
}));
}
return $this->supportedActivities;
}
示例5: testFilter
public function testFilter()
{
$this->configManager->expects($this->once())->method('getConfigs')->with('testScope', DemoEntity::ENTITY_NAME, false)->will($this->returnValue(array($this->entityConfig)));
$this->assertEquals(array(), $this->configProvider->filter(function (ConfigInterface $config) {
return $config->getId()->getScope() == 'wrongScope';
}, DemoEntity::ENTITY_NAME));
}
示例6: getPropertyChoiceList
/**
* @return array
*/
protected function getPropertyChoiceList()
{
$choices = array();
if (!$this->entityClass) {
return $choices;
}
$fields = $this->configProvider->filter(function (Config $config) {
return in_array($config->getId()->getFieldType(), ['integer', 'string', 'smallint', 'decimal', 'bigint', 'text', 'money']) && $config->is('is_deleted', false);
}, $this->entityClass);
$entityConfigProvider = $this->configProvider->getConfigManager()->getProvider('entity');
foreach ($fields as $field) {
$label = $entityConfigProvider->getConfigById($field->getId())->get('label');
$choices[$field->getId()->getFieldName()] = $label ?: $field->getId()->getFieldName();
}
return $choices;
}
示例7: prepareConfiguration
/**
* Prepare configuration from entity config
*
* @return array
*/
private function prepareConfiguration()
{
$configuration = array();
foreach ($this->configProvider->getIds() as $entityConfigId) {
$className = $entityConfigId->getClassName();
$fields = $this->configProvider->filter(function (ConfigInterface $fieldConfig) {
return $fieldConfig->is('available_in_template');
}, $className);
if (count($fields)) {
$configuration[$className] = array();
foreach ($fields as $fieldConfig) {
$configuration[$className][] = 'get' . strtolower($fieldConfig->getId()->getFieldName());
}
}
}
return $configuration;
}
示例8: getActivityTypes
/**
* Returns the list of FQCN of all activity entities
*
* @return string[]
*/
public function getActivityTypes()
{
return array_values(array_map(function (ConfigInterface $config) {
return $config->getId()->getClassName();
}, $this->groupingConfigProvider->filter(function (ConfigInterface $config) {
// filter activity entities
$groups = $config->get('groups');
return !empty($groups) && in_array(ActivityScope::GROUP_ACTIVITY, $groups, true);
})));
}
示例9: getFields
/**
* @param object $entity
* @param null|string $entityClass
* @return array
*/
public function getFields($entity, $entityClass = null)
{
$dynamicRow = [];
$priorities = [];
if (null === $entityClass) {
$entityClass = ClassUtils::getRealClass($entity);
}
$fields = $this->extendProvider->filter([$this, 'filterFields'], $entityClass);
foreach ($fields as $field) {
/** @var FieldConfigId $fieldConfigId */
$fieldConfigId = $field->getId();
$fieldName = $fieldConfigId->getFieldName();
$fieldType = $fieldConfigId->getFieldType();
$value = $this->propertyAccessor->getValue($entity, $fieldName);
$event = new ValueRenderEvent($entity, $value, $fieldConfigId);
$this->eventDispatcher->dispatch(EntityExtendEvents::BEFORE_VALUE_RENDER, $event);
$fieldConfig = $this->entityProvider->getConfigById($fieldConfigId);
$dynamicRow[$fieldName] = ['type' => $fieldType, 'label' => $fieldConfig->get('label') ?: $fieldName, 'value' => $event->getFieldViewValue()];
$priorities[] = $this->viewProvider->getConfigById($fieldConfigId)->get('priority', false, 0);
}
array_multisort($priorities, SORT_DESC, $dynamicRow);
return $dynamicRow;
}
示例10: testGetConfigs
public function testGetConfigs()
{
$this->configManager->expects($this->exactly(4))->method('getIds')->with('testScope', DemoEntity::ENTITY_NAME)->will($this->returnValue(array($this->entityConfig->getId())));
$this->assertEquals(array($this->entityConfig->getId()), $this->configProvider->getIds(DemoEntity::ENTITY_NAME));
$this->assertEquals(array($this->entityConfig), $this->configProvider->getConfigs(DemoEntity::ENTITY_NAME));
$this->assertEquals(array(), $this->configProvider->filter(function (ConfigInterface $config) {
return $config->getId()->getScope() == 'wrongScope';
}, DemoEntity::ENTITY_NAME));
$entityConfig = new Config(new EntityConfigId(DemoEntity::ENTITY_NAME, 'testScope'));
$entityConfig->set('key', 'value');
$this->assertEquals(array($entityConfig), $this->configProvider->map(function (ConfigInterface $config) {
return $config->set('key', 'value');
}, DemoEntity::ENTITY_NAME));
}
示例11: checkSchema
/**
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @param ConfigInterface $extendConfig
* @param array|null $aliases
* @param array|null $skippedOrigins
*/
protected function checkSchema(ConfigInterface $extendConfig, $aliases, array $skippedOrigins = null)
{
$className = $extendConfig->getId()->getClassName();
$doctrine = [];
$entityName = $className;
if (ExtendHelper::isCustomEntity($className)) {
$type = 'Custom';
$tableName = $extendConfig->get('table');
if (!$tableName) {
$tableName = $this->nameGenerator->generateCustomEntityTableName($className);
}
$doctrine[$entityName] = ['type' => 'entity', 'table' => $tableName];
// add 'id' field only for Custom entity without inheritance
if (!$extendConfig->has('inherit')) {
$doctrine[$entityName]['fields'] = ['id' => ['type' => 'integer', 'id' => true, 'generator' => ['strategy' => 'AUTO']]];
}
} else {
$type = 'Extend';
$entityName = $extendConfig->get('extend_class');
$doctrine[$entityName] = ['type' => 'mappedSuperclass', 'fields' => []];
}
$schema = $extendConfig->get('schema');
$properties = [];
$relationProperties = $schema ? $schema['relation'] : [];
$defaultProperties = [];
$addRemoveMethods = [];
$fieldConfigs = $this->configProvider->filter($this->createOriginFilterCallback($skippedOrigins), $className, true);
foreach ($fieldConfigs as $fieldConfig) {
$this->checkFields($entityName, $fieldConfig, $relationProperties, $defaultProperties, $properties, $doctrine);
$this->configProvider->persist($fieldConfig);
}
$relations = $extendConfig->get('relation', false, []);
foreach ($relations as $relation) {
/** @var FieldConfigId $fieldId */
$fieldId = $relation['field_id'];
if (!$fieldId) {
continue;
}
$fieldName = $fieldId->getFieldName();
if (!isset($relationProperties[$fieldName])) {
$relationProperties[$fieldName] = $fieldName;
}
if ($fieldId->getFieldType() !== RelationType::MANY_TO_ONE) {
$addRemoveMethods[$fieldName]['self'] = $fieldName;
/** @var FieldConfigId $targetFieldId */
$targetFieldId = $relation['target_field_id'];
if ($targetFieldId) {
$fieldType = $fieldId->getFieldType();
$addRemoveMethods[$fieldName]['target'] = $targetFieldId->getFieldName();
$addRemoveMethods[$fieldName]['is_target_addremove'] = $fieldType === RelationType::MANY_TO_MANY;
}
}
}
$schema = ['class' => $className, 'entity' => $entityName, 'type' => $type, 'property' => $properties, 'relation' => $relationProperties, 'default' => $defaultProperties, 'addremove' => $addRemoveMethods, 'doctrine' => $doctrine];
if ($type === 'Extend') {
$parentClassName = get_parent_class($className);
if ($parentClassName === $entityName) {
$parentClassName = $aliases[$entityName];
}
$schema['parent'] = $parentClassName;
$schema['inherit'] = get_parent_class($parentClassName);
} elseif ($extendConfig->has('inherit')) {
$schema['inherit'] = $extendConfig->get('inherit');
}
$extendConfig->set('schema', $schema);
$this->configProvider->persist($extendConfig);
}