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

Releasing 2.0.2 into master #150

Merged
merged 38 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6d814b9
Clean up badges in README file (#116)
romaninsh Dec 1, 2019
fb62b28
Configuration Elements cannot be replaced (#117)
bepixeld Jan 20, 2020
2872fdb
Apply fixes from StyleCI
DarkSide666 Jan 20, 2020
7b08c27
Update composer.json
DarkSide666 Feb 11, 2020
6b01645
Update release-drafter.yml
DarkSide666 Feb 11, 2020
410e491
Update release-drafter.yml
DarkSide666 Feb 11, 2020
d3612e5
Create bundler.yml
DarkSide666 Feb 11, 2020
777cab2
Add POC for "CRUD::addTo($app)" syntax (#123)
romaninsh Feb 24, 2020
cdb8e0b
[REFACTOR] rename addHook to onHook with argument naming consistency …
georgehristov Feb 24, 2020
3e956a3
hook $this by default (#126)
georgehristov Feb 25, 2020
2ee83a5
Move doc builder instructions into Docker (#125)
romaninsh Feb 25, 2020
6a3a0d2
Rename hook spot argument (#127)
georgehristov Feb 25, 2020
d8faf82
Update unit-tests.yml
DarkSide666 Feb 25, 2020
dc4e7ea
Update unit-tests.yml
DarkSide666 Feb 25, 2020
dcfd2d5
Update unit-tests.yml
DarkSide666 Feb 25, 2020
2d72fed
avoid code duplication (#128)
georgehristov Feb 25, 2020
a2afb9e
setLayout -> initLayout (#130)
DarkSide666 Mar 9, 2020
026603f
Rename HEAD to develop for Composer in unit tests (#135)
mvorisek Mar 14, 2020
61ec8ba
Fix EOL to NL (#132)
mvorisek Mar 14, 2020
42bdb7a
Do not fail-fast PHP test matrix (#136)
mvorisek Mar 14, 2020
65a83e6
Improve StaticAddToTrait trait (#139)
mvorisek Mar 14, 2020
bed4b23
Fix typo
mvorisek Mar 14, 2020
7aa0260
Improve StaticAddTo tests and add unsafe method for BC UI impl. (#140)
mvorisek Mar 14, 2020
b89f97e
Do not wrap exception message in array (#141)
mvorisek Mar 15, 2020
5f01a1b
Add skip_add param to StaticAddToTrait trait methods (#143)
mvorisek Mar 16, 2020
483766a
Require class name in seed for addToWithClassName methods (#144)
mvorisek Mar 16, 2020
0b4a3d5
Update release-drafter.yml
DarkSide666 Mar 18, 2020
c40a81a
Update release-drafter.yml
DarkSide666 Mar 18, 2020
8707241
Update StaticAddToTrait.php
DarkSide666 Mar 20, 2020
3615739
Improve hooks and allow to delete/check specific priority (#133)
mvorisek Mar 21, 2020
9cc818e
Fix hook doc
mvorisek Mar 21, 2020
188895e
fix compatibility
DarkSide666 Mar 23, 2020
0157d7d
Fix bad phpdoc
mvorisek Apr 1, 2020
882cf1c
Add injection of solutions in Exception constructor (#119)
abbadon1334 Apr 2, 2020
7999f76
Fix CS - do not import classes without namespace (#147)
mvorisek Apr 7, 2020
8d908fd
Align exception header properly (#148)
mvorisek Apr 8, 2020
64d692f
Setting release dependencies
web-flow Apr 8, 2020
a8835f7
Merge branch 'master' into release/2.0.2
DarkSide666 Apr 8, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: toolmantim/release-drafter@master
- uses: toolmantim/release-drafter@v5.6.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ jobs:
container:
image: atk4/image:${{ matrix.php }} # https://github.com/atk4/image
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', 'latest']
steps:
- uses: actions/checkout@v1
# need this to trick composer
- uses: actions/checkout@v2
- run: php --version
- run: "git branch develop; git checkout develop"

# need this to trick composer that this is a "atk4/core:develop" dependency to install atk4/data
- name: Rename HEAD to develop for Composer
run: git switch -C develop HEAD

- name: Get Composer Cache Directory
id: composer-cache
run: |
Expand Down
17 changes: 17 additions & 0 deletions docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:2-stretch as builder

WORKDIR /www

ADD requirements.txt .

RUN pip install pip==9.0.1 wheel==0.29.0 \
&& pip install -r requirements.txt

ADD . .

RUN make html
#RUN cp -R images build/html/images

FROM nginx:latest

COPY --from=builder /www/build/html /usr/share/nginx/html
18 changes: 4 additions & 14 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
How to build this documentation
Our documentation can now be built in the Docker.

```
sudo apt-get install python-sphinx python-setuptools
sudo easy_install pip

sudo pip install sphinx_rtd_theme
sudo pip install sphinxcontrib-phpdomain

make html
docker build -t docs .
docker run -p 8080:80 docs
```

next open `html/index.html` in your browser

```
open html/index.html
```

Open http://localhost:8080/ in your browser.

43 changes: 43 additions & 0 deletions docs/docs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
================
Writing ATK Docs
================

New users of Agile Toolkit rely on documentation. To make it easier for the
maintainers to update documentation - each component of ATK framework comes
with a nice documentation builder.

Writing ATK Documentation
=========================

Open file "docs/index.rst" in your editor. Most editors will support
"reSTructured Text" through add-on. The support is not perfect, but it works.

If you are updating a feature - find a corresponding ".rst" file. Your editor
may be able to show you a preview. Modify or extend documentation as needed.

See also: http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html

Building and Testing Documentation
==================================

Make sure you have "Docker" installed, follow simple instructions in
"docs/README.md".

Integrating PhpStorm
--------------------

You can integrate PhpStorm build process like this:

.. figure:: images/doc-build-phpstorm1.png
:scale: 50 %
:alt: Create build configuration for the Dockerfile


.. figure:: images/doc-build-phpstorm2.png
:scale: 50 %
:alt: Adjust Port settings to expose 80 as 8080

.. figure:: images/doc-build-phpstorm3.png
:scale: 50 %
:alt: Use "Ctrl+R" anytime to build docs

38 changes: 25 additions & 13 deletions docs/factory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,33 @@ things like:

Thanks to Factory trait, the following code::

$view->add(['Button', 'A Label', 'icon'=>'book', 'action'=>My\Action::class]);
$button = $app->add(['Button', 'A Label', 'icon'=>'book', 'action'=>My\Action::class]);

can replace this::

$button = new \atk4\ui\Button('A Label');
$button->icon = new \atk4\ui\Icon('book');
$button->action = new My\Action();
$app->add($button);

Type Hinting
------------

Agile Toolkit 2.1 introduces support for a new syntax. It is functionally
identical to a short-hand code, but your IDE will properly set type for
a `$button` to be `class Button` instead of `class View`::

$button = Button::addTo($view, ['A Label', 'icon'=>'book', 'action'=>My\Action::class]);

The traditional `$view->add` will remain available, there are no plans to
remove that syntax.

Class Name Resolution
=====================

Ability to specify only name of the class in ATK is used to keep code clean::

$app->setLayout('Centered');
$app->initLayout('Centered');
$form = $app->add('Form');
$form->addField('food_selection', ['Lookup', 'model'=>Model\Food::class]);

Expand All @@ -40,7 +52,7 @@ various methods are able to accept short identifiers for a simple syntax.

.. php:method:: normalizeClassName($name, $prefix = null)

So App::setLayout() would call `normalizeClassName($layout, 'atk4\ui\Layout')`,
So App::initLayout() would call `normalizeClassName($layout, 'atk4\ui\Layout')`,
and View::add() would call `normalizeClassName($view, 'atk4\ui')` and finally
Form::addField() would call `normalizeClassName($field, 'atk4\ui\FormField` to
produce the actual name of the class.
Expand All @@ -49,11 +61,11 @@ ATK also fully supports the following two alternative forms::

use MyOwn\Layout;

$app->setLayout(Layout::class);
$app->initLayout(Layout::class);

and::

$app->setLayout(new MyOwn\Layout());
$app->initLayout(new MyOwn\Layout());

In the first case `Layout::class` resolves into string `"MyOwn\Layout"` by the
PHP and normalizeClassName would leave it alone. In the former case, object is
Expand All @@ -69,31 +81,31 @@ classes defined in global namespace::
class TestLayout {
}

$app->setLayout(TestLayout::class);
// same as $app->setLayout('TestLayout');
$app->initLayout(TestLayout::class);
// same as $app->initLayout('TestLayout');

In this case, the call to normalizeClassName would proceed to prefix 'TestLayout' layout
into `\atk4\ui\Layout\Test`.

The solution in this case is to use `$app->setLayout('\TestLayout')`
The solution in this case is to use `$app->initLayout('\TestLayout')`

Name Resoluion Safety
---------------------

While you specify name of the layout yourself, it is not a problem, but if
you have a code like this::

$app->setLayout($_GET['layout']);
$app->initLayout($_GET['layout']);

Although it seems harmless, technically argument can point to ANY class, which
will be loaded and code in this class executed. This can be solved by using
a '.' prefix in front of the relative class name::

$app->setLayout('.'.$_GET['layout']);
$app->initLayout('.'.$_GET['layout']);

// or

$app->setLayout('.Centered');
$app->initLayout('.Centered');

Sub-namespaces
--------------
Expand All @@ -103,12 +115,12 @@ Sometimes developers prefer to use sub-namespaces, so instead of
to use `\atk4\ui\Layout\Centererd\Login`. This becomes another problem
for the resolution::

$app->setLayout('Centered\Login');
$app->initLayout('Centered\Login');

This actually looks like the a string generated by `use Centered; Login::class`
and to avoid, the following syntax can be used::

$app->setLayout('Centered/Login');
$app->initLayout('Centered/Login');

Substituting / Overriding classes
---------------------------------
Expand Down
48 changes: 25 additions & 23 deletions docs/hook.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,28 @@ The framework or application would typically execute hooks like this::

You can register multiple call-backs to be executed for the requested `spot`::

$obj->addHook('spot', function($obj){ echo "Hook 'spot' is called!"; });
$obj->onHook('spot', function($obj){ echo "Hook 'spot' is called!"; });

Adding callbacks
================

.. php:method:: addHook($spot, $callback, $args = null, $priority = 5)
.. php:method:: onHook($spot, $fx = null, array $args = [], int $priority = 5)

Register a call-back method. Calling several times will register multiple
callbacks which will be execute in the order that they were added.

Short way to describe callback method
=====================================

There is a concise syntax for using $callback by specifying object only.
There is a concise syntax for using $fx by specifying object only.
In case $fx is omitted then $this object is used as $fx.

In this case a method with same name as $spot will be used as callback::

function init() {
parent::init();

$this->addHook('beforeUpdate', $this);
$this->onHook('beforeUpdate');
}

function beforeUpdate($obj){
Expand All @@ -67,20 +69,20 @@ hook with priority 1 it will always be executed before any hooks with priority
Normally hooks are executed in the same order as they are added, however if you
use negative priority, then hooks will be executed in reverse order::

$obj->addHook('spot', third, null, -1);
$obj->onHook('spot', third, [], -1);

$obj->addHook('spot', second, null, -5);
$obj->addHook('spot', first, null, -5);
$obj->onHook('spot', second, [], -5);
$obj->onHook('spot', first, [], -5);

$obj->addHook('spot', fourth, null, 0);
$obj->addHook('spot', fifth, null, 0);
$obj->onHook('spot', fourth, [], 0);
$obj->onHook('spot', fifth, [], 0);

$obj->addHook('spot', ten, null, 1000);
$obj->onHook('spot', ten, [], 1000);

$obj->addHook('spot', sixth, null, 2);
$obj->addHook('spot', seventh, null, 5);
$obj->addHook('spot', eight);
$obj->addHook('spot', nine, null, 5);
$obj->onHook('spot', sixth, [], 2);
$obj->onHook('spot', seventh, [], 5);
$obj->onHook('spot', eight);
$obj->onHook('spot', nine, [], 5);


.. php:method:: hook($spot, $args = null)
Expand All @@ -96,8 +98,8 @@ will be placed in array and returned by hook()::
return $a+$b;
};

$obj->addHook('test', $mul);
$obj->addHook('test', $add);
$obj->onHook('test', $mul);
$obj->onHook('test', $add);

$res1 = $obj->hook('test', [2, 2]);
// res1 = [4, 4]
Expand All @@ -112,7 +114,7 @@ As you see in the code above, we were able to pass some arguments into those
hooks. There are actually 3 sources that are considered for the arguments:

- first argument to callbacks is always the $object
- arguments passed as 3rd argument to addHook() are included
- arguments passed as 3rd argument to onHook() are included
- arguments passed as 2nd argument to hook() are included

You can also use key declarations if you wish to override arguments::
Expand All @@ -123,8 +125,8 @@ You can also use key declarations if you wish to override arguments::
return pow($a, $power)+$pow($b, $power);
}

$obj->addHook('test', $pow, [2]);
$obj->addHook('test', $pow, [7]);
$obj->onHook('test', $pow, [2]);
$obj->onHook('test', $pow, [7]);

// execute all 3 hooks
$res3 = $obj->hook('test', [2, 2]);
Expand All @@ -151,13 +153,13 @@ Remember that adding breaking hook with a lower priority can prevent other
call-backs from being executed::


$obj->addHook('test', function($obj){
$obj->onHook('test', function($obj){
$obj->breakHook("break1");
});

$obj->addHook('test', function($obj){
$obj->onHook('test', function($obj){
$obj->breakHook("break2");
}, null, -5);
}, [], -5);

$res3 = $obj->hook('test', [4, 4]);
// res3 = "break2"
Expand All @@ -176,7 +178,7 @@ value is set it may call normalization hook (methods will change $value)::
$this->data[$field] = $value;
}

$m->addHook('normalize', function(&$a) { $a = trim($a); });
$m->onHook('normalize', function(&$a) { $a = trim($a); });

Checking if hook has callbacks
==============================
Expand Down
Binary file added docs/images/doc-build-phpstorm1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/doc-build-phpstorm2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/doc-build-phpstorm3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Object Containers
.. figure:: images/containers.png
:scale: 50 %

Within your application / framework you can quite often have requirement for
Within your application or framework you can quite often have requirement for
using containers:

- Form containing fields
Expand Down Expand Up @@ -134,8 +134,8 @@ and triggering callbacks::

$object = new AnyClass();

$object->addHook('test', function($o){ echo 'hello'; }
$object->addHook('test', function($o){ echo 'world'; }
$object->onHook('test', function($o){ echo 'hello'; }
$object->onHook('test', function($o){ echo 'world'; }

$object->hook('test');
// outputs: helloworld
Expand Down Expand Up @@ -273,3 +273,4 @@ Others

debug
session
docs
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
sphinxcontrib-phpdomain
sphinx_rtd_theme
2 changes: 1 addition & 1 deletion examples/test2.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function doWork()
}

$c = new MyClass();
$c->addHook('afterWork', function () {
$c->onHook('afterWork', function () {
echo "HOOKed on work\n";
});
$c->doWork();
Loading