Browse Source

Gestion avancée des urls inter applications (frontend, backend, producer)

Amélioration de la configuration de l'UrlManager. Depuis chaque application, nous pouvons désormais accéder à l'UrlManager des autres apps. Par exemple accéder à UrlManagerFrontend depuis l'app "producer" pour faire un lien vers l'app "frontend".
refactoring
keun 6 years ago
parent
commit
594c5a52c1
9 changed files with 4372 additions and 14 deletions
  1. +3
    -0
      backend/config/main.php
  2. +50
    -0
      common/components/UrlManagerCommon.php
  3. +14
    -1
      common/config/bootstrap.php
  4. +34
    -0
      common/config/main.php
  5. +4
    -1
      frontend/config/main.php
  6. +1
    -1
      producer/components/UrlManagerProducer.php
  7. +3
    -9
      producer/config/main.php
  8. +4261
    -0
      producer/runtime/logs/app.log
  9. +2
    -2
      producer/views/layouts/main.php

+ 3
- 0
backend/config/main.php View File

require(__DIR__ . '/params-local.php') require(__DIR__ . '/params-local.php')
); );


$common_config_main = array_merge(require(__DIR__ . '/../../common/config/main.php'));

return [ return [
'id' => 'app-backend', 'id' => 'app-backend',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'errorHandler' => [ 'errorHandler' => [
'errorAction' => 'site/error', 'errorAction' => 'site/error',
], ],
'urlManager' => $common_config_main['components']['urlManagerBackend'],
], ],
'params' => $params, 'params' => $params,
]; ];

+ 50
- 0
common/components/UrlManagerCommon.php View File

<?php
namespace common\components;

use Yii;
use yii\helpers\Url;
use yii\base\InvalidConfigException;
use yii\web\UrlManager ;

class UrlManagerCommon extends UrlManager
{
public $subDomain;
public $domainName;

protected $_hostInfo;

public function getProperDomain()
{
if ( ! isset($this->domainName) || empty($this->domainName) ) {
throw new InvalidConfigException('Request requires a domain name to be configured!');
}

$subDomain = (isset($this->subDomain) && !empty($this->subDomain)) ? $this->subDomain : '';
$domain = empty($subDomain) ? '' : $subDomain . '.';
$domain .= $this->domainName;

return $domain;
}

public function getHostInfo()
{
if ($this->_hostInfo === null)
{
$secure = Yii::$app->getRequest()->getIsSecureConnection();
$http = $secure ? 'https' : 'http';

if (isset($_SERVER['HTTP_HOST'])) {
$this->_hostInfo = $http . '://' . $this->getProperDomain();
} elseif (isset($_SERVER['SERVER_NAME'])) {
$this->_hostInfo = $http . '://' . $this->getProperDomain();
$port = $secure ? $this->getSecurePort() : $this->getPort();

if (($port !== 80 && !$secure) || ($port !== 443 && $secure)) {
$this->_hostInfo .= ':' . $port;
}
}
}
return $this->_hostInfo;
}

}

+ 14
- 1
common/config/bootstrap.php View File

Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console'); Yii::setAlias('console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('producer', dirname(dirname(__DIR__)) . '/producer'); Yii::setAlias('producer', dirname(dirname(__DIR__)) . '/producer');


$server_name = $_SERVER['SERVER_NAME'] ;
Yii::setAlias('@domainName', (YII_ENV === 'dev') ? (($server_name == 'localhost') ? 'localhost' : 'laboiteapain-dev.net') : 'laboiteapain.net');
Yii::setAlias('@baseUrl', ($server_name == 'localhost') ? '/reservation_pain/' : '/');
Yii::setAlias('@baseUrlFrontend', (($server_name == 'localhost') ? '/frontend/web' : ''));
Yii::setAlias('@baseUrlBackend', (($server_name == 'localhost') ? '/backend/web' : ''));
Yii::setAlias('@baseUrlProducer', (($server_name == 'localhost') ? '/producer/web' : ''));
Yii::setAlias('@frontendSubdomain', (($server_name == 'localhost') ? '' : 'www'));
Yii::setAlias('@backendSubdomain', (($server_name == 'localhost') ? '' : 'admin'));
Yii::setAlias('@producerSubdomain', (($server_name == 'localhost') ? '' : 'producteurs'));

/* /*
* Autoload * Autoload
*/ */
Import::using('yii\helpers\*'); Import::using('yii\helpers\*');
Import::using('yii\web\NotFoundHttpException'); Import::using('yii\web\NotFoundHttpException');



// models // models
Import::using('common\models\*'); Import::using('common\models\*');
Import::using('frontend\models\*'); Import::using('frontend\models\*');
// components // components
Import::using('common\components\*'); Import::using('common\components\*');
Import::using('producer\components\*'); Import::using('producer\components\*');
Import::using('backend\components\*');
Import::using('frontend\components\*');


// pdf // pdf
Import::using('kartik\mpdf\Pdf');
Import::using('kartik\mpdf\Pdf');

+ 34
- 0
common/config/main.php View File

'class' => 'yii\image\ImageDriver', 'class' => 'yii\image\ImageDriver',
'driver' => 'GD', //GD or Imagick 'driver' => 'GD', //GD or Imagick
], ],
'urlManagerProducer' => [
'class' => 'producer\components\UrlManagerProducer',
'subDomain' => Yii::getAlias('@producerSubdomain'),
'domainName' => Yii::getAlias('@domainName'),
'baseUrl' => Yii::getAlias('@baseUrl').Yii::getAlias('@baseUrlProducer'),
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'<slug_producer:\w+>/<controller>/<action>' => '<controller>/<action>',
],
],
'urlManagerFrontend' => [
'class' => 'common\components\UrlManagerCommon',
'subDomain' => Yii::getAlias('@frontendSubdomain'),
'domainName' => Yii::getAlias('@domainName'),
'baseUrl' => Yii::getAlias('@baseUrl').Yii::getAlias('@baseUrlFrontend'),
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
],
],
'urlManagerBackend' => [
'class' => 'common\components\UrlManagerCommon',
'subDomain' => Yii::getAlias('@backendSubdomain'),
'domainName' => Yii::getAlias('@domainName'),
'baseUrl' => Yii::getAlias('@baseUrl').Yii::getAlias('@baseUrlBackend'),
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
],
],
], ],
'language' => 'fr-FR', 'language' => 'fr-FR',
]; ];

+ 4
- 1
frontend/config/main.php View File

require(__DIR__ . '/params-local.php') require(__DIR__ . '/params-local.php')
); );


$common_config_main = array_merge(require(__DIR__ . '/../../common/config/main.php'));

return [ return [
'id' => 'app-frontend', 'id' => 'app-frontend',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
], ],
'view' => [ 'view' => [
'class' => 'common\components\MyView', 'class' => 'common\components\MyView',
]
],
'urlManager' => $common_config_main['components']['urlManagerFrontend'],
], ],
'params' => $params, 'params' => $params,
]; ];

producer/components/ProducerUrlManager.php → producer/components/UrlManagerProducer.php View File



namespace producer\components ; namespace producer\components ;


class ProducerUrlManager extends \yii\web\UrlManager {
class UrlManagerProducer extends \common\components\UrlManagerCommon {
public function createUrl($params) { public function createUrl($params) {
if(!is_array($params)) if(!is_array($params))

+ 3
- 9
producer/config/main.php View File

require(__DIR__ . '/params-local.php') require(__DIR__ . '/params-local.php')
); );


$common_config_main = array_merge(require(__DIR__ . '/../../common/config/main.php'));

return [ return [
'id' => 'app-producer', 'id' => 'app-producer',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'view' => [ 'view' => [
'class' => 'producer\components\ProducerView', 'class' => 'producer\components\ProducerView',
], ],
'urlManager' => [
'class' => 'producer\components\ProducerUrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'<slug_producer:\w+>/<controller>/<action>' => '<controller>/<action>',
],
],
'urlManager' => $common_config_main['components']['urlManagerProducer'],
], ],
'params' => $params, 'params' => $params,
]; ];

+ 4261
- 0
producer/runtime/logs/app.log
File diff suppressed because it is too large
View File


+ 2
- 2
producer/views/layouts/main.php View File

'items' => [ 'items' => [
[ [
'label' => '<span class="glyphicon glyphicon-user"></span> Inscription', 'label' => '<span class="glyphicon glyphicon-user"></span> Inscription',
'url' => Url::frontend('site/signup'),
'url' => Yii::$app->urlManagerFrontend->createUrl(['site/signup']),
'visible' => Yii::$app->user->isGuest 'visible' => Yii::$app->user->isGuest
], ],
[ [
'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion', 'label' => '<span class="glyphicon glyphicon-log-in"></span> Connexion',
'url' => Url::frontend('site/login'),
'url' => Yii::$app->urlManagerFrontend->createUrl(['site/login','return_url' => Yii::$app->urlManager->createUrl(['producer/index'])]),
'visible' => Yii::$app->user->isGuest 'visible' => Yii::$app->user->isGuest
], ],
[ [

Loading…
Cancel
Save