-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBackOfficePath.php
More file actions
96 lines (80 loc) · 3.36 KB
/
Copy pathBackOfficePath.php
File metadata and controls
96 lines (80 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace BackOfficePath;
use Propel\Runtime\Connection\ConnectionInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ServicesConfigurator;
use Thelia\Model\ConfigQuery;
use Thelia\Module\BaseModule;
/**
* Class BackOfficePath
*
* @author Florian Picard <fpicard@openstudio.fr>
* @author Jérôme Billiras <jbilliras@openstudio.fr>
*/
class BackOfficePath extends BaseModule
{
/** @var string Translation domain */
const MESSAGE_DOMAIN = 'backofficepath';
/** @var string Default admin path */
const DEFAULT_THELIA_PREFIX = 'admin';
/** @var string Configuration key for new path */
const CONFIG_PATH = 'back_office_path';
/** @var string Configuration key for using default path */
const CONFIG_USE_DEFAULT_PATH = 'back_office_path_default_enabled';
/** @var string Request attribute key to determine if custom admin path is in use */
const IS_CUSTOM_ADMIN_PATH = 'is_custom_admin_path';
public function preActivation(ConnectionInterface $con = null)
{
$prefix = ConfigQuery::read(self::CONFIG_PATH);
if ($prefix === null) {
ConfigQuery::write(self::CONFIG_PATH, '', false, true);
}
$enabled = ConfigQuery::read(self::CONFIG_USE_DEFAULT_PATH, null);
if ($enabled === null) {
ConfigQuery::write(self::CONFIG_USE_DEFAULT_PATH, true, false, true);
}
return true;
}
/**
* Replace url in content
*
* @param string $content
* @param string $oldPrefix
* @param string $newPrefix
*
* @return string Content with replaced urls
*/
public static function replaceUrl($content, $oldPrefix, $newPrefix)
{
$replacedUrl = preg_replace(
'#(.*?)/' . preg_quote($oldPrefix, '#') . '(.*?)#',
'$1/' . $newPrefix . '$2',
$content
);
return $replacedUrl;
}
public static function matchPath($path, $prefix)
{
return preg_match("/^\/".preg_quote($prefix, '/')."(\/.*$|$)/", $path) === 1;
}
public static function matchUrl($path, $prefix)
{
return preg_match("/\/".preg_quote($prefix, '/')."(\/.*$|$)/", $path) === 1;
}
public static function configureServices(ServicesConfigurator $servicesConfigurator): void
{
$servicesConfigurator->load(self::getModuleCode().'\\', __DIR__)
->exclude([THELIA_MODULE_DIR.ucfirst(self::getModuleCode()).'/I18n/*'])
->autowire(true)
->autoconfigure(true);
}
}