Skip to content

Commit

Permalink
Adjust renamed "short_name" to "shortName" (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 11, 2022
1 parent fee2638 commit 7e12b6c
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion docs/persistence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Your init() method for a Field_Currency might look like this::

$this->never_persist = true;

$f = $this->short_name; // balance
$f = $this->shortName; // balance

$this->getOwner()->addField(
$f.'_amount',
Expand Down
20 changes: 10 additions & 10 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getTypeObject(): Type

protected function onHookToOwnerEntity(string $spot, \Closure $fx, array $args = [], int $priority = 5): int
{
$name = $this->short_name; // use static function to allow this object to be GCed
$name = $this->shortName; // use static function to allow this object to be GCed

return $this->getOwner()->onHookDynamic(
$spot,
Expand Down Expand Up @@ -279,7 +279,7 @@ public function normalize($value)
$messages[] = $e->getMessage();
} while ($e = $e->getPrevious());

throw (new ValidationException([$this->short_name => implode(': ', $messages)], $this->getOwner()))
throw (new ValidationException([$this->shortName => implode(': ', $messages)], $this->getOwner()))
->addMoreInfo('field', $this);
}
}
Expand All @@ -303,7 +303,7 @@ final public function get(Model $entity)
{
$entity->assertIsEntity($this->getOwner());

return $entity->get($this->short_name);
return $entity->get($this->shortName);
}

/**
Expand All @@ -315,7 +315,7 @@ final public function set(Model $entity, $value): self
{
$entity->assertIsEntity($this->getOwner());

$entity->set($this->short_name, $value);
$entity->set($this->shortName, $value);

return $this;
}
Expand All @@ -327,7 +327,7 @@ final public function setNull(Model $entity): self
{
$entity->assertIsEntity($this->getOwner());

$entity->setNull($this->short_name);
$entity->setNull($this->shortName);

return $this;
}
Expand Down Expand Up @@ -389,7 +389,7 @@ public function getReference(): ?Reference

public function getPersistenceName(): string
{
return $this->actual ?? $this->short_name;
return $this->actual ?? $this->shortName;
}

/**
Expand Down Expand Up @@ -422,7 +422,7 @@ public function getQueryArguments($operator, $value): array
], true)) {
$typecastField = new self(['type' => 'string']);
$typecastField->setOwner(new Model($this->getOwner()->persistence, ['table' => false]));
$typecastField->short_name = $this->short_name;
$typecastField->shortName = $this->shortName;
$allowArray = false;
}

Expand Down Expand Up @@ -470,7 +470,7 @@ public function isHidden(): bool
*/
public function getCaption(): string
{
return $this->caption ?? $this->ui['caption'] ?? $this->readableCaption($this->short_name);
return $this->caption ?? $this->ui['caption'] ?? $this->readableCaption($this->shortName);
}

// }}}
Expand All @@ -493,8 +493,8 @@ public function getDsqlExpression(Expression $expression): Expression
public function __debugInfo(): array
{
$arr = [
'owner_class' => get_class($this->getOwner()),
'short_name' => $this->short_name,
'ownerClass' => get_class($this->getOwner()),
'shortName' => $this->shortName,
'type' => $this->type,
];

Expand Down
2 changes: 1 addition & 1 deletion src/Field/CallbackField.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function init(): void
$this->ui['table']['sortable'] = false;

$this->onHookToOwnerEntity(Model::HOOK_AFTER_LOAD, function (Model $entity) {
$entity->getDataRef()[$this->short_name] = ($this->expr)($entity);
$entity->getDataRef()[$this->shortName] = ($this->expr)($entity);
});
}
}
6 changes: 3 additions & 3 deletions src/Field/EmailField.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ public function normalize($value)
}

if (strpos($email, '@') === false) {
throw new ValidationException([$this->short_name => 'Email address does not have domain'], $this->getOwner());
throw new ValidationException([$this->shortName => 'Email address does not have domain'], $this->getOwner());
}

[$user, $domain] = explode('@', $email, 2);
$domain = idn_to_ascii($domain, \IDNA_DEFAULT, \INTL_IDNA_VARIANT_UTS46); // always convert domain to ASCII

if (!filter_var($user . '@' . $domain, \FILTER_VALIDATE_EMAIL)) {
throw new ValidationException([$this->short_name => 'Email address format is invalid'], $this->getOwner());
throw new ValidationException([$this->shortName => 'Email address format is invalid'], $this->getOwner());
}

if ($this->dns_check) {
if (!$this->hasAnyDnsRecord($domain)) {
throw new ValidationException([$this->short_name => 'Email address domain does not exist'], $this->getOwner());
throw new ValidationException([$this->shortName => 'Email address domain does not exist'], $this->getOwner());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Field/PasswordField.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function verifyPassword(Model $entity, string $password): bool
$v = $this->get($entity);
if ($v === null) {
throw (new Exception('Password hash is null, verification is impossible'))
->addMoreInfo('field', $this->short_name);
->addMoreInfo('field', $this->shortName);
}

return $this->hashPasswordVerify($v, $password);
Expand Down
20 changes: 10 additions & 10 deletions src/Model/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ protected function createFakeForeignModel(): Model
'table' => $this->foreign_table,
]);
foreach ($this->getOwner()->getFields() as $ownerField) {
if ($ownerField->hasJoin() && $ownerField->getJoin()->short_name === $this->short_name
&& $ownerField->short_name !== $fakeModel->id_field
&& $ownerField->short_name !== $this->foreign_field) {
$fakeModel->addField($ownerField->short_name, [
if ($ownerField->hasJoin() && $ownerField->getJoin()->shortName === $this->shortName
&& $ownerField->shortName !== $fakeModel->id_field
&& $ownerField->shortName !== $this->foreign_field) {
$fakeModel->addField($ownerField->shortName, [
'actual' => $ownerField->actual,
'type' => $ownerField->type,
]);
Expand Down Expand Up @@ -160,7 +160,7 @@ public function setOwner(object $owner)

protected function onHookToOwnerBoth(string $spot, \Closure $fx, array $args = [], int $priority = 5): int
{
$name = $this->short_name; // use static function to allow this object to be GCed
$name = $this->shortName; // use static function to allow this object to be GCed

return $this->getOwner()->onHookDynamic(
$spot,
Expand All @@ -179,7 +179,7 @@ static function (Model $model) use ($name): self {

protected function onHookToOwnerEntity(string $spot, \Closure $fx, array $args = [], int $priority = 5): int
{
$name = $this->short_name; // use static function to allow this object to be GCed
$name = $this->shortName; // use static function to allow this object to be GCed

return $this->getOwner()->onHookDynamic(
$spot,
Expand Down Expand Up @@ -284,7 +284,7 @@ protected function initJoinHooks(): void
*/
public function addField(string $name, array $seed = []): Field
{
$seed['joinName'] = $this->short_name;
$seed['joinName'] = $this->shortName;

return $this->getOwner()->addField($this->prefix . $name, $seed);
}
Expand Down Expand Up @@ -315,7 +315,7 @@ public function addFields(array $fields = [], array $defaults = [])
*/
public function join(string $foreignTable, array $defaults = []): self
{
$defaults['joinName'] = $this->short_name;
$defaults['joinName'] = $this->shortName;

return $this->getOwner()->join($foreignTable, $defaults);
}
Expand All @@ -327,7 +327,7 @@ public function join(string $foreignTable, array $defaults = []): self
*/
public function leftJoin(string $foreignTable, array $defaults = []): self
{
$defaults['joinName'] = $this->short_name;
$defaults['joinName'] = $this->shortName;

return $this->getOwner()->leftJoin($foreignTable, $defaults);
}
Expand All @@ -339,7 +339,7 @@ public function leftJoin(string $foreignTable, array $defaults = []): self
*/
public function hasOne(string $link, array $defaults = [])
{
$defaults['joinName'] = $this->short_name;
$defaults['joinName'] = $this->shortName;

return $this->getOwner()->hasOne($link, $defaults);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/JoinLinkTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getJoin(): Join

public function setJoin(Join $join): self
{
$this->joinName = $join->short_name;
$this->joinName = $join->shortName;

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function __clone()
$this->elements[$k]->unsetOwner();
}
$this->elements[$k]->setOwner($this);
$this->elements[$k]->short_name = $nestedCondition->short_name;
$this->elements[$k]->shortName = $nestedCondition->shortName;
}
if ($this->issetOwner()) {
$this->unsetOwner();
}
$this->short_name = null; // @phpstan-ignore-line
$this->shortName = null; // @phpstan-ignore-line
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Scope/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function __construct($key, $operator = null, $value = null)
if ($key instanceof AbstractScope) {
throw new Exception('Only Scope can contain another conditions');
} elseif ($key instanceof Field) { // for BC
$key = $key->short_name;
$key = $key->shortName;
} elseif (!is_string($key) && !($key instanceof Expressionable)) {
throw new Exception('Field must be a string or an instance of Expressionable');
}
Expand Down Expand Up @@ -163,7 +163,7 @@ protected function onChangeModel(): void
// TODO Model/field should not be mutated, see:
// https://github.com/atk4/data/issues/662
// for now, do not set default at least for PK/ID
if ($field instanceof Field && $field->short_name !== $field->getOwner()->id_field) {
if ($field instanceof Field && $field->shortName !== $field->getOwner()->id_field) {
$field->system = true;
$field->default = $this->value;
}
Expand Down Expand Up @@ -384,7 +384,7 @@ protected function valueToWords(Model $model, $value): string
if ($field instanceof Field && $field->getReference() !== null) {
// make sure we set the value in the Model
$model = $model->isEntity() ? clone $model : $model->createEntity();
$model->set($field->short_name, $value);
$model->set($field->shortName, $value);

// then take the title
$title = $model->ref($field->getReference()->link)->getTitle();
Expand Down
4 changes: 2 additions & 2 deletions src/Model/UserAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function execute(...$args)

$run = function () use ($args) {
if ($this->callback === null) {
$fx = [$this->getEntity(), $this->short_name];
$fx = [$this->getEntity(), $this->shortName];
} elseif (is_string($this->callback)) {
$fx = [$this->getEntity(), $this->callback];
} else {
Expand Down Expand Up @@ -254,6 +254,6 @@ public function getConfirmation()

public function getCaption(): string
{
return $this->caption ?? ucwords(str_replace('_', ' ', $this->short_name));
return $this->caption ?? ucwords(str_replace('_', ' ', $this->shortName));
}
}
4 changes: 2 additions & 2 deletions src/Persistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function typecastSaveField(Field $field, $value)
return $v;
} catch (\Exception $e) {
throw (new Exception('Typecast save error', 0, $e))
->addMoreInfo('field', $field->short_name);
->addMoreInfo('field', $field->shortName);
}
}

Expand All @@ -370,7 +370,7 @@ public function typecastLoadField(Field $field, $value)
return $this->_typecastLoadField($field, $value);
} catch (\Exception $e) {
throw (new Exception('Typecast parse error', 0, $e))
->addMoreInfo('field', $field->short_name);
->addMoreInfo('field', $field->shortName);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Persistence/Array_/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function match(array $row, Model\Scope\AbstractScope $condition): bool
->addMoreInfo('condition', $condition);
}

return $this->evaluateIf($row[$field->short_name] ?? null, $operator, $value);
return $this->evaluateIf($row[$field->shortName] ?? null, $operator, $value);
} elseif ($condition instanceof Model\Scope) { // nested conditions
$matches = [];

Expand Down
8 changes: 4 additions & 4 deletions src/Persistence/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function initWithCursors(Model $model, Query $query): void
*/
public function initField(Query $query, Field $field): void
{
$query->field($field, $field->useAlias() ? $field->short_name : null);
$query->field($field, $field->useAlias() ? $field->shortName : null);
}

/**
Expand Down Expand Up @@ -413,7 +413,7 @@ public function action(Model $model, string $type, array $args = [])
if (isset($args['alias'])) {
$query->reset('field')->field($field, $args['alias']);
} elseif ($field instanceof SqlExpressionField) {
$query->reset('field')->field($field, $field->short_name);
$query->reset('field')->field($field, $field->shortName);
} else {
$query->reset('field')->field($field);
}
Expand Down Expand Up @@ -449,7 +449,7 @@ public function action(Model $model, string $type, array $args = [])
if (isset($args['alias'])) {
$query->reset('field')->field($query->expr($expr, [$field]), $args['alias']);
} elseif ($field instanceof SqlExpressionField) {
$query->reset('field')->field($query->expr($expr, [$field]), $fx . '_' . $field->short_name);
$query->reset('field')->field($query->expr($expr, [$field]), $fx . '_' . $field->shortName);
} else {
$query->reset('field')->field($query->expr($expr, [$field]));
}
Expand Down Expand Up @@ -638,7 +638,7 @@ public function getFieldSqlExpression(Field $field, Expression $expression): Exp
$mask = '{{}}.{}';
$prop = [
$field->hasJoin()
? ($field->getJoin()->foreign_alias ?: $field->getJoin()->short_name)
? ($field->getJoin()->foreign_alias ?: $field->getJoin()->shortName)
: ($field->getOwner()->table_alias ?? (is_object($field->getOwner()->table) ? '_tm' : $field->getOwner()->table)),
$field->getPersistenceName(),
];
Expand Down
14 changes: 7 additions & 7 deletions src/Persistence/Sql/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function init(): void

// our short name will be unique
if (!$this->foreign_alias) {
$this->foreign_alias = ($this->getOwner()->table_alias ?: '') . $this->short_name;
$this->foreign_alias = ($this->getOwner()->table_alias ?: '') . $this->shortName;
}

// Master field indicates ID of the joined item. In the past it had to be
Expand All @@ -46,7 +46,7 @@ protected function init(): void

$field = $owner->addField($this->master_field, ['system' => true, 'read_only' => true]);

$this->master_field = $field->short_name;
$this->master_field = $field->shortName;
}
}

Expand Down Expand Up @@ -87,21 +87,21 @@ public function initSelectQuery(Model $model, Query $query): void

/*
if ($this->reverse) {
$query->field([$this->short_name => (
$query->field([$this->shortName => (
$this->join ?: ($model->table_alias ?: $model->table) . '.' . $this->master_field
)]);
} else {
$query->field([$this->short_name => $this->foreign_alias . '.' . $this->foreign_field]);
$query->field([$this->shortName => $this->foreign_alias . '.' . $this->foreign_field]);
}
*/
}

public function afterLoad(Model $entity): void
{
// we need to collect ID
if (isset($entity->getDataRef()[$this->short_name])) {
$this->setId($entity, $entity->getDataRef()[$this->short_name]);
unset($entity->getDataRef()[$this->short_name]);
if (isset($entity->getDataRef()[$this->shortName])) {
$this->setId($entity, $entity->getDataRef()[$this->shortName]);
unset($entity->getDataRef()[$this->shortName]);
}
}
}
2 changes: 1 addition & 1 deletion src/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getTheirFieldName(): string

protected function onHookToOurModel(Model $model, string $spot, \Closure $fx, array $args = [], int $priority = 5): int
{
$name = $this->short_name; // use static function to allow this object to be GCed
$name = $this->shortName; // use static function to allow this object to be GCed

return $model->onHookDynamic(
$spot,
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function setModel(Model $model): Model
continue;
}

if ($field->short_name === $model->id_field) {
if ($field->shortName === $model->id_field) {
$refype = self::REF_TYPE_PRIMARY;
$persistField = $field;
} else {
Expand Down

0 comments on commit 7e12b6c

Please sign in to comment.