Commit 0ad30ede authored by tino.goratsch@hotmail.com's avatar [email protected]

Merged revision(s) 1902-1907 from branches/develop:

- fixed the path to the services definitions on case sensitive file systems
........
- made it possible to rewrite URLs to the their aliases, when there are multiple attributes before the href attribute
........
- correctly check, whether the given controller action exists when rewriting URLs
........
- inject the service container into the Modules class to check, whether the given controller action exists or not
........
- inject the Newsletter Model into the Guestbook Validator via a setter injection to allow the removal of the module
........
- made the Minify module a protected module
........
parent d2429ef3
......@@ -49,7 +49,7 @@ class RewriteInternalUri
{
$rootDir = str_replace('/', '\/', ROOT_DIR);
$host = $_SERVER['HTTP_HOST'];
return preg_replace_callback('/<a href="(http(s?):\/\/' . $host . ')?(' . $rootDir . ')?(index\.php)?(\/?)((?i:[a-z\d_\-]+\/){2,})"/', [$this, "_rewriteInternalUriCallback"], $text);
return preg_replace_callback('/<a(.*)href="(http(s?):\/\/' . $host . ')?(' . $rootDir . ')?(index\.php)?(\/?)((?i:[a-z\d_\-]+\/){2,})"/i', [$this, "_rewriteInternalUriCallback"], $text);
}
/**
......@@ -61,10 +61,10 @@ class RewriteInternalUri
*/
private function _rewriteInternalUriCallback($matches)
{
if ($this->aliasesValidator->uriAliasExists($matches[6]) === true) {
if ($this->aliasesValidator->uriAliasExists($matches[7]) === true) {
return $matches[0];
} else {
$uriArray = explode('/', $matches[6]);
$uriArray = explode('/', $matches[7]);
$path = 'frontend/' . $uriArray[0];
if (!empty($uriArray[1])) {
$path .= '/' . $uriArray[1];
......@@ -72,9 +72,12 @@ class RewriteInternalUri
if (!empty($uriArray[2])) {
$path .= '/' . $uriArray[2];
}
if (!empty($uriArray[3])) {
$path .= '/' . $uriArray[3];
}
if ($this->modules->actionExists($path)) {
return '<a href="' . $this->router->route($matches[6]) . '"';
if ($this->modules->actionExists($path) === true) {
return '<a' . $matches[1] . 'href="' . $this->router->route($matches[7]) . '"';
} else {
return $matches[0];
}
......
......@@ -2,6 +2,7 @@
namespace ACP3\Core;
use ACP3\Modules\System;
use Symfony\Component\DependencyInjection\Container;
/**
* Class Modules
......@@ -10,19 +11,23 @@ use ACP3\Modules\System;
class Modules
{
/**
* @var Lang
* @var \Symfony\Component\DependencyInjection\Container
*/
protected $container;
/**
* @var \ACP3\Core\Lang
*/
protected $lang;
/**
* @var XML
* @var \ACP3\Core\XML
*/
protected $xml;
/**
* @var Cache
* @var \ACP3\Core\Cache
*/
protected $cache;
/**
* @var System\Model
* @var \ACP3\Modules\System\Model
*/
protected $systemModel;
/**
......@@ -35,18 +40,21 @@ class Modules
private $allModules = [];
/**
* @param Lang $lang
* @param XML $xml
* @param Cache $modulesCache
* @param System\Model $systemModel
* @param \Symfony\Component\DependencyInjection\Container $container
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\XML $xml
* @param \ACP3\Core\Cache $modulesCache
* @param \ACP3\Modules\System\Model $systemModel
*/
public function __construct(
Container $container,
Lang $lang,
XML $xml,
Cache $modulesCache,
System\Model $systemModel
)
{
$this->container = $container;
$this->lang = $lang;
$this->xml = $xml;
$this->cache = $modulesCache;
......@@ -63,23 +71,23 @@ class Modules
public function actionExists($path)
{
$pathArray = array_map(function ($value) {
return str_replace(' ', '', ucwords(strtolower(str_replace('_', ' ', $value))));
return str_replace(' ', '', strtolower(str_replace('_', ' ', $value)));
}, explode('/', $path));
if (empty($pathArray[2]) === true) {
$pathArray[2] = 'Index';
$pathArray[2] = 'index';
}
if (empty($pathArray[3]) === true) {
$pathArray[3] = 'Index';
$pathArray[3] = 'index';
}
if ($pathArray[0] !== 'Frontend') {
$className = "\\ACP3\\Modules\\$pathArray[1]\\Controller\\$pathArray[0]\\$pathArray[2]";
} else {
$className = "\\ACP3\\Modules\\$pathArray[1]\\Controller\\$pathArray[2]";
$serviceId = $pathArray[1] . '.controller.' . $pathArray[0] . '.' . $pathArray[2];
if ($this->container->has($serviceId)) {
return method_exists($this->container->get($serviceId), 'action' . $pathArray[3]);
}
return method_exists($className, 'action' . $pathArray[3]);
return false;
}
/**
......
......@@ -11,11 +11,11 @@ use ACP3\Modules\Newsletter;
class Validator extends Core\Validator\AbstractValidator
{
/**
* @var Core\Validator\Rules\Captcha
* @var \ACP3\Core\Validator\Rules\Captcha
*/
protected $captchaValidator;
/**
* @var Core\ACL
* @var \ACP3\Core\ACL
*/
protected $acl;
/**
......@@ -31,24 +31,23 @@ class Validator extends Core\Validator\AbstractValidator
*/
protected $modules;
/**
* @var Model
* @var \ACP3\Modules\Guestbook\Model
*/
protected $guestbookModel;
/**
* @var Newsletter\Model
* @var \ACP3\Modules\Newsletter\Model
*/
protected $newsletterModel;
/**
* @param Core\Lang $lang
* @param Core\Validator\Rules\Misc $validate
* @param Core\Validator\Rules\Captcha $captchaValidator
* @param Core\ACL $acl
* @param Core\Auth $auth
* @param Core\Date $date
* @param Core\Modules $modules
* @param Model $guestbookModel
* @param Newsletter\Model $newsletterModel
* @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Validator\Rules\Misc $validate
* @param \ACP3\Core\Validator\Rules\Captcha $captchaValidator
* @param \ACP3\Core\ACL $acl
* @param \ACP3\Core\Auth $auth
* @param \ACP3\Core\Date $date
* @param \ACP3\Core\Modules $modules
* @param \ACP3\Modules\Guestbook\Model $guestbookModel
*/
public function __construct(
Core\Lang $lang,
......@@ -58,9 +57,8 @@ class Validator extends Core\Validator\AbstractValidator
Core\Auth $auth,
Core\Date $date,
Core\Modules $modules,
Model $guestbookModel,
Newsletter\Model $newsletterModel
) {
Model $guestbookModel)
{
parent::__construct($lang, $validate);
$this->captchaValidator = $captchaValidator;
......@@ -69,12 +67,24 @@ class Validator extends Core\Validator\AbstractValidator
$this->date = $date;
$this->modules = $modules;
$this->guestbookModel = $guestbookModel;
}
/**
* @param \ACP3\Modules\Newsletter\Model $newsletterModel
*
* @return $this
*/
public function setNewsletterModel(Newsletter\Model $newsletterModel)
{
$this->newsletterModel = $newsletterModel;
return $this;
}
/**
* @param array $formData
* @param $newsletterAccess
* @param $newsletterAccess
*
* @throws Core\Exceptions\InvalidFormToken
* @throws Core\Exceptions\ValidationFailed
*/
......@@ -118,6 +128,7 @@ class Validator extends Core\Validator\AbstractValidator
/**
* @param array $formData
* @param array $settings
*
* @throws Core\Exceptions\InvalidFormToken
* @throws Core\Exceptions\ValidationFailed
*/
......@@ -141,6 +152,7 @@ class Validator extends Core\Validator\AbstractValidator
/**
* @param array $formData
*
* @throws Core\Exceptions\InvalidFormToken
* @throws Core\Exceptions\ValidationFailed
*/
......
......@@ -21,7 +21,9 @@ services:
guestbook.validator:
class: ACP3\Modules\Guestbook\Validator
arguments: ['@core.lang', '@core.validator.rules.misc', '@core.validator.rules.captcha', '@core.acl', '@core.auth', '@core.date', '@core.modules', '@guestbook.model', '@newsletter.model']
arguments: ['@core.lang', '@core.validator.rules.misc', '@core.validator.rules.captcha', '@core.acl', '@core.auth', '@core.date', '@core.modules', '@guestbook.model']
calls:
- ['setNewsletterModel', ['@?newsletter.model']]
guestbook.installer:
class: ACP3\Modules\Guestbook\Installer
......
......@@ -5,5 +5,6 @@
<description lang="true"/>
<author>Tino Goratsch</author>
<version core="true"/>
<protected/>
</info>
</module>
......@@ -4,10 +4,10 @@ imports:
- { resource: helpers.yml }
- { resource: validation.yml }
- { resource: ../Core/WYSIWYG/config/services.yml }
- { resource: ../modules/Permissions/config/services.yml }
- { resource: ../modules/Seo/config/services.yml }
- { resource: ../modules/System/config/services.yml }
- { resource: ../modules/Users/config/services.yml }
- { resource: ../Modules/Permissions/config/services.yml }
- { resource: ../Modules/Seo/config/services.yml }
- { resource: ../Modules/System/config/services.yml }
- { resource: ../Modules/Users/config/services.yml }
services:
core.acl:
......@@ -63,7 +63,7 @@ services:
core.modules:
class: ACP3\Core\Modules
arguments: ['@core.lang', '@core.xml', '@system.cache.core.modules', '@system.model']
arguments: ['@service_container', '@core.lang', '@core.xml', '@system.cache.core.modules', '@system.model']
core.modules.abstractInstaller:
abstract: true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment