Skip to content

Commit

Permalink
Remove NameTrait from TrackableTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 10, 2022
1 parent 7a36cc0 commit 07e3467
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions docs/initializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Declare a object class in your framework::

class FormField {
use AppScopeTrait;
use TrackableTrait;
use InitializerTrait;

use NameTrait;
use TrackableTrait;
}

class FormField_Input extends FormField {
Expand Down Expand Up @@ -51,10 +51,11 @@ class::

class FormField {
use AppScopeTrait;
use TrackableTrait;
use InitializerTrait {
init as _init
}
use TrackableTrait;
use NameTrait;

public $value = null;

Expand Down
2 changes: 1 addition & 1 deletion src/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function _addIntoCollection(string $name, object $item, string $collectio
if (TraitUtil::hasTrackableTrait($item)) {
$item->short_name = $name;
$item->setOwner($this);
if (TraitUtil::hasTrackableTrait($this)) {
if (TraitUtil::hasTrackableTrait($this) && TraitUtil::hasNameTrait($this) && TraitUtil::hasNameTrait($item)) {
$item->name = $this->_shorten_ml($this->name . '-' . $collection, $item->short_name, $item->name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function _add_Container(object $element, $args = []): object

$element->setOwner($this);
$element->short_name = $args[0];
if (TraitUtil::hasNameTrait($this)) {
if (TraitUtil::hasTrackableTrait($this) && TraitUtil::hasNameTrait($this) && TraitUtil::hasNameTrait($element)) {
$element->name = $this->_shorten((string) $this->name, $element->short_name, $element->name);
}
$this->elements[$element->short_name] = $element;
Expand Down
2 changes: 0 additions & 2 deletions src/TrackableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*/
trait TrackableTrait
{
use NameTrait;

/** @var object|null Link to (parent) object into which we added this object. */
private $_owner;

Expand Down
4 changes: 1 addition & 3 deletions tests/CollectionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,9 @@ public function testClone(): void
}
}

/**
* Adds support for apptrait and trackable.
*/
class CollectionMockWithApp extends CollectionMock
{
use Core\AppScopeTrait;
use Core\NameTrait;
use Core\TrackableTrait;
}
4 changes: 4 additions & 0 deletions tests/ContainerTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public function testPreservePresetNames(): void

$createTrackableMockFx = function (string $name, bool $isLongName = false) {
return new class($name, $isLongName) extends TrackableMock {
use Core\NameTrait;

public function __construct(string $name, bool $isLongName)
{
if ($isLongName) {
Expand Down Expand Up @@ -155,6 +157,7 @@ public function testArgs(): void
$m = new ContainerMock();
$m2 = $m->add(new class() extends TrackableMock {
use Core\DiContainerTrait;
use Core\NameTrait;
}, ['name' => 'foo']);
$this->assertTrue($m->hasElement('foo'));
$this->assertSame('foo', $m2->short_name);
Expand Down Expand Up @@ -233,6 +236,7 @@ class ContainerAppMock
{
use Core\AppScopeTrait;
use Core\ContainerTrait;
use Core\NameTrait;
use Core\TrackableTrait;

public function getElementCount(): int
Expand Down
2 changes: 2 additions & 0 deletions tests/FieldMockCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Atk4\Core\AppScopeTrait;
use Atk4\Core\InitializerTrait;
use Atk4\Core\NameTrait;
use Atk4\Core\TrackableTrait;

class FieldMockCustom extends FieldMock
Expand All @@ -14,6 +15,7 @@ class FieldMockCustom extends FieldMock
use InitializerTrait {
init as private _init;
}
use NameTrait;
use TrackableTrait;

/** @var bool verifying if init was called */
Expand Down

0 comments on commit 07e3467

Please sign in to comment.