Skip to content

Commit

Permalink
namespace YForm
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Sep 7, 2024
1 parent ada7342 commit aaae23c
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 42 deletions.
4 changes: 3 additions & 1 deletion boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* @psalm-scope-this rex_addon
*/

rex_yform::addTemplatePath(rex_path::addon('yform', 'ytemplates'));
class_alias('Yakamara\YForm\YForm', 'rex_yform');

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

if (rex::isBackend() && rex::getUser()) {
/* @var $this rex_addon */
Expand Down
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"
]
}
}
20 changes: 19 additions & 1 deletion lib/yform/yform.php → lib/YForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/

class rex_yform
namespace Yakamara\YForm;

use Exception;
use rex;
use rex_article;
use rex_autoload;
use rex_clang;
use rex_extension;
use rex_extension_point;
use rex_factory_trait;
use rex_fragment;
use rex_i18n;
use rex_response;
use rex_sql;
use rex_yform_base_abstract;
use rex_yform_validate_abstract;
use rex_yform_value_abstract;

class YForm
{
use rex_factory_trait;

Expand Down
8 changes: 4 additions & 4 deletions lib/manager/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ public function delete(): bool
return $success;
}

public function getForm(): rex_yform
public function getForm(): \Yakamara\YForm\YForm
{
$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setDebug(self::$debug);
$yform->objparams['form_name'] = 'yform-manager-multi-edit';
$yform->objparams['form_class'] .= ' yform-manager-multi-edit';
Expand Down Expand Up @@ -529,9 +529,9 @@ public function getForm(): rex_yform
}

/**
* @param null|callable(rex_yform):void $afterFieldsExecuted
* @param null|callable(\Yakamara\YForm\YForm):void $afterFieldsExecuted
*/
public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = null): string
public function executeForm(\Yakamara\YForm\YForm $yform, ?callable $afterFieldsExecuted = null): string
{
$yform->executeFields();

Expand Down
18 changes: 9 additions & 9 deletions lib/manager/dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public function getFields(array $filter = []): array
return $this->getTable()->getFields($filter);
}

public function getForm(): rex_yform
public function getForm(): \Yakamara\YForm\YForm
{
$yform = $this->createForm();
$this->setFormMainId($yform);
Expand All @@ -501,18 +501,18 @@ public function getForm(): rex_yform
}

/**
* @param null|callable(rex_yform):void $afterFieldsExecuted
* @param null|callable(\Yakamara\YForm\YForm):void $afterFieldsExecuted
*/
public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = null): string
public function executeForm(\Yakamara\YForm\YForm $yform, ?callable $afterFieldsExecuted = null): string
{
$exists = $this->exists();
$oldData = $this->getData();

if ($exists) {
/** @var rex_yform $yform */
/** @var \Yakamara\YForm\YForm $yform */
$yform = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_UPDATE', $yform, ['table' => $this->getTable(), 'data_id' => $this->id, 'data' => $this]));
} else {
/** @var rex_yform $yform */
/** @var \Yakamara\YForm\YForm $yform */
$yform = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_ADD', $yform, ['table' => $this->getTable(), 'data' => $this]));
}

Expand Down Expand Up @@ -672,7 +672,7 @@ public function __set(string $key, $value): void
$this->setValue($key, $value);
}

private function getInternalForm(): rex_yform
private function getInternalForm(): \Yakamara\YForm\YForm
{
$dummy = new static($this->table, 0);

Expand All @@ -685,9 +685,9 @@ private function getInternalForm(): rex_yform
return $yform;
}

private function createForm(): rex_yform
private function createForm(): \Yakamara\YForm\YForm
{
$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$fields = $this->getFields();
$yform->setDebug(self::$debug);

Expand Down Expand Up @@ -721,7 +721,7 @@ private function createForm(): rex_yform
return $yform;
}

private function setFormMainId(rex_yform $yform): void
private function setFormMainId(\Yakamara\YForm\YForm $yform): void
{
if ($this->exists()) {
$where = 'id = ' . (int) $this->id;
Expand Down
10 changes: 5 additions & 5 deletions lib/manager/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function getDataPage()
<script type="text/javascript" nonce="<?= rex_response::getNonce() ?>">
rex_retain_popup_event_handlers("rex:YForm_selectData");
</script>
<?php
<?php
}

echo rex_extension::registerPoint(
Expand Down Expand Up @@ -377,7 +377,7 @@ public function getDataPage()
$sql_db = rex_sql::factory();
$form = '';
$sql_db->transactional(static function () use (&$form, &$yform, $data, $func) {
$afterFieldsExecuted = static function (rex_yform $yform) {
$afterFieldsExecuted = static function (\Yakamara\YForm\YForm $yform) {
/** @var rex_yform_value_abstract $valueObject */
foreach ($yform->objparams['values'] as $valueObject) {
if ('submit' == $valueObject->getName()) {
Expand All @@ -390,7 +390,7 @@ public function getDataPage()
};

if ('clone' == $func) {
$afterFieldsExecuted = static function (rex_yform $yform) use ($afterFieldsExecuted) {
$afterFieldsExecuted = static function (\Yakamara\YForm\YForm $yform) use ($afterFieldsExecuted) {
$yform->objparams['form_hiddenfields']['func'] = 'add';
unset($yform->objparams['form_hiddenfields']['data_id']);

Expand Down Expand Up @@ -824,7 +824,7 @@ public function getFieldPage()
echo $fragment->parse('core/page/section.php');
}

$types = rex_yform::getTypeArray();
$types = \Yakamara\YForm\YForm::getTypeArray();
if ('choosenadd' == $func) {
$link = 'index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=add&';

Expand Down Expand Up @@ -913,7 +913,7 @@ public function getFieldPage()
if (('add' == $func || 'edit' == $func) && isset($types[$type_id][$type_name])) {
$field = new rex_yform_manager_field(['type_id' => $type_id, 'type_name' => $type_name]);

$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setDebug(false);

foreach ($this->getLinkVars() as $k => $v) {
Expand Down
4 changes: 2 additions & 2 deletions lib/manager/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function setScriptPath(string $scriptpath): self
return $this;
}

public function getYForm(): rex_yform
public function getYForm(): \Yakamara\YForm\YForm
{
$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setObjectparams('form_name', 'rex_yform_searchvars-' . $this->table->getTableName());
$yform->setObjectparams('form_showformafterupdate', 1);
$yform->setObjectparams('csrf_protection', false);
Expand Down
4 changes: 2 additions & 2 deletions lib/yform/value/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function canView(bool $viewable = true)

public function isEditable()
{
/** @var rex_yform $yform */
/** @var \Yakamara\YForm\YForm $yform */
$yform = $this->params['this'];
if (!$yform->isEditable()) {
return false;
Expand All @@ -326,7 +326,7 @@ public function isEditable()

public function isViewable()
{
/** @var rex_yform $yform */
/** @var \Yakamara\YForm\YForm $yform */
$yform = $this->params['this'];
if (!$yform->isViewable()) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/yform/value/be_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function getColumnsByName($definition)
if (count($_columns)) {
foreach ($_columns as $index => $col) {
// Use ;; for separating choice columns instead of ,
$values = explode('|', trim(trim(str_replace(';;', ',', rex_yform::unhtmlentities($col))), '|'));
$values = explode('|', trim(trim(str_replace(';;', ',', \Yakamara\YForm\YForm::unhtmlentities($col))), '|'));
if (1 == count($values)) {
$values = ['text', 'text_' . $index, $values[0]];
}
Expand Down Expand Up @@ -79,8 +79,8 @@ public function enterObject()

$this->fieldData = $data;

$yfparams = rex_yform::factory()->objparams;
$yfparams['this'] = rex_yform::factory();
$yfparams = \Yakamara\YForm\YForm::factory()->objparams;
$yfparams['this'] = \Yakamara\YForm\YForm::factory();

/* TODO
* error class von validierung ans Eingabefeld übergeben
Expand Down
2 changes: 1 addition & 1 deletion pages/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

$form_data[] = 'datestamp|updatedate||||0';

$yform = rex_yform::factory();
$yform = \Yakamara\YForm\YForm::factory();
$yform->setObjectparams('form_action', 'index.php?page=yform/email');
$yform->setObjectparams('form_name', 'yform-email-template');

Expand Down
2 changes: 1 addition & 1 deletion pages/manager.data_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
$options = '<small class="rex-panel-option-title">' . rex_i18n::msg('yform_history_delete') . ':</small> ' . $fragment->parse('core/buttons/button_group.php');
}

$historySearchForm = new rex_yform();
$historySearchForm = new \Yakamara\YForm\YForm();
$historySearchForm->setObjectparams('form_action', $list->getUrl());
$historySearchForm->setObjectparams('form_showformafterupdate', true);
$historySearchForm->setObjectparams('real_field_names', true);
Expand Down
4 changes: 2 additions & 2 deletions pages/manager.table_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$show_list = true;

if ('tableset_import' == $func && rex::getUser()->isAdmin()) {
$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setDebug(true);
$yform->setHiddenField('page', $page);
$yform->setHiddenField('func', $func);
Expand Down Expand Up @@ -73,7 +73,7 @@
}
}

$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
// $yform->setDebug(TRUE);
$yform->setObjectparams('form_name', $_csrf_key);
$yform->setHiddenField('page', $page);
Expand Down
4 changes: 2 additions & 2 deletions pages/manager.table_migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
}

$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setObjectparams('form_showformafterupdate', 1);
$yform->setObjectparams('form_name', $_csrf_key);
$yform->setHiddenField('page', $page);
Expand All @@ -45,7 +45,7 @@

unset($missing_tables[$table_name]);

$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setObjectparams('form_showformafterupdate', 1);
$yform->setHiddenField('page', $page);
$yform->setValueField('choice', ['name' => 'table_name', 'label' => rex_i18n::msg('yform_table'), 'choices' => $missing_tables]);
Expand Down
2 changes: 1 addition & 1 deletion pages/manager.tableset_export.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$yform_tables[$table_name] = $g_table->getNameLocalized() . ' [' . $table_name . ']';
}

$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setHiddenField('page', $page);
$yform->setObjectparams('real_field_names', true);
$yform->setObjectparams('form_name', $_csrf_key);
Expand Down
2 changes: 1 addition & 1 deletion pages/manager.tableset_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

$page = rex_request('page', 'string', '');

$yform = new rex_yform();
$yform = new \Yakamara\YForm\YForm();
$yform->setHiddenField('page', $page);
$yform->setObjectparams('real_field_names', true);
$yform->setObjectparams('form_name', $_csrf_key);
Expand Down
2 changes: 1 addition & 1 deletion pages/rest.access.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
$form_data[] = 'datetime|datetime_created|translate:yform_rest_token_access_datetime_created';
$form_data[] = 'text|url|translate:yform_rest_token_url';

$yform = rex_yform::factory();
$yform = \Yakamara\YForm\YForm::factory();
$yform->setObjectparams('form_action', 'index.php?page=yform/rest/access');

$yform->setFormData(implode("\n", $form_data));
Expand Down
2 changes: 1 addition & 1 deletion pages/rest.token.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
$form_data[] = 'integer|amount|translate:yform_rest_token_amount';
$form_data[] = 'choice|paths|translate:yform_rest_token_token_paths|' . implode(',', $routes) . '||1';

$yform = rex_yform::factory();
$yform = \Yakamara\YForm\YForm::factory();
$yform->setObjectparams('form_action', 'index.php?page=yform/rest/token');
$yform->setObjectparams('form_name', 'yform-rest-token-form');

Expand Down
2 changes: 1 addition & 1 deletion pages/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@

$fragment = new rex_fragment();
$fragment->setVar('title', $this->i18n('description_type_heading'), false);
$fragment->setVar('body', rex_yform::showHelp(), false);
$fragment->setVar('body', \Yakamara\YForm\YForm::showHelp(), false);
echo $fragment->parse('core/page/section.php');
16 changes: 16 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->withPaths(['docs', 'fragments', 'lib', 'module', 'pages', 'ytemplates', 'boot.php'])
->withParallel()
->withPhpVersion(PhpVersion::PHP_83)
->withConfiguredRule(
RenameClassRector::class,
[
'rex_yform' => 'Yakamara\YForm\YForm',
],
);
3 changes: 1 addition & 2 deletions ytemplates/bootstrap/value.fieldset.tpl.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

/**
* @var rex_yform_value_abstract|rex_yform $this
* @var rex_yform_value_abstract|\Yakamara\YForm\YForm $this
* @psalm-scope-this rex_yform_value_abstract
*/

$option ??= '';

switch ($option) {
Expand Down

0 comments on commit aaae23c

Please sign in to comment.