Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rename into collection trait #104

Merged
merged 6 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ Methods

None

MultiContainerTrait
CollectionTrait
===================

.. php:trait:: MultiContainerTrait
.. php:trait:: CollectionTrait

This trait makes it possible for you to add child objects
into your object, but unlike "ContainerTrait" you can use
Expand All @@ -69,7 +69,7 @@ Example::

class Form
{
use core\MultiContainerTrait;
use core\CollectionTrait;
use core\FactoryTrait;

protected $fields = [];
Expand Down Expand Up @@ -133,7 +133,7 @@ Methods
Shortening is identical to :php:meth::`ContainerTrait::_shorten`.

Your object can this train together with ContainerTrait. As per June 2019
ATK maintainers agreed to gradually refactor ATK Data to use MultiContainerTrait
ATK maintainers agreed to gradually refactor ATK Data to use CollectionTrait
for fields, relations, actions.


Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ The natural solution to the problem is to create array like this::
After that you would need to create code for adding objects into container, removing,
verify their existence etc.

:php:trait:`MultiContainerTrait` implements several handy methods which can be used
:php:trait:`CollectionTrait` implements several handy methods which can be used
to create necessary methods with minimum code footprint::

class Form {
use MultiContainerTrait;
use CollectionTrait;

public $fields = [];

Expand All @@ -60,7 +60,7 @@ Traits add multiple checks to prevert collisions between existing objects, call
init() method, carry over $app and set $owner properties and calculate 'name'
by combining it with the parent.

MultiContainerTrait only supports named object - you may not omit the name, however
CollectionTrait only supports named object - you may not omit the name, however
a more older implementation of :php:trait:`ContainerTrait` is used primarily
for tracking Render Tree in ATK UI where name is optional and a unique name
is guaranteed.
Expand Down
15 changes: 14 additions & 1 deletion src/MultiContainerTrait.php → src/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* to add another element with same name, it will result in
* exception.
*/
trait MultiContainerTrait
trait CollectionTrait
{
/**
* Use this method trait like this:.
Expand Down Expand Up @@ -108,6 +108,19 @@ public function _removeFromCollection(string $name, string $collection)
unset($this->{$collection}[$name]);
}

/**
* Call this on collections after cloning object. This will clone all collection
* elements (which are objects).
*
* @param string $collection to be cloned
*/
public function _cloneCollection(string $collection)
{
foreach ($this->{$collection} as &$object) {
$object = clone $object;
}
}

/**
* Returns object from collection or false if object is not found.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/MultiContainerMock.php → tests/CollectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use atk4\core;

class MultiContainerMock
class CollectionMock
{
use core\MultiContainerTrait;
use core\CollectionTrait;
use core\FactoryTrait;

protected $fields = [];
Expand Down
20 changes: 10 additions & 10 deletions tests/MultiContainerTraitTest.php → tests/CollectionTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @coversDefaultClass \atk4\core\ContainerTrait
*/
class MultiContainerTraitTest extends TestCase
class CollectionTraitTest extends TestCase
{
/**
* Test constructor.
Expand All @@ -18,7 +18,7 @@ class MultiContainerTraitTest extends TestCase
public function testBasic()
{
try {
$m = new MultiContainerMock();
$m = new CollectionMock();
$m->addField('name');

$this->assertNotEmpty($m->hasField('name'));
Expand All @@ -45,7 +45,7 @@ public function testBasic()
public function testBasicWithApp()
{
try {
$m = new MultiContainerMockWithApp();
$m = new CollectionMockWithApp();
$m->app = new class() {
public $name = 'app';
public $max_name_length = 20;
Expand Down Expand Up @@ -74,7 +74,7 @@ public function testBasicWithApp()
public function testException1()
{
$this->expectException(core\Exception::class);
$m = new MultiContainerMock();
$m = new CollectionMock();
$m->_addIntoCollection('foo', (object) [], ''); // empty collection name
}

Expand All @@ -84,7 +84,7 @@ public function testException1()
public function testException2()
{
$this->expectException(core\Exception::class);
$m = new MultiContainerMock();
$m = new CollectionMock();
$m->_addIntoCollection('', (object) [], 'fields'); // empty object name
}

Expand All @@ -94,7 +94,7 @@ public function testException2()
public function testException3()
{
$this->expectException(core\Exception::class);
$m = new MultiContainerMock();
$m = new CollectionMock();
$m->_addIntoCollection('foo', (object) [], 'fields');
$m->_addIntoCollection('foo', (object) [], 'fields'); // already exists
}
Expand All @@ -105,7 +105,7 @@ public function testException3()
public function testException4()
{
$this->expectException(core\Exception::class);
$m = new MultiContainerMock();
$m = new CollectionMock();
$m->_removeFromCollection('dont_exist', 'fields'); // do not exist
}

Expand All @@ -115,7 +115,7 @@ public function testException4()
public function testException5()
{
$this->expectException(core\Exception::class);
$m = new MultiContainerMock();
$m = new CollectionMock();
$m->_getFromCollection('dont_exist', 'fields'); // do not exist
}

Expand All @@ -125,7 +125,7 @@ public function testException5()
public function testException6()
{
$this->expectException(core\Exception::class);
$m = new MultiContainerMock();
$m = new CollectionMock();
$m->addField('test', new class() {
use core\DIContainerTrait;
use core\InitializerTrait;
Expand All @@ -141,7 +141,7 @@ public function init()
/**
* Adds support for apptrait and trackable.
*/
class MultiContainerMockWithApp extends MultiContainerMock
class CollectionMockWithApp extends CollectionMock
{
use core\TrackableTrait;
use core\AppScopeTrait;
Expand Down
13 changes: 2 additions & 11 deletions tools/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,11 @@ git checkout release/$version
# Find out previous version
prev_version=$(git log --tags --simplify-by-decoration --pretty="format:%d" | grep -Eo '[0-9\.A-Z-]+' | head -1)

echo "Releasing $prev_version -> $version"
echo "Releasing $version"
gcg

vimr CHANGELOG.md

# Compute diffs
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative $prev_version...

git log --pretty=full $prev_version... | grep '#[0-9]*' | sed 's/.*#\([0-9]*\).*/\1/' | sort | uniq | while read i; do
echo "-[ $i ]-------------------------------------------------------------------------------"
ghi --color show $i | head -50
done

open "https://github.com/atk4/$product/compare/$prev_version...$head"

composer update
./vendor/phpunit/phpunit/phpunit --no-coverage

Expand Down