Skip to content

Commit

Permalink
path.ymlを絶対パスから相対パスに変更
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yamamura committed Jun 7, 2016
1 parent 3498a42 commit 009e668
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 62 deletions.
148 changes: 115 additions & 33 deletions src/Eccube/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

use Eccube\Application\ApplicationTrait;
use Eccube\Common\Constant;
use Monolog\Logger;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -76,7 +75,8 @@ public function __construct(array $values = array())
public function initConfig()
{
// load config
$this['config'] = $this->share(function() {
$app = $this;
$this['config'] = $this->share(function ($app) {
$ymlPath = __DIR__.'/../../app/config/eccube';
$distPath = __DIR__.'/../../src/Eccube/Resource/config';

Expand All @@ -96,6 +96,25 @@ public function initConfig()
$path_yml = $ymlPath.'/path.yml';
if (file_exists($path_yml)) {
$config_path = Yaml::parse(file_get_contents($path_yml));
// RootDirまでのpath補完
$config_path['root_dir'] = $app->getRootDir();
$config_path['public_path_realdir'] = $app->getRootDir().$config_path['public_path'];
$config_path['image_save_realdir'] = $app->getRootDir().$config_path['public_path'].$config_path['image_save_realdir'];
$config_path['image_temp_realdir'] = $app->getRootDir().$config_path['public_path'].$config_path['image_temp_realdir'];
$config_path['user_data_realdir'] = $app->getRootDir().$config_path['public_path'].$config_path['user_data_realdir'];
$config_path['block_default_realdir'] = $app->getSrcDir().$config_path['block_default_realdir'];
$config_path['block_realdir'] = $app->getAppDir().$config_path['block_realdir'];
$config_path['template_default_realdir'] = $app->getSrcDir().$config_path['template_default_realdir'];
$config_path['template_default_html_realdir'] = $app->getRootDir().$config_path['public_path'].$config_path['template_default_html_realdir'];
$config_path['template_admin_realdir'] = $app->getSrcDir().$config_path['template_admin_realdir'];
$config_path['template_admin_html_realdir'] = $app->getRootDir().$config_path['public_path'].$config_path['template_admin_html_realdir'];
$config_path['template_realdir'] = $app->getAppDir().$config_path['template_realdir'];
$config_path['template_html_realdir'] = $app->getRootDir().$config_path['public_path'].$config_path['template_html_realdir'];
$config_path['template_temp_realdir'] = $app->getAppDir().$config_path['template_temp_realdir'];
$config_path['csv_temp_realdir'] = $app->getAppDir().$config_path['csv_temp_realdir'];
$config_path['plugin_realdir'] = $app->getAppDir().$config_path['plugin_realdir'];
$config_path['plugin_temp_realdir'] = $app->getAppDir().$config_path['plugin_temp_realdir'];
$config_path['plugin_html_realdir'] = $app->getRootDir().$config_path['public_path'].$config_path['plugin_html_realdir'];
}

$config_constant = array();
Expand Down Expand Up @@ -187,7 +206,7 @@ public function initialize()
$this->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());

$app = $this;
$this->error(function(\Exception $e, $code) use ($app) {
$this->error(function (\Exception $e, $code) use ($app) {
if ($app['debug']) {
return;
}
Expand Down Expand Up @@ -248,7 +267,7 @@ public function initLocale()
$this->register(new \Silex\Provider\TranslationServiceProvider(), array(
'locale' => $this['config']['locale'],
));
$this['translator'] = $this->share($this->extend('translator', function($translator, \Silex\Application $app) {
$this['translator'] = $this->share($this->extend('translator', function ($translator, \Silex\Application $app) {
$translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());

$r = new \ReflectionClass('Symfony\Component\Validator\Validator');
Expand Down Expand Up @@ -292,16 +311,16 @@ public function initRendering()
$this->register(new \Silex\Provider\TwigServiceProvider(), array(
'twig.form.templates' => array('Form/form_layout.twig'),
));
$this['twig'] = $this->share($this->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) {
$this['twig'] = $this->share($this->extend('twig', function (\Twig_Environment $twig, \Silex\Application $app) {
$twig->addExtension(new \Eccube\Twig\Extension\EccubeExtension($app));
$twig->addExtension(new \Twig_Extension_StringLoader());

return $twig;
}));

$this->before(function(Request $request, \Silex\Application $app) {
$this->before(function (Request $request, \Silex\Application $app) {
// フロント or 管理画面ごとにtwigの探索パスを切り替える.
$app['twig'] = $app->share($app->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) {
$app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig, \Silex\Application $app) {
$paths = array();

// 互換性がないのでprofiler とproduction 時のcacheを分離する
Expand Down Expand Up @@ -353,7 +372,7 @@ public function initRendering()

// twigのグローバル変数を定義.
$app = $this;
$this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {
$this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function (\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {
// ショップ基本情報
$BaseInfo = $app['eccube.repository.base_info']->get();
$app['twig']->addGlobal('BaseInfo', $BaseInfo);
Expand Down Expand Up @@ -413,7 +432,7 @@ public function initMailer()
// メール送信時の文字エンコード指定(デフォルトはUTF-8)
if (isset($this['config']['mail']['charset_iso_2022_jp']) && is_bool($this['config']['mail']['charset_iso_2022_jp'])) {
if ($this['config']['mail']['charset_iso_2022_jp'] === true) {
\Swift::init(function() {
\Swift::init(function () {
\Swift_DependencyContainer::getInstance()
->register('mime.qpheaderencoder')
->asAliasOf('mime.base64headerencoder');
Expand Down Expand Up @@ -442,7 +461,7 @@ public function initDoctrine()
$this->register(new \Silex\Provider\DoctrineServiceProvider(), array(
'dbs.options' => array(
'default' => $this['config']['database']
)));
)));
$this->register(new \Saxulum\DoctrineOrmManagerRegistry\Silex\Provider\DoctrineOrmManagerRegistryProvider());

// プラグインのmetadata定義を合わせて行う.
Expand Down Expand Up @@ -558,19 +577,19 @@ public function initSecurity()
array('^/mypage', 'ROLE_USER'),
);

$this['eccube.password_encoder'] = $this->share(function($app) {
$this['eccube.password_encoder'] = $this->share(function ($app) {
return new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']);
});
$this['security.encoder_factory'] = $this->share(function($app) {
$this['security.encoder_factory'] = $this->share(function ($app) {
return new \Symfony\Component\Security\Core\Encoder\EncoderFactory(array(
'Eccube\Entity\Customer' => $app['eccube.password_encoder'],
'Eccube\Entity\Member' => $app['eccube.password_encoder'],
));
});
$this['eccube.event_listner.security'] = $this->share(function($app) {
$this['eccube.event_listner.security'] = $this->share(function ($app) {
return new \Eccube\EventListener\SecurityEventListener($app['orm.em']);
});
$this['user'] = function($app) {
$this['user'] = function ($app) {
$token = $app['security']->getToken();

return ($token !== null) ? $token->getUser() : null;
Expand All @@ -581,17 +600,17 @@ public function initSecurity()

// Voterの設定
$app = $this;
$this['authority_voter'] = $this->share(function($app) {
$this['authority_voter'] = $this->share(function ($app) {
return new \Eccube\Security\Voter\AuthorityVoter($app);
});

$app['security.voters'] = $app->extend('security.voters', function($voters) use ($app) {
$app['security.voters'] = $app->extend('security.voters', function ($voters) use ($app) {
$voters[] = $app['authority_voter'];

return $voters;
});

$this['security.access_manager'] = $this->share(function($app) {
$this['security.access_manager'] = $this->share(function ($app) {
return new \Symfony\Component\Security\Core\Authorization\AccessDecisionManager($app['security.voters'], 'unanimous');
});

Expand All @@ -615,42 +634,42 @@ public function initializePlugin()
public function initPluginEventDispatcher()
{
// EventDispatcher
$this['eccube.event.dispatcher'] = $this->share(function() {
$this['eccube.event.dispatcher'] = $this->share(function () {
return new EventDispatcher();
});

// hook point
$this->before(function(Request $request, \Silex\Application $app) {
$this->before(function (Request $request, \Silex\Application $app) {
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.before');
}, self::EARLY_EVENT);

$this->before(function(Request $request, \Silex\Application $app) {
$this->before(function (Request $request, \Silex\Application $app) {
$event = 'eccube.event.controller.'.$request->attributes->get('_route').'.before';
$app['eccube.event.dispatcher']->dispatch($event);
});

$this->after(function(Request $request, Response $response, \Silex\Application $app) {
$this->after(function (Request $request, Response $response, \Silex\Application $app) {
$event = 'eccube.event.controller.'.$request->attributes->get('_route').'.after';
$app['eccube.event.dispatcher']->dispatch($event);
});

$this->after(function(Request $request, Response $response, \Silex\Application $app) {
$this->after(function (Request $request, Response $response, \Silex\Application $app) {
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.after');
}, self::LATE_EVENT);

$this->finish(function(Request $request, Response $response, \Silex\Application $app) {
$this->finish(function (Request $request, Response $response, \Silex\Application $app) {
$event = 'eccube.event.controller.'.$request->attributes->get('_route').'.finish';
$app['eccube.event.dispatcher']->dispatch($event);
});

$app = $this;
$this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) {
$this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function (\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) {
$route = $event->getRequest()->attributes->get('_route');
$app['eccube.event.dispatcher']->dispatch('eccube.event.render.'.$route.'.before', $event);
});

// Request Event
$this->on(\Symfony\Component\HttpKernel\KernelEvents::REQUEST, function(\Symfony\Component\HttpKernel\Event\GetResponseEvent $event) use ($app) {
$this->on(\Symfony\Component\HttpKernel\KernelEvents::REQUEST, function (\Symfony\Component\HttpKernel\Event\GetResponseEvent $event) use ($app) {

if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
Expand Down Expand Up @@ -681,7 +700,7 @@ public function initPluginEventDispatcher()
}, 30); // Routing(32)が解決しし, 認証判定(8)が実行される前のタイミング.

// Controller Event
$this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {
$this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function (\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {

if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
Expand Down Expand Up @@ -712,7 +731,7 @@ public function initPluginEventDispatcher()
});

// Response Event
$this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) {
$this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function (\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) {

if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
Expand Down Expand Up @@ -742,7 +761,7 @@ public function initPluginEventDispatcher()
});

// Exception Event
$this->on(\Symfony\Component\HttpKernel\KernelEvents::EXCEPTION, function(\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event) use ($app) {
$this->on(\Symfony\Component\HttpKernel\KernelEvents::EXCEPTION, function (\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event) use ($app) {

if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
Expand Down Expand Up @@ -772,7 +791,7 @@ public function initPluginEventDispatcher()
});

// Terminate Event
$this->on(\Symfony\Component\HttpKernel\KernelEvents::TERMINATE, function(\Symfony\Component\HttpKernel\Event\PostResponseEvent $event) use ($app) {
$this->on(\Symfony\Component\HttpKernel\KernelEvents::TERMINATE, function (\Symfony\Component\HttpKernel\Event\PostResponseEvent $event) use ($app) {

$route = $event->getRequest()->attributes->get('_route');

Expand Down Expand Up @@ -835,7 +854,7 @@ public function loadPlugin()
$this['eccube.service.plugin']->checkPluginArchiveContent($path);
} catch (\Eccube\Exception\PluginException $e) {
$this['monolog']->warning("skip {$code} config loading. config.yml not foud or invalid.", array(
'path' => $path,
'path' => $path,
'original-message' => $e->getMessage()
));
continue;
Expand All @@ -848,7 +867,7 @@ public function loadPlugin()

// const
if (isset($config['const'])) {
$this['config'] = $this->share($this->extend('config', function($eccubeConfig) use ($config) {
$this['config'] = $this->share($this->extend('config', function ($eccubeConfig) use ($config) {
$eccubeConfig[$config['code']] = array(
'const' => $config['const'],
);
Expand All @@ -869,7 +888,7 @@ public function loadPlugin()

if (!class_exists($class)) {
$this['monolog']->warning("skip {$code} loading. event class not foud.", array(
'class' => $class,
'class' => $class,
));
$eventExists = false;
}
Expand Down Expand Up @@ -899,7 +918,7 @@ public function loadPlugin()
$class = '\\Plugin\\'.$config['code'].'\\ServiceProvider\\'.$service;
if (!class_exists($class)) {
$this['monolog']->warning("skip {$code} loading. service provider class not foud.", array(
'class' => $class,
'class' => $class,
));
continue;
}
Expand All @@ -909,12 +928,74 @@ public function loadPlugin()
}
}

/**
* EC-CUBE Root Directory
*
* @return string
*/
public function getRootDir()
{
static $dir;
if (null === $dir) {
$r = new \ReflectionObject($this);
$dir = dirname(dirname(dirname($r->getFileName())));
}

return $dir;
}

/**
* EC-CUBE app Directory
*
* @return string
*/
public function getAppDir()
{
static $dir;
if (null === $dir) {
$dir = $this->getRootDir().'/app';
}

return $dir;
}

/**
* EC-CUBE src Directory
*
* @return string
*/
public function getSrcDir()
{
static $dir;
if (null === $dir) {
$dir = $this->getRootDir().'/src';
}

return $dir;
}

/**
* EC-CUBE html Directory
*
* @return string
*/
public function getHtmlDir()
{
static $dir;
if (null === $dir) {
$dir = $this->getRootDir().$this['config']['public_path'];
}

return $dir;
}

/**
*
* データベースの接続を確認
* 成功 : trueを返却
* 失敗 : \Doctrine\DBAL\DBALExceptionエラーが発生( 接続に失敗した場合 )、エラー画面を表示しdie()
* 備考 : app['debug']がtrueの際は処理を行わない
*
* @return boolean true
*
*/
Expand All @@ -939,6 +1020,7 @@ protected function checkDatabaseConnection()
$response->send();
die();
}

return true;
}
}
6 changes: 3 additions & 3 deletions src/Eccube/Controller/Install/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function complete(InstallApplication $app, Request $request)
$host = $request->getSchemeAndHttpHost();
$basePath = $request->getBasePath();

$adminUrl = $host . $basePath . '/' . $config['admin_dir'];
$adminUrl = $host . $basePath . '/' . $config['admin_root'] . '/';

return $app['twig']->render('complete.twig', array(
'admin_url' => $adminUrl,
Expand Down Expand Up @@ -786,8 +786,8 @@ private function createPathYamlFile($data, Request $request)
$ROOT_DIR = realpath(__DIR__ . '/../../../../');
$ROOT_URLPATH = $request->getBasePath();

$target = array('${ADMIN_ROUTE}', '${TEMPLATE_CODE}', '${USER_DATA_ROUTE}', '${ROOT_DIR}', '${ROOT_URLPATH}');
$replace = array($ADMIN_ROUTE, $TEMPLATE_CODE, $USER_DATA_ROUTE, $ROOT_DIR, $ROOT_URLPATH);
$target = array('${ADMIN_ROUTE}', '${TEMPLATE_CODE}', '${USER_DATA_ROUTE}', '${ROOT_URLPATH}');
$replace = array($ADMIN_ROUTE, $TEMPLATE_CODE, $USER_DATA_ROUTE, $ROOT_URLPATH);

$fs = new Filesystem();
$content = str_replace(
Expand Down
Loading

0 comments on commit 009e668

Please sign in to comment.