Merged revision(s) 1807 from branches/develop:

- run php-cs-fixer with level PSR-2 over all relevant project files
........
parent cb1b1ad4
......@@ -274,4 +274,4 @@ class Application
$view->assign('CONTENT', $errorMessage);
$view->displayTemplate('system/exception.tpl');
}
}
\ No newline at end of file
}
This diff is collapsed.
This diff is collapsed.
<?php
namespace ACP3\Core\Assets;
use ACP3\Core;
use ACP3\Modules\Minify;
/**
* Class ThemeResolver
* @package ACP3\Core\Assets
*/
class ThemeResolver
{
/**
* @var Core\XML
*/
protected $xml;
/**
* @var Minify\Cache
*/
protected $minifyCache;
/**
* @var array
*/
protected $cachedPaths = [];
/**
* @var bool
*/
protected $newAssetPathsAdded = false;
/**
* @var string
*/
protected $modulesAssetsPath = MODULES_DIR;
/**
* @var string
*/
protected $designAssetsPath = DESIGN_PATH_INTERNAL;
/**
* @param Minify\Cache $minifyCache
*/
public function __construct(
Core\XML $xml,
Minify\Cache $minifyCache
)
{
$this->xml = $xml;
$this->minifyCache = $minifyCache;
$this->cachedPaths = $minifyCache->getCache();
}
/**
* Write newly added assets paths into the cache
*/
public function __destruct()
{
if ($this->newAssetPathsAdded === true) {
$this->minifyCache->setCache($this->cachedPaths);
}
}
/**
* @param $modulePath
* @param $designPath
* @param $dir
* @param $file
*
* @return string
*/
public function getStaticAssetPath($modulePath, $designPath, $dir = '', $file = '')
{
if (strpos($modulePath, '.') === false && !preg_match('=/$=', $modulePath)) {
$modulePath .= '/';
}
if (strpos($designPath, '.') === false && !preg_match('=/$=', $designPath)) {
$designPath .= '/';
}
if (!empty($dir) && !preg_match('=/$=', $dir)) {
$dir .= '/';
}
$systemAssetPath = $this->modulesAssetsPath . $modulePath . $dir . $file;
// Return early, if the path has already been cached
if (isset($this->cachedPaths[$systemAssetPath])) {
return $this->cachedPaths[$systemAssetPath];
} else {
return $this->_resolveAssetPath($modulePath, $designPath, $dir, $file);
}
}
/**
* @param $modulePath
* @param $designPath
* @param $dir
* @param $file
* @return string
*/
private function _resolveAssetPath($modulePath, $designPath, $dir, $file)
{
$assetPath = '';
$systemAssetPath = $this->modulesAssetsPath . $modulePath . $dir . $file;
$designAssetPath = $this->designAssetsPath . $designPath . $dir . $file;
if (is_file($designAssetPath) === true) {
$assetPath = $designAssetPath;
} else {
$designInfo = $this->xml->parseXmlFile($this->designAssetsPath . '/info.xml', '/design');
if (!empty($designInfo['parent'])) {
$this->designAssetsPath = ACP3_ROOT_DIR . 'designs/' . $designInfo['parent'];
$assetPath = $this->getStaticAssetPath($modulePath, $designPath, $dir, $file);
$this->designAssetsPath = DESIGN_PATH_INTERNAL;
} elseif (is_file($systemAssetPath) === true) {
$assetPath = $systemAssetPath;
}
}
$this->cachedPaths[$systemAssetPath] = $assetPath;
$this->newAssetPathsAdded = true;
return $assetPath;
}
/**
* @param $template
* @return string
*/
public function resolveTemplatePath($template)
{
$modulesPath = '';
// If an template with directory is given, uppercase the first letter
if (strpos($template, '/') !== false) {
$template = ucfirst($template);
// Pfad zerlegen
$fragments = explode('/', $template);
$modulesPath .= $fragments[0] . '/Resources/View/' . $fragments[1];
if (isset($fragments[2])) {
$modulesPath .= '/' . $fragments[2];
}
$asset = $this->getStaticAssetPath($modulesPath, $template);
} else {
$asset = $this->getStaticAssetPath($modulesPath, '', '', $template);
}
return $asset;
}
}
\ No newline at end of file
<?php
namespace ACP3\Core\Assets;
use ACP3\Core;
use ACP3\Modules\Minify;
/**
* Class ThemeResolver
* @package ACP3\Core\Assets
*/
class ThemeResolver
{
/**
* @var Core\XML
*/
protected $xml;
/**
* @var Minify\Cache
*/
protected $minifyCache;
/**
* @var array
*/
protected $cachedPaths = [];
/**
* @var bool
*/
protected $newAssetPathsAdded = false;
/**
* @var string
*/
protected $modulesAssetsPath = MODULES_DIR;
/**
* @var string
*/
protected $designAssetsPath = DESIGN_PATH_INTERNAL;
/**
* @param Minify\Cache $minifyCache
*/
public function __construct(
Core\XML $xml,
Minify\Cache $minifyCache
) {
$this->xml = $xml;
$this->minifyCache = $minifyCache;
$this->cachedPaths = $minifyCache->getCache();
}
/**
* Write newly added assets paths into the cache
*/
public function __destruct()
{
if ($this->newAssetPathsAdded === true) {
$this->minifyCache->setCache($this->cachedPaths);
}
}
/**
* @param $modulePath
* @param $designPath
* @param $dir
* @param $file
*
* @return string
*/
public function getStaticAssetPath($modulePath, $designPath, $dir = '', $file = '')
{
if (strpos($modulePath, '.') === false && !preg_match('=/$=', $modulePath)) {
$modulePath .= '/';
}
if (strpos($designPath, '.') === false && !preg_match('=/$=', $designPath)) {
$designPath .= '/';
}
if (!empty($dir) && !preg_match('=/$=', $dir)) {
$dir .= '/';
}
$systemAssetPath = $this->modulesAssetsPath . $modulePath . $dir . $file;
// Return early, if the path has already been cached
if (isset($this->cachedPaths[$systemAssetPath])) {
return $this->cachedPaths[$systemAssetPath];
} else {
return $this->_resolveAssetPath($modulePath, $designPath, $dir, $file);
}
}
/**
* @param $modulePath
* @param $designPath
* @param $dir
* @param $file
* @return string
*/
private function _resolveAssetPath($modulePath, $designPath, $dir, $file)
{
$assetPath = '';
$systemAssetPath = $this->modulesAssetsPath . $modulePath . $dir . $file;
$designAssetPath = $this->designAssetsPath . $designPath . $dir . $file;
if (is_file($designAssetPath) === true) {
$assetPath = $designAssetPath;
} else {
$designInfo = $this->xml->parseXmlFile($this->designAssetsPath . '/info.xml', '/design');
if (!empty($designInfo['parent'])) {
$this->designAssetsPath = ACP3_ROOT_DIR . 'designs/' . $designInfo['parent'];
$assetPath = $this->getStaticAssetPath($modulePath, $designPath, $dir, $file);
$this->designAssetsPath = DESIGN_PATH_INTERNAL;
} elseif (is_file($systemAssetPath) === true) {
$assetPath = $systemAssetPath;
}
}
$this->cachedPaths[$systemAssetPath] = $assetPath;
$this->newAssetPathsAdded = true;
return $assetPath;
}
/**
* @param $template
* @return string
*/
public function resolveTemplatePath($template)
{
$modulesPath = '';
// If an template with directory is given, uppercase the first letter
if (strpos($template, '/') !== false) {
$template = ucfirst($template);
// Pfad zerlegen
$fragments = explode('/', $template);
$modulesPath .= $fragments[0] . '/Resources/View/' . $fragments[1];
if (isset($fragments[2])) {
$modulesPath .= '/' . $fragments[2];
}
$asset = $this->getStaticAssetPath($modulesPath, $template);
} else {
$asset = $this->getStaticAssetPath($modulesPath, '', '', $template);
}
return $asset;
}
}
......@@ -72,14 +72,13 @@ class Auth
* @param Config $usersConfig
* @param Users\Model $usersModel
*/
function __construct(
public function __construct(
Session $session,
Secure $secureHelper,
Config $systemConfig,
Config $usersConfig,
Users\Model $usersModel
)
{
) {
$this->session = $session;
$this->secureHelper = $secureHelper;
$this->usersConfig = $usersConfig;
......@@ -280,4 +279,4 @@ class Auth
}
return 0;
}
}
\ No newline at end of file
}
......@@ -8,7 +8,6 @@ namespace ACP3\Core;
*/
class Breadcrumb
{
/**
* Enthält alle Schritte der Brotkrümelspur,
* welche sich aus der Navigationsstruktur der Website ergeben
......@@ -65,8 +64,7 @@ class Breadcrumb
Request $request,
Router $router,
Config $systemConfig
)
{
) {
$this->lang = $lang;
$this->request = $request;
$this->router = $router;
......@@ -348,5 +346,4 @@ class Breadcrumb
}
}
}
}
\ No newline at end of file
}
<?php
namespace ACP3\Core;
use Doctrine\Common\Cache\CacheProvider;
use Symfony\Component\DependencyInjection\Container;
/**
* Class Cache
* @package ACP3\Core
*/
class Cache
{
/**
* @var string
*/
protected $namespace = '';
/**
* @var CacheProvider
*/
protected $driver;
/**
* @param Container $container
* @param $namespace
*/
public function __construct(
Container $container,
$namespace
)
{
$this->namespace = $namespace;
if ($container->hasParameter('cache_driver')) {
$driverName = $container->getParameter('cache_driver');
} else {
$driverName = 'Array';
}
// If debug mode is enabled, override the cache driver configuration
if (defined('DEBUG') && DEBUG === true) {
$driverName = 'Array';
}
$cacheDriverPath = "\\Doctrine\\Common\\Cache\\" . $driverName . 'Cache';
if (class_exists($cacheDriverPath)) {
if ($driverName === 'PhpFile') {
$cacheDir = UPLOADS_DIR . 'cache/sql/';
$this->driver = new $cacheDriverPath($cacheDir);
} else {
$this->driver = new $cacheDriverPath();
}
$this->driver->setNamespace($namespace);
} else {
throw new \InvalidArgumentException(sprintf('Could not find the requested cache driver "%s"!', $cacheDriverPath));
}
}
/**
* @param string $dir
* @param string $cacheId
*
* @return bool
*/
public static function purge($dir, $cacheId = '')
{
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = "$dir/$file";
if (is_dir($path)) {
static::purge($path, $cacheId);
if (empty($cacheId)) {
@rmdir($path);
}
} else {
if (!empty($cacheId) && strpos($file, $cacheId) === false) {
continue;
}
@unlink($path);
}
}
if (!empty($cacheId)) {
return true;
}
return true;
}
/**
* @param $id
*
* @return bool|mixed|string
*/
public function fetch($id)
{
return $this->driver->fetch($id);
}
/**
* @param $id
*
* @return bool
*/
public function contains($id)
{
return $this->driver->contains($id);
}
/**
* @param $id
* @param $data
* @param int $lifetime
*
* @return bool
*/
public function save($id, $data, $lifetime = 0)
{
return $this->driver->save($id, $data, $lifetime);
}
/**
* @param $id
*
* @return bool
*/
public function delete($id)
{
return $this->driver->delete($id);
}
/**
* @return CacheProvider
*/
public function getDriver()
{
return $this->driver;
}
}
\ No newline at end of file
<?php
namespace ACP3\Core;
use Doctrine\Common\Cache\CacheProvider;
use Symfony\Component\DependencyInjection\Container;
/**
* Class Cache
* @package ACP3\Core
*/
class Cache
{
/**
* @var string
*/
protected $namespace = '';
/**
* @var CacheProvider
*/
protected $driver;
/**
* @param Container $container
* @param $namespace
*/
public function __construct(
Container $container,
$namespace
) {
$this->namespace = $namespace;
if ($container->hasParameter('cache_driver')) {
$driverName = $container->getParameter('cache_driver');
} else {
$driverName = 'Array';
}
// If debug mode is enabled, override the cache driver configuration
if (defined('DEBUG') && DEBUG === true) {
$driverName = 'Array';
}
$cacheDriverPath = "\\Doctrine\\Common\\Cache\\" . $driverName . 'Cache';
if (class_exists($cacheDriverPath)) {
if ($driverName === 'PhpFile') {
$cacheDir = UPLOADS_DIR . 'cache/sql/';
$this->driver = new $cacheDriverPath($cacheDir);
} else {
$this->driver = new $cacheDriverPath();
}
$this->driver->setNamespace($namespace);
} else {
throw new \InvalidArgumentException(sprintf('Could not find the requested cache driver "%s"!', $cacheDriverPath));
}
}
/**
* @param string $dir
* @param string $cacheId
*
* @return bool
*/
public static function purge($dir, $cacheId = '')
{
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = "$dir/$file";
if (is_dir($path)) {
static::purge($path, $cacheId);
if (empty($cacheId)) {
@rmdir($path);
}
} else {
if (!empty($cacheId) && strpos($file, $cacheId) === false) {