本文整理匯總了PHP中Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper::getShortClassName方法的典型用法代碼示例。如果您正苦於以下問題:PHP ExtendHelper::getShortClassName方法的具體用法?PHP ExtendHelper::getShortClassName怎麽用?PHP ExtendHelper::getShortClassName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper
的用法示例。
在下文中一共展示了ExtendHelper::getShortClassName方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getEntityAlias
/**
* {@inheritdoc}
*/
public function getEntityAlias($entityClass)
{
if ($this->configManager->hasConfig($entityClass)) {
// check for enums
$enumCode = $this->configManager->getProvider('enum')->getConfig($entityClass)->get('code');
if ($enumCode) {
$entityAlias = $this->getEntityAliasFromConfig($entityClass);
if (null !== $entityAlias) {
return $entityAlias;
}
return $this->createEntityAlias(str_replace('_', '', $enumCode));
}
// check for dictionaries
$groups = $this->configManager->getProvider('grouping')->getConfig($entityClass)->get('groups');
if (!empty($groups) && in_array(GroupingScope::GROUP_DICTIONARY, $groups, true)) {
// delegate aliases generation to default provider
return null;
}
// exclude hidden entities
if ($this->configManager->isHiddenModel($entityClass)) {
return false;
}
// check for custom entities
if (ExtendHelper::isCustomEntity($entityClass)) {
$entityAlias = $this->getEntityAliasFromConfig($entityClass);
if (null !== $entityAlias) {
return $entityAlias;
}
return $this->createEntityAlias('Extend' . ExtendHelper::getShortClassName($entityClass));
}
}
return null;
}
示例2: updateEntity
/**
* @param EntityConfigEvent $event
*/
public function updateEntity(EntityConfigEvent $event)
{
$className = $event->getClassName();
$parentClassName = get_parent_class($className);
if (!$parentClassName) {
return;
}
if (ExtendHelper::isExtendEntityProxy($parentClassName)) {
// When application is installed parent class will be replaced (via class_alias)
$extendClass = $parentClassName;
} else {
// During install parent class is not replaced (via class_alias)
$shortClassName = ExtendHelper::getShortClassName($className);
if (ExtendHelper::getShortClassName($parentClassName) !== 'Extend' . $shortClassName) {
return;
}
$extendClass = ExtendHelper::getExtendEntityProxyClassName($parentClassName);
}
$configManager = $event->getConfigManager();
$config = $configManager->getProvider('extend')->getConfig($className);
$hasChanges = false;
if (!$config->is('is_extend')) {
$config->set('is_extend', true);
$hasChanges = true;
}
if (!$config->is('extend_class', $extendClass)) {
$config->set('extend_class', $extendClass);
$hasChanges = true;
}
if ($hasChanges) {
$configManager->persist($config);
}
}
示例3: testSetDefaultOptions
/**
* @dataProvider setDefaultOptionsProvider
*/
public function testSetDefaultOptions($enumCode, $class, $nullValue, $values, $fieldOptions, $expectedOptions)
{
$enumValueClassName = $class !== null ? $class : ExtendHelper::buildEnumValueClassName($enumCode);
if ($enumValueClassName) {
// AbstractEnumType require class to be instance of AbstractEnumValue
// This may be achieved with Stub. Stub namespace does not reflect Stub path.
// So we have to load it manually
$fileName = ExtendHelper::getShortClassName($enumValueClassName) . '.php';
require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . 'Stub' . DIRECTORY_SEPARATOR . $fileName);
$this->provider->expects($this->once())->method('getEnumChoices')->with($enumValueClassName)->will($this->returnValue($values));
}
$this->translator->expects($this->any())->method('trans')->with('oro.entity_extend.datagrid.enum.filter.empty')->will($this->returnValue('None'));
$resolver = $this->getOptionsResolver();
$this->type->setDefaultOptions($resolver);
$options = [];
if ($enumCode !== null) {
$options['enum_code'] = $enumCode;
}
if ($class !== null) {
$options['class'] = $class;
}
if ($nullValue !== null) {
$options['null_value'] = $nullValue;
}
if ($fieldOptions !== null) {
$options['field_options'] = $fieldOptions;
}
$resolvedOptions = $resolver->resolve($options);
$this->assertEquals($expectedOptions, $resolvedOptions);
}
示例4: updateEntityConfig
/**
* @param EntityConfigEvent $event
*/
public function updateEntityConfig(EntityConfigEvent $event)
{
$parentClassName = get_parent_class($event->getClassName());
if (!$parentClassName) {
return;
}
$shortClassName = ExtendHelper::getShortClassName($event->getClassName());
if (ExtendHelper::getShortClassName($parentClassName) !== 'Extend' . $shortClassName) {
return;
}
$config = $event->getConfigManager()->getProvider('extend')->getConfig($event->getClassName());
$hasChanges = false;
if (!$config->is('is_extend')) {
$config->set('is_extend', true);
$hasChanges = true;
}
$extendClass = ExtendHelper::getExtendEntityProxyClassName($parentClassName);
if (!$config->is('extend_class', $extendClass)) {
$config->set('extend_class', $extendClass);
$hasChanges = true;
}
if ($hasChanges) {
$event->getConfigManager()->persist($config);
}
}
示例5: generateSchemaFiles
/**
* Generate php and yml files for schema
*
* @param array $schema
*/
public function generateSchemaFiles(array $schema)
{
// generate PHP code
$class = PhpClass::create($schema['entity']);
foreach ($this->getExtensions() as $extension) {
if ($extension->supports($schema)) {
$extension->generate($schema, $class);
}
}
$className = ExtendHelper::getShortClassName($schema['entity']);
// write PHP class to the file
$strategy = new DefaultGeneratorStrategy();
file_put_contents($this->entityCacheDir . DIRECTORY_SEPARATOR . $className . '.php', "<?php\n\n" . $strategy->generate($class));
// write doctrine metadata in separate yaml file
file_put_contents($this->entityCacheDir . DIRECTORY_SEPARATOR . $className . '.orm.yml', Yaml::dump($schema['doctrine'], 5));
}
示例6: getWidgets
/**
* {@inheritdoc}
*/
public function getWidgets($object)
{
$result = [];
$entityClass = ClassUtils::getClass($object);
$entityId = $this->entityIdAccessor->getIdentifier($object);
$items = $this->activityManager->getActivityAssociations($entityClass);
foreach ($items as $item) {
if (empty($item['acl']) || $this->securityFacade->isGranted($item['acl'])) {
$url = $this->entityRoutingHelper->generateUrl($item['route'], $entityClass, $entityId);
$alias = sprintf('%s_%s_%s', strtolower(ExtendHelper::getShortClassName($item['className'])), dechex(crc32($item['className'])), $item['associationName']);
$widget = ['widgetType' => 'block', 'alias' => $alias, 'label' => $this->translator->trans($item['label']), 'url' => $url];
if (isset($item['priority'])) {
$widget['priority'] = $item['priority'];
}
$result[] = $widget;
}
}
return $result;
}
示例7: hasAssociationConfigs
/**
* {@inheritdoc}
*/
protected function hasAssociationConfigs(ClassMetadata $metadata, $associationName)
{
if ($this->isExtendField($metadata->name, $associationName)) {
return false;
}
// check for default field of oneToMany or manyToMany relation
if (strpos($associationName, ExtendConfigDumper::DEFAULT_PREFIX) === 0) {
$guessedName = substr($associationName, strlen(ExtendConfigDumper::DEFAULT_PREFIX));
if (!empty($guessedName) && $this->isExtendField($metadata->name, $guessedName)) {
return false;
}
}
// check for inverse side field of oneToMany relation
$targetClass = $metadata->getAssociationTargetClass($associationName);
$prefix = strtolower(ExtendHelper::getShortClassName($targetClass)) . '_';
if (strpos($associationName, $prefix) === 0) {
$guessedName = substr($associationName, strlen($prefix));
if (!empty($guessedName) && $this->isExtendField($targetClass, $guessedName)) {
return false;
}
}
return parent::hasAssociationConfigs($metadata, $associationName);
}
示例8: doTestSetDefaultOptions
protected function doTestSetDefaultOptions(AbstractEnumType $type, OptionsResolver $resolver, $enumCode, $multiple = false, $expanded = false, array $options = [])
{
$enumValueClassName = ExtendHelper::buildEnumValueClassName($enumCode);
// AbstractEnumType require class to be instance of AbstractEnumValue
// This may be achieved with Stub. Stub namespace does not reflect Stub path. So we have to load it manually
$fileName = ExtendHelper::getShortClassName($enumValueClassName) . '.php';
require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . 'Stub' . DIRECTORY_SEPARATOR . $fileName);
$enumConfig = new Config(new EntityConfigId('enum', $enumValueClassName));
$enumConfig->set('multiple', $multiple);
$enumConfigProvider = $this->getConfigProviderMock();
$this->configManager->expects($this->once())->method('getProvider')->with('enum')->will($this->returnValue($enumConfigProvider));
$enumConfigProvider->expects($this->once())->method('getConfig')->with($enumValueClassName)->will($this->returnValue($enumConfig));
$type->setDefaultOptions($resolver);
$resolvedOptions = $resolver->resolve(array_merge($options, ['enum_code' => $enumCode, 'expanded' => $expanded]));
$this->assertEquals($multiple, $resolvedOptions['multiple']);
$this->assertEquals($expanded, $resolvedOptions['expanded']);
$this->assertEquals($enumCode, $resolvedOptions['enum_code']);
$this->assertEquals($enumValueClassName, $resolvedOptions['class']);
$this->assertEquals('name', $resolvedOptions['property']);
$this->assertNotNull($resolvedOptions['query_builder']);
unset($resolvedOptions['multiple'], $resolvedOptions['expanded'], $resolvedOptions['enum_code'], $resolvedOptions['class'], $resolvedOptions['property'], $resolvedOptions['query_builder']);
return $resolvedOptions;
}
示例9: buildAssociationName
/**
* Returns a string that can be used as a field name to the relation to the given entity.
*
* To prevent name collisions this method adds a hash built based on the full class name
* and the kind of the association to the end.
*
* @param string $targetEntityClassName The association target class name
* @param string $associationKind The kind of the association
* For example 'activity', 'sponsorship' etc
* NULL for unclassified (default) association
*
* @return string
*/
public static function buildAssociationName($targetEntityClassName, $associationKind = null)
{
$hash = strtolower(dechex(crc32(empty($associationKind) ? $targetEntityClassName : $associationKind . $targetEntityClassName)));
return sprintf('%s_%s', Inflector::tableize(ExtendHelper::getShortClassName($targetEntityClassName)), $hash);
}
示例10: buildEnumCode
/**
* @param string $entityClassName
* @param string $fieldName
* @param string[] $existingEnumTables
*
* @return string
*/
protected function buildEnumCode($entityClassName, $fieldName, $existingEnumTables)
{
$nameGenerator = $this->extendExtension->getNameGenerator();
$enumCode = ExtendHelper::generateEnumCode($entityClassName, $fieldName, $nameGenerator->getMaxEnumCodeSize());
// check if an enum with that code is already exist and generate new code if so
while (in_array($nameGenerator->generateEnumTableName($enumCode), $existingEnumTables, true)) {
$enumCode = sprintf('enum_%s_%s', dechex(crc32(ExtendHelper::getShortClassName($entityClassName))), dechex(crc32(microtime())));
}
return $enumCode;
}
示例11: renameOneToManyExtendField
protected function renameOneToManyExtendField(Schema $schema, QueryBag $queries, Table $table, $associationName, $targetEntityClassName, EntityMetadataHelper $entityMetadataHelper)
{
$entityClassName = $entityMetadataHelper->getEntityClassByTableName($table->getName());
$targetTableName = $entityMetadataHelper->getTableNameByEntityClass($targetEntityClassName);
if ($schema->hasTable($targetTableName)) {
$targetTable = $schema->getTable($targetTableName);
$oldTargetColumnName = sprintf('field_%s_%s_id', strtolower(ExtendHelper::getShortClassName($entityClassName)), $associationName);
if ($targetTable->hasColumn($oldTargetColumnName)) {
$newTargetColumnName = $this->nameGenerator->generateOneToManyRelationColumnName($entityClassName, $associationName);
$oldIndexName = $this->nameGenerator->generateIndexName($targetTableName, [$oldTargetColumnName], false, true);
if ($targetTable->hasIndex($oldIndexName)) {
$targetTable->dropIndex($oldIndexName);
}
$oldForeignKeyName = $this->nameGenerator->generateForeignKeyConstraintName($targetTableName, [$oldTargetColumnName], true);
if ($targetTable->hasForeignKey($oldForeignKeyName)) {
$targetTable->removeForeignKey($oldForeignKeyName);
}
$this->renameExtension->renameColumn($schema, $queries, $targetTable, $oldTargetColumnName, $newTargetColumnName);
$this->renameExtension->addIndex($schema, $queries, $targetTable->getName(), [$newTargetColumnName]);
$this->renameExtension->addForeignKeyConstraint($schema, $queries, $targetTable->getName(), $table->getName(), [$newTargetColumnName], $table->getPrimaryKeyColumns(), ['onDelete' => 'SET NULL']);
}
}
}
示例12: generateIndexNameForExtendFieldVisibleInGrid
/**
* @param string $entityClassName
* @param string $fieldName
* @return string
*/
public function generateIndexNameForExtendFieldVisibleInGrid($entityClassName, $fieldName)
{
$entityClassName = ExtendHelper::getShortClassName($entityClassName);
// remove ending underscore (_) char
$prefix = substr(self::CUSTOM_INDEX_PREFIX, 0, -1);
return $this->generateIdentifierName($entityClassName, [$fieldName], $prefix, false);
}
示例13: testGetShortClassName
/**
* @dataProvider getShortClassNameProvider
*/
public function testGetShortClassName($className, $expected)
{
$this->assertEquals($expected, ExtendHelper::getShortClassName($className));
}