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

WIP: namespace YForm #1527

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
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
59 changes: 44 additions & 15 deletions boot.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
<?php

/**
* @var rex_addon $this
* @psalm-scope-this rex_addon
*/

rex_yform::addTemplatePath(rex_path::addon('yform', 'ytemplates'));
use Yakamara\YForm\Manager\Dataset;
use Yakamara\YForm\Manager\Table\Table;
use Yakamara\YForm\Rest\Rest;
use Yakamara\YForm\YForm;

/** @var rex_addon $this */

// Aliases are deprecated and will be removed in the next major version

class_alias('Yakamara\YForm\YForm', 'rex_yform');
class_alias('Yakamara\YForm\Rest\Rest', 'rex_yform_rest');
class_alias('Yakamara\YForm\Rest\Route', 'rex_yform_rest_route');
class_alias('Yakamara\YForm\Rest\AuthToken', 'rex_yform_rest_auth_token');
class_alias('Yakamara\YForm\List\YList', 'rex_yform_list');
class_alias('Yakamara\YForm\List\Tools', 'rex_yform_list_tools');
class_alias('Yakamara\YForm\RexVar\Data', 'rex_var_yform_data');
class_alias('Yakamara\YForm\RexVar\TableData', 'rex_var_yform_table_data');
class_alias('Yakamara\YForm\Email\Template', 'rex_yform_email_template');
class_alias('Yakamara\YForm\Manager\Table\Table', 'rex_yform_manager_table');
class_alias('Yakamara\YForm\Manager\Table\Authorization', 'rex_yform_manager_table_authorization');
class_alias('Yakamara\YForm\Manager\Table\Api', 'rex_yform_manager_table_api');
class_alias('Yakamara\YForm\Manager\Table\Perm\Edit', 'rex_yform_manager_table_perm_edit');
class_alias('Yakamara\YForm\Manager\Table\Perm\View', 'rex_yform_manager_table_perm_view');
class_alias('Yakamara\YForm\Manager\Collection', 'rex_yform_manager_collection');
class_alias('Yakamara\YForm\Manager\Dataset', 'rex_yform_manager_dataset');
class_alias('Yakamara\YForm\Manager\Field', 'rex_yform_manager_field');
class_alias('Yakamara\YForm\Manager\Manager', 'rex_yform_manager_manager');
class_alias('Yakamara\YForm\Manager\Query', 'rex_yform_manager_query');
class_alias('Yakamara\YForm\Manager\Search', 'rex_yform_manager_search');
class_alias('Yakamara\YForm\Choice\GroupView', 'rex_yform_choice_group_view');
class_alias('Yakamara\YForm\Choice\ChoiceList', 'rex_yform_choice_list');
class_alias('Yakamara\YForm\Choice\ListView', 'rex_yform_choice_list_view');
class_alias('Yakamara\YForm\Choice\View', 'rex_yform_choice_view');

YForm::addTemplatePath(rex_path::addon('yform', 'ytemplates'));

if (rex::isBackend() && rex::getUser()) {
/* @var $this rex_addon */
Expand Down Expand Up @@ -64,7 +93,7 @@

rex_extension::register('PACKAGES_INCLUDED', static function () {
if (!rex::isBackend()) {
rex_yform_rest::handleRoutes();
Rest::handleRoutes();
}
});

Expand All @@ -80,8 +109,8 @@

// Manager

rex_complex_perm::register('yform_manager_table_edit', 'rex_yform_manager_table_perm_edit');
rex_complex_perm::register('yform_manager_table_view', 'rex_yform_manager_table_perm_view');
rex_complex_perm::register('yform_manager_table_edit', '\Yakamara\YForm\Manager\Table\Perm\Edit');
rex_complex_perm::register('yform_manager_table_view', '\Yakamara\YForm\Manager\Table\Perm\View');

if (rex::isBackend() && rex::getUser()) {
rex_extension::register('PACKAGES_INCLUDED', function () {
Expand All @@ -107,7 +136,7 @@
}

try {
$tables = rex_yform_manager_table::getAll();
$tables = Table::getAll();
} catch (Exception $e) {
$tables = [];
}
Expand Down Expand Up @@ -152,27 +181,27 @@
$this->setProperty('pages', $pages);
}

rex_extension::register('MEDIA_IS_IN_USE', 'rex_yform_value_be_media::isMediaInUse');
rex_extension::register('PACKAGES_INCLUDED', 'rex_yform_value_be_link::isArticleInUse');
rex_extension::register('MEDIA_IS_IN_USE', '\Yakamara\YForm\Value\BackendMedia::isMediaInUse');
rex_extension::register('PACKAGES_INCLUDED', '\Yakamara\YForm\Value\BackendLink::isArticleInUse');

rex_extension::register('YFORM_SAVED', static function (rex_extension_point $ep) {
if ($ep->getSubject() instanceof Exception) {
return;
}

$table = rex_yform_manager_table::get($ep->getParam('table'));
$table = Table::get($ep->getParam('table'));
if (!$table) {
return;
}

$dataset = $ep->getParam('form')->getParam('manager_dataset');
if (!$dataset) {
$dataset = rex_yform_manager_dataset::getRaw($ep->getParam('id'), $table->getTableName());
$dataset = Dataset::getRaw($ep->getParam('id'), $table->getTableName());
}
$dataset->invalidateData();

if ($table->hasHistory() && $dataset->isHistoryEnabled()) {
$action = 'insert' === $ep->getParam('action') ? rex_yform_manager_dataset::ACTION_CREATE : rex_yform_manager_dataset::ACTION_UPDATE;
$action = 'insert' === $ep->getParam('action') ? Dataset::ACTION_CREATE : Dataset::ACTION_UPDATE;
$dataset->makeSnapshot($action);
}
});
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
"require-dev": {
"redaxo/php-cs-fixer-config": "^2.0",
"friendsofphp/php-cs-fixer": "v3.37.1",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"rector/rector": "^1.2"
},
"scripts": {
"cs-dry": "php-cs-fixer fix -v --ansi --dry-run --config=.php-cs-fixer.dist.php",
"cs-fix": "php-cs-fixer fix -v --ansi --config=.php-cs-fixer.dist.php",
"test": "phpunit --testdox"
"test": "phpunit --testdox",
"rector": [
"Composer\\Config::disableProcessTimeout",
"rector process --ansi"
],
"rector:no-cache": [
"Composer\\Config::disableProcessTimeout",
"rector process --clear-cache --ansi"
]
}
}
10 changes: 5 additions & 5 deletions docs/04_yorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ dump($items);

Es stehen folgende Klassen zur Verfügung:

- `rex_yform_manager_dataset`
- `rex_yform_manager_collection`
- `rex_yform_manager_query`
- `Yakamara\YForm\Manager\Collection`
- `Yakamara\YForm\Manager\Dataset`
- `Yakamara\YForm\Manager\Query`

<a name="klasse-erstellen"></a>

Expand Down Expand Up @@ -519,7 +519,7 @@ Beispiel für resetSelect()
// resetSelect() ermöglicht es im Anschluss per select nur die Felder des Datensatzes zu erhalten, die man wirklich benötigt.

```php
$dataset = rex_yform_manager_query::get('rex_yf_example')
$dataset = Yakamara\YForm\Manager\Query::get('rex_yf_example')
->resetSelect()
->select('id')
->select('title')
Expand Down Expand Up @@ -682,7 +682,7 @@ Nachteil: Man kann keine anderen Operatoren als = verwenden.
Mit `whereNested` in der Callback-Notation arbeiten:

```
$query->whereNested(function (rex_yform_manager_query $query) {
$query->whereNested(function (Yakamara\YForm\Manager\Query $query) {
$query
->where('foo', 1)
->where('bar', 2)
Expand Down
2 changes: 1 addition & 1 deletion fragments/yform/manager/page/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/** @var rex_yform_manager $manager */
$manager = $this->getVar('this');

/** @var rex_yform_manager_table $table */
/** @var \Yakamara\YForm\Manager\Table\Table $table */
$table = $this->getVar('table');
$detailForm = $this->getVar('detailForm');
$historyPage = $this->getVar('historyPage');
Expand Down
10 changes: 5 additions & 5 deletions fragments/yform/manager/page/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
$popup = $this->getVar('popup');
$hasDataPageFunctions = $this->getVar('hasDataPageFunctions');

/** @var rex_yform_list $list */
$list = rex_yform_list::factory($query, $table->getListAmount());
/** @var \Yakamara\YForm\List\YList $list */
$list = \Yakamara\YForm\List\YList::factory($query, $table->getListAmount());

$list->addTableAttribute('class', 'table-striped table-hover yform-table-' . rex_string::normalize($this->table->getTableName()));

Expand Down Expand Up @@ -99,19 +99,19 @@ static function ($params) {
if (isset($params['list']->getParams()['table_name'])) {
$target_table = $params['list']->getParams()['table_name'];
$target_field = $tablefield[0];
$values = rex_yform_value_be_manager_relation::getListValues($target_table, $target_field);
$values = \Yakamara\YForm\Value\BackendManagerRelation::getListValues($target_table, $target_field);
$value = $values[$params['list']->getValue('id')];
}
} else {
[$table_name, $field_name] = explode('.', $params['params']['opener_field']);
$table = rex_yform_manager_table::get($table_name);
$table = \Yakamara\YForm\Manager\Table\Table::get($table_name);
if ($table) {
$fields = $table->getValueFields(['name' => $field_name]);
if (isset($fields[$field_name])) {
$target_table = $fields[$field_name]->getElement('table');
$target_field = $fields[$field_name]->getElement('field');

$values = rex_yform_value_be_manager_relation::getListValues(
$values = \Yakamara\YForm\Value\BackendManagerRelation::getListValues(
$target_table,
$target_field,
);
Expand Down
11 changes: 3 additions & 8 deletions lib/yform/base_abstract.php → lib/AbstractBase.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/

abstract class rex_yform_base_abstract
namespace Yakamara\YForm;

abstract class AbstractBase
{
public $id;
public $params = [];
Expand Down
15 changes: 15 additions & 0 deletions lib/Action/AbstractAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Yakamara\YForm\Action;

use Yakamara\YForm\AbstractBase;

abstract class AbstractAction extends AbstractBase
{
public $action = [];

protected function getElementMappingOffset()
{
return 1;
}
}
14 changes: 6 additions & 8 deletions lib/yform/action/callback.php → lib/Action/Callback.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/

class rex_yform_action_callback extends rex_yform_action_abstract
namespace Yakamara\YForm\Action;

use function call_user_func;
use function in_array;

class Callback extends AbstractAction
{
public static $callback_actions = [
'pre',
Expand Down
9 changes: 2 additions & 7 deletions lib/yform/action/copy_value.php → lib/Action/CopyValue.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
namespace Yakamara\YForm\Action;

class rex_yform_action_copy_value extends rex_yform_action_abstract
class CopyValue extends AbstractAction
{
public function executeAction(): void
{
Expand Down
15 changes: 7 additions & 8 deletions lib/yform/action/create_table.php → lib/Action/CreateTable.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/

class rex_yform_action_create_table extends rex_yform_action_abstract
namespace Yakamara\YForm\Action;

use rex;
use rex_sql;
use function in_array;

class CreateTable extends AbstractAction
{
public function executeAction(): void
{
Expand Down
38 changes: 11 additions & 27 deletions lib/yform/action/db.php → lib/Action/Db.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
class rex_yform_action_db extends rex_yform_action_abstract
namespace Yakamara\YForm\Action;

use Exception;
use rex;
use rex_extension;
use rex_extension_point;
use rex_sql;
use function call_user_func;
use function count;

class Db extends AbstractAction
{
public function executeAction(): void
{
Expand Down Expand Up @@ -68,8 +70,6 @@ public function executeAction(): void
$action = 'insert';
$id = $sql->getLastId();
$this->params['main_id'] = $id;
/** @deprecated since 3.4.1 use id (lowercase) instead */
$this->params['value_pool']['email']['ID'] = $id;
$this->params['value_pool']['email']['id'] = $id;
}
} catch (Exception $e) {
Expand Down Expand Up @@ -103,22 +103,6 @@ public function executeAction(): void
'yform' => true,
],
));

/**
* @deprecated since 3.4.1 use EP YFORM_SAVED instead
*/
rex_extension::registerPoint(new rex_extension_point(
'REX_YFORM_SAVED',
$sql,
[
'form' => $this,
'sql' => $sql,
'table' => $main_table,
'action' => $action,
'id' => $this->params['main_id'],
'yform' => true,
],
));
}
}

Expand Down
14 changes: 6 additions & 8 deletions lib/yform/action/db_query.php → lib/Action/DbQuery.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/

class rex_yform_action_db_query extends rex_yform_action_abstract
namespace Yakamara\YForm\Action;

use Exception;
use rex_sql;

class DbQuery extends AbstractAction
{
public function executeAction(): void
{
Expand Down
13 changes: 6 additions & 7 deletions lib/yform/action/email.php → lib/Action/Email.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
namespace Yakamara\YForm\Action;

class rex_yform_action_email extends rex_yform_action_abstract
use rex_mailer;

use function is_array;

class Email extends AbstractAction
{
public function executeAction(): void
{
Expand Down
Loading
Loading