Skip to content
This repository was archived by the owner on May 21, 2021. It is now read-only.

Feature/friendly url dist patch1#35

Open
GodsDev wants to merge 70 commits into
developfrom
feature/FriendlyUrlDist-patch1
Open

Feature/friendly url dist patch1#35
GodsDev wants to merge 70 commits into
developfrom
feature/FriendlyUrlDist-patch1

Conversation

@GodsDev
Copy link
Copy Markdown
Owner

@GodsDev GodsDev commented Sep 8, 2020

Core code:

  • MyFriendlyURL is a new routing part of Controller (of MVC) (Examples of behaviour explained in dist/README.md#seo are implemented in dist)
  • Controller is set by Controller::prepareTemplate a Controller::prepareTemplateAll and called by MyController::run (instead of MyController::controller, which still remains for backward compatibility)

Dist code:

  • rozsáhlejší úpravy dist, aby se rovnou nainstalovalo funkční včetně datové struktury stránek a produktů vč. friendly URL směrování ve 4 jazycích (cs,de,en,fr) a užití redirektoru

Governance and Coding stype:

  • README.md and dist/README.md: rozsáhlé doplnění komentářů, aby bylo srozumitelnější;
  • PHPUnit test: friendly URL testováno
  • Coding style: https://www.php-fig.org/psr/psr-12/ replaces PSR-2
  • Coding style: array() to [] (As of PHP 5.4)
  • Coding style: removal of spaces (PHP CS Fixer)
  • Many elements ordered alphabetically for better readability
  • Removal of unused code

New methods:

  • MyCommon::verboseBarDump - Dumps information about a variable in Tracy Debug Bar or is silent
  • MyController::redir - Redirects to $redir (incl. relative) and die
  • MyController::run - spuštění, které používá Controller::prepareTemplate a Controller::prepareTemplateAll
  • ProjectCommon::getLinkSql - Returns SQL fragment for column link ($fieldName) which construct either parametric URL or relative friendly URL
  • ProjectCommon::language - Returns or set the language
  • MyTableAdmin: fix if prefill value is not yet among the existing values, set as value for the own-value input box

View:

  • latte may use $applicationDirLanguage to keep the selected language folder
  • FEATURE_FLAGS are available now in javascript

WorkOfStan and others added 30 commits May 25, 2020 23:59
added ProjectCommon->language() Sets language (instead of having it in every project specific ProjectSpecific)
added ProjectCommon->getLinkSql() Returns SQL fragment for column link ($fieldName) which construct either parametric URL or relative friendly URL (instead of having it in every project specific ProjectSpecific)
added MyCommon->verboseBarDump($var, $title = null, array $options = []) Dumps information about a variable in Tracy Debug Bar or dumps it to standard output
MyFriendlyUrl - better described

dist/.htaccess: If mod_alias is not enabled, the Apache should fail to show anything in order to always hide the files in the section below
dist/.htaccess: Friendly URL processing enabled
dist/build.sh: composer set to autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.
dist/conf/config.php: default values for 'FRIENDLY_URL', 'HOME_TOKEN', 'FORCE_301', 'REDIRECTOR_ENABLED' - explained in `dist/README.md`
dist/index.php: Controller called with `'requestUri' => $_SERVER['REQUEST_URI']` and request parameters POST are also taken into account
dist/classes/FriendlyUrl.php: new
…iable in Tracy Debug Bar or is silent based on `$this->verbose` set when instantiating Controller
…MUST be the same both for Controller extends MyController extends MyCommon and MyFriendlyUrl extends MyCommon

FriendlyUrl->switchParametric() contains example to be implement in database
MyController->redir() moved from Controller->redir() projects

MyController->run()
* Determines template, set Session language, runs prepareTemplate for single template and prepareAllTemplates for general transformations
* Outputs changed $MyCMS->template and $MyCMS->context as fields of an array
* replaces ->controller() /which still remains for backward compatibility/

dist/conf/config.php
* description of RULES for switchParametric to be configured in 'templateAssignementParametricRules'
* $WEBSITE['menu']: populates the default menu in `header.latte`, key means URL

`dist/conf/config.local.dist.php` - more legible
…roller even though the methods of same name but from the child class will only be used

example latte created so that the menu links work
* Constants put in alphabetical order for better legibility
… is cleaner to use {$applicationDir} in .latte instead of {$_SERVER['SCRIPT_NAME'])}
… calculation

* add languages fr and de
* change cn to zh for Chinese according to ISO 639-1 https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
…kind of redirect may be caused by using the same token for multiple languages without using language subpatern folder, so 302 Found aka Moved Temporarily is the best choice)

* de and fr translations
* parse path regexp pattern is calculated from array_keys($MyCMS->TRANSLATIONS) without DEFAULT_LANGUAGE to match interestingPath with `language subpattern` and the `rest of the path` in the method MyFriendlyUrl::friendlyIdentifyRedirect
* init_admin_table migration written using proper object methods
* create redirector_table
* fix admin: if prefill value is not yet among the existing values, set as value for the own-value input box
* fix admin: if multiple column values needed in label - use array of columns instead of trying to use SQL statements such as CONCAT
* category 1 part of menu
…ed in README.md

* refactoring FriendlyUrl::findFriendlyUrlToken
* default category has friendly url_XX
* description: how to add new content
* typeToTableMapping for type uses specific table for its records set in config.php instead of FriendlyUrl::findFriendlyUrlToken
* findFriendlyUrlToken moved to MyFriendlyUrl so if the default behaviour is ok, it doesn't have to be overidden
* product context expanded from json to array
* removal of unused code
* finishing FriendlyUrlTest including Redirector tests old_url => new_url
* latest commit of godsdev/mycms (TODO: after merge to develop and master - change to ^0.4.0)
…::$requestUri)

* fix dist/.htaccess not to switch default-something to de language
* fix ?article&code=contacts work even without FRIENDLY_URL == true
* fix new Controller::projectSpecific moved after Controller->language has been properly set (i.e. fixing scenario when after /?language=cs the /en/alfa still had czech menu
* fix autotrack.2.4.1.js sourceMappingURL=autotrack.2.4.1.js.map
* FEATURE_FLAGS are available now in javascript
* @layout.latte block script now might include change of variables expected in index.js below
* github workflows/php-composer-dependencies.yml
…d xx/ to xx

* readability: dist/.htaccess - alphabetic order
@GodsDev GodsDev requested a review from crs2 September 8, 2020 19:14
WorkOfStan and others added 2 commits September 9, 2020 02:16
* a bit different coding style concerning blank lines so that https://github.com/github/super-linter likes it
Code governance
* phpunit is only require-dev, so `webmozart/assert` MUST be required in the `composer.json` of this application
* Check composer --no-dev dependencies
* build.sh set Executable bit (+x) to fix Warnings found in [bash-exec] linter! [WARN ] Error: File:[/github/workspace/build.sh] is not executable
* CustomFilters::webalize renamed because Method name "CustomFilters::webalize_" is not in camel caps format
* context['article'] to context['content'] for article.latte
* .gitignore: .php_cs.cache
* PHPUnit: error_reporting(E_ALL); // incl E_NOTICE
* change of author email rejthar@stanislavrejthar.com
* bump version "godsdev/tools": "^0.3.7
* bump version backyard/3.2.9 ("minimum-stability": "stable")
* gitignore cache
* forgotten HOME_TOKEN settings hinted by PHPUnit
* phplint.yml uses actions/checkout@v2 version as well
* main branch (will replace `master` branch in due time)
* dist/build.sh: To work on low performing environments, the script accepts number of seconds as parameter to be used as a waiting time between steps.
* PHP/5.6 tested and PHP/7.2 tested

Code changes and various minor bugs fixes
* TableAdmin.php: Localised field content\\url_## has language independant behaviour
* TableAdmin.php: TRANSLATIONS are defined through constructor, uses web app config
* LogMysqli: int instead of bool Parameter #2 of method GodsDev\MyCMS\LogMysqli::query() so that it is compatible with method GodsDev\Backyard\BackyardMysqli::query()
* MyAdmin: definition of properties $ASSETS_SUBFOLDERS, $agendas instead of their definition in dist/classes/Admin.php
* MyAdmin: Method GodsDev\MyCMS\MyAdmin::projectSpecificSections() invoked with 1 parameter, 0 required.
* MyAdminProcess: fix type Tools::addMessage($result['success'], $result['messages']); (instead of message)
* MyAdminProcess: $salt = mt_rand((int) 1e8, (int) 1e9); (Fix: mt_rand expects int, float given)
* MyTableAdmin: removed __construct as it only duplicated parent
* MyTableLister::viewInputs - $option typo changed to $options
* fix MyCMSMonoLingual::csrfStart: Parameter #1 $min and #2 $max of function rand expects int, float given.
* fix MyController Access to an undefined properties GodsDev\MyCMS\MyController::$language and GodsDev\MyCMS\MyController::$requestUri.
* fix MyCMSMonoLingual Result of (!is_object($this->logger) || !($this->logger instanceof LoggerInterface)) is always false.
* fix type for MyAdminProcess::$tableAdmin
* fix MyTableLister::setTable throw new \RunTimeException
* fix TableAdmin: LogMysqli database object instead of vanilla \mysqli
* LogMysqli::query does not throw \DBQueryException as it logs troubles instead
* LogMysqli::query @return \mysqli_result Object|false
* MyTableLister::viewTable argument \mysqli_result $query (instead of \mysqli)
* TableAdmin::customSave - typecast to fix parameter #1 $input of function str_pad expects string, int given.
* AdminProcess::adminProcess - fix Binary operation "+" between string and (float|int) results in an error. Parameter #1 $input of function str_pad expects string, (float|int) given.
* config.php: fix Parameter #2 $newvalue of function ini_set expects string, int given.
* fix MyFriendlyUrl::PAGE_NOT_FOUND - Visibility must be declared on all constants if your project supports PHP 7.1 or later
* fix MyFriendlyUrl - The first trait import statement must be declared on the first non-comment line after the class opening brace
* fix MyAdminProcess::processFilePack - Parentheses must be used when instantiating a new class (\ZipArchive)
* Parentheses must be used when instantiating a new class: MyCMSMonoLingual::renderLatte, MyAdminProcess::processFileUnpack

Code style
* PHP linter and super-linter for GitHub Actions
* $this->tableAdmin everywhere instead of $this->TableAdmin or $TableAdmin
* markdown lint README.md: MD010/no-hard-tabs, MD009/no-trailing-spaces, MD014/commands-show-output, MD025/single-title/single-h1, MD040/fenced-code-language, MD009/no-trailing-spaces, MD037/no-space-in-emphasis
* VALIDATE_CSS: false (stylelint seems to evaluate sass the same way as CSS; `.stylelintignore` prepared for future use)

PHPStan
* recommended fixes to PHPDocs
* removal of wrong code
* phpstan include structure (mycms includes dist, github/phpstan includes local; when PHPStan test dist/ as part of MyCMS, it knows the GodsDev\\MyCMS\\* classes, so they should be ignored only if dist/ lives in its own project) 
* ignoreErrors references to 3rd library objects
* reasonable ignoreErrors exceptions
* dynamicConstantNames instead of constant induced exceptions
* some mixed type hints replaced with more specific ones
* discovering-symbols, e.g. conf/constants.php: Predefining constants for PHPSTAN analysis as recommanded by <https://phpstan.org/user-guide/discovering-symbols> 

PHPCS
* 120 chars limit enforced
* multi-line control structure
* loosen rules where it makes sense

TODO fix (CRS2)
* MyTableAdmin: the right correction is replacing #3 $cols and #4 $rows false,false by 60,5 as int is expected?
* MyTableLister: addPage() invoked with 6 parameters, 3-5 required; Parameter #1 $types of method GodsDev\MyCMS\MyTableLister::filterKeys() expects array, string given

Authored-by: Stanislav Rejthar, rejthar@stanislavrejthar.com
Copy link
Copy Markdown
Owner Author

@GodsDev GodsDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crs2 Ahoj Karle, prošel jsem celý kód (vesměs pomocí PHPStan) a našel několik věcí z původně tvého kódu, se kterým si na první ani druhý pohled nevím rady. Mrkneš na to někdy pls? Dík Slávek

Comment thread dist/classes/AdminProcess.php Outdated
Comment thread dist/classes/AdminProcess.php Outdated
Comment thread dist/classes/AdminProcess.php Outdated
Comment thread dist/classes/AdminProcess.php
Comment thread classes/MyAdmin.php Outdated
Comment thread classes/MyTableAdmin.php Outdated
Comment thread classes/MyTableAdmin.php
Comment thread classes/MyTableAdmin.php
Comment thread classes/MyTableLister.php Outdated
Comment thread dist/classes/ProjectSpecific.php Outdated
Security fix
* Don't log SQL for user creation or password change
* Log only INFO about the event of user creation or password change

Authored-by: Stanislav Rejthar, rejthar@stanislavrejthar.com
Comment thread classes/MyTableAdmin.php Outdated
 PHPUnit test by GitHub actions
* Skip dist tests until MySQLi is prepared
* Btw:  HTTP requests to self can't work in CLI only environment

Governance
* class path moved to `use` statement
* FaviconTest.php checks for presence of favicon resources
* workflow test badges
* Favicon resources moved to images/favicon folder, but due to RewriteRule in [.htaccess](dist/.htaccess) they still seem to be present where devices are automatically looking for them
* PHPUnit test automatically checks the availability of those resources
* MyTableLister: method addPage has just 5 parameters
* AdminProcess: use TableAdmin (instead of MyTableAdmin) so that $this->tableAdmin->customDelete() refers to an existing method
* MyTableAdmin: recordSave() $field instead of $value; check for $this->fields being be an array with at least one element
* If you want to append array elements from the second array to the first array while not overwriting the elements from the first array and not re-indexing, use the + array union operator: fix Binary operation "+=" between arrays results in an error ==> for simplicity and better readability use simple assignment, i.e.
`$input['class'] = 'form-control input-date';` instead of `$input += [/* 'type' => 'date', */ 'class' => 'form-control input-date'];` which should be anyway `$input = ['class' => 'form-control input-date'] + $input;`
* AdminProcess: method adminProcess() fix Binary operation "+=" between array&nonEmpty and array|false results in an error.
Copy link
Copy Markdown
Owner Author

@GodsDev GodsDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Přidal jsem ještě 6 drobností. Slávek

foreach (explode('&', $check) as $condition) {
$condition = explode('=', $condition, 2);
if (Tools::begins($condition[0], 'where[') && Tools::ends($condition[0], ']')) { //@todo doesn't work for nulls
// TODO fix: Call to function is_null() with string will always evaluate to false.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crs2 výsledkem explode budou strings, má tedy smysl na nich testovat is_null ? Slávek

Comment thread classes/MyTableAdmin.php
*/
public function outputSelectPath($name, $path_id = null, $options = [])
{
// TODO what does this construction mean? Call to function is_array() with string will always evaluate to false.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crs2 Znamená to, že buď je $name array, kde definuji pole table a column anebo je to string, a pak se má pracovat s polem, kde table i column je tím řetězcem? Slávek

Comment thread classes/MyTableAdmin.php
}
$command = 'UPDATE';
// todo fix Parameter #1 $types of method GodsDev\MyCMS\MyTableLister::filterKeys() expects array, string given.
$unique = ($this->filterKeys('PRI') ?: $this->filterKeys('UNI')) ?: array_flip(array_keys($this->fields));
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crs2 filterKeys tedy může použít jako parametr nejen array, ale legitimně i string? Nebylo by čitelnější upravit volání $this->filterKeys('PRI') na $this->filterKeys(['PRI']) a metodu filterKeys předělat, aby akceptovala jen array?

Comment thread classes/MyTableLister.php
break;
}
}
// todo fix Method GodsDev\MyCMS\MyTableLister::bulkUpdateSQL() should return string but return statement is missing.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crs2 buď by tam mělo být return $result; anebo metoda nemá vracet nic?

Comment thread classes/MyTableLister.php
. ' FROM ' . Tools::escapeDbIdentifier(TAB_PREFIX . $options['table'])
. ' GROUP BY ' . Tools::escapeDbIdentifier($options['type']) . ' WITH ROLLUP LIMIT 100');
if (!$query) {
// TODO fix Method GodsDev\MyCMS\MyTableLister::contentByType() should return string but empty return statement found.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crs2 má zde být return null; nebo return ''; ? Slávek

Comment thread classes/MyTableLister.php
return $output;
}
echo $output;
// TODO fix Method GodsDev\MyCMS\MyTableLister::contentByType() should return string but return statement is missing.
Copy link
Copy Markdown
Owner Author

@GodsDev GodsDev Dec 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crs2 Nemají 4 poslední řádky být spíš

        if (!(isset($options['return-output']) && $options['return-output'])) {
            echo $output;
        }
        return $output;

...? Aby return string.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants