Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor以下での利用を可能に #1543

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
ini_set('wincache.fcenabled', 1);
}

$autoload = __DIR__.'/vendor/autoload.php';

if (file_exists($autoload) && is_readable($autoload)) {
$loader = require $autoload;
if (file_exists(__DIR__.'/vendor.phar')) {
$loader = require __DIR__.'/vendor.phar';
} elseif (file_exists(__DIR__.'/vendor/autoload.php')) {
$loader = require __DIR__.'/vendor/autoload.php';
} else {
die('Composer is not installed.');
}
$loader->addPsr4('Plugin\\', __DIR__ . '/app/Plugin');

// autoloader cache
if (extension_loaded('apc') && ini_get('apc.enabled')) {
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"autoload": {
"psr-4": {
"Eccube\\": "src/Eccube",
"Plugin\\": "app/Plugin",
"Dbtlr\\MigrationProvider\\Provider\\": "src/silex-doctrine-migrations"
}
},
Expand Down
51 changes: 35 additions & 16 deletions src/Eccube/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Application extends ApplicationTrait
protected $initialized = false;
protected $initializedPlugin = false;

public $package;
public $rootDir;

public static function getInstance(array $values = array())
{
if (!is_object(self::$instance)) {
Expand All @@ -60,6 +63,20 @@ final public function __clone()

public function __construct(array $values = array())
{
if (\Phar::running(false)) {
// phar
$this->package = 'phar';
$this->rootDir = dirname(\Phar::running(false));
} elseif (file_exists(__DIR__.'/../../../../../vendor/ec-cube/ec-cube')) {
// composer
$this->package = 'composer';
$this->rootDir = __DIR__.'/../../../../..';
} else {
// other
$this->package = 'general';
$this->rootDir = __DIR__.'/../..';
}

parent::__construct($values);

if (is_null(self::$instance)) {
Expand All @@ -76,9 +93,10 @@ public function __construct(array $values = array())
public function initConfig()
{
// load config
$this['config'] = $this->share(function() {
$ymlPath = __DIR__.'/../../app/config/eccube';
$distPath = __DIR__.'/../../src/Eccube/Resource/config';
$app = $this;
$this['config'] = $this->share(function() use ($app) {
$ymlPath = $app->rootDir.'/app/config/eccube';
$distPath = __DIR__.'/Resource/config';

$config = array();
$config_yml = $ymlPath.'/config.yml';
Expand All @@ -96,6 +114,9 @@ public function initConfig()
$path_yml = $ymlPath.'/path.yml';
if (file_exists($path_yml)) {
$config_path = Yaml::parse(file_get_contents($path_yml));
$config_path['block_default_realdir'] = __DIR__.'/Resource/template/default/Block';
$config_path['template_default_realdir'] = __DIR__.'/Resource/template/default';
$config_path['template_admin_realdir'] = __DIR__.'/Resource/template/admin';
}

$config_constant = array();
Expand Down Expand Up @@ -158,9 +179,8 @@ public function initConfig()

public function initLogger()
{
$app = $this;
$this->register(new ServiceProvider\EccubeMonologServiceProvider($app));
$this['monolog.logfile'] = __DIR__.'/../../app/log/site.log';
$this['monolog.logfile'] = $this->rootDir.'/app/log/site.log';
$this['monolog.name'] = 'eccube';
}

Expand Down Expand Up @@ -239,7 +259,6 @@ public function initialize()

public function initLocale()
{

// timezone
if (!empty($this['config']['timezone'])) {
date_default_timezone_set($this['config']['timezone']);
Expand Down Expand Up @@ -274,7 +293,7 @@ public function initLocale()
public function initSession()
{
$this->register(new \Silex\Provider\SessionServiceProvider(), array(
'session.storage.save_path' => $this['config']['root_dir'].'/app/cache/eccube/session',
'session.storage.save_path' => $this->rootDir.'/app/cache/eccube/session',
'session.storage.options' => array(
'name' => 'eccube',
'cookie_path' => $this['config']['root_urlpath'] ?: '/',
Expand Down Expand Up @@ -310,24 +329,24 @@ public function initRendering()
$app['front'] = false;

if (isset($app['profiler'])) {
$cacheBaseDir = __DIR__.'/../../app/cache/twig/profiler/';
$cacheBaseDir = $app->rootDir.'/app/cache/twig/profiler/';
} else {
$cacheBaseDir = __DIR__.'/../../app/cache/twig/production/';
$cacheBaseDir = $app->rootDir.'/app/cache/twig/production/';
}
if (strpos($app['request']->getPathInfo(), '/'.trim($app['config']['admin_route'], '/')) === 0) {
if (file_exists(__DIR__.'/../../app/template/admin')) {
$paths[] = __DIR__.'/../../app/template/admin';
if (file_exists($app->rootDir.'/app/template/admin')) {
$paths[] = $app->rootDir.'/app/template/admin';
}
$paths[] = $app['config']['template_admin_realdir'];
$paths[] = __DIR__.'/../../app/Plugin';
$paths[] = $app->rootDir.'/app/Plugin';
$cache = $cacheBaseDir.'admin';
$app['admin'] = true;
} else {
if (file_exists($app['config']['template_realdir'])) {
$paths[] = $app['config']['template_realdir'];
}
$paths[] = $app['config']['template_default_realdir'];
$paths[] = __DIR__.'/../../app/Plugin';
$paths[] = $app->rootDir.'/app/Plugin';
$cache = $cacheBaseDir.$app['config']['template_code'];
$app['front'] = true;
}
Expand Down Expand Up @@ -443,7 +462,7 @@ public function initDoctrine()
$this->register(new \Saxulum\DoctrineOrmManagerRegistry\Silex\Provider\DoctrineOrmManagerRegistryProvider());

// プラグインのmetadata定義を合わせて行う.
$pluginBasePath = __DIR__.'/../../app/Plugin';
$pluginBasePath = $this->rootDir.'/app/Plugin';
$finder = Finder::create()
->in($pluginBasePath)
->directories()
Expand Down Expand Up @@ -486,7 +505,7 @@ public function initDoctrine()
}

$this->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array(
'orm.proxies_dir' => __DIR__.'/../../app/cache/doctrine',
'orm.proxies_dir' => $this->rootDir.'/app/cache/doctrine',
'orm.em.options' => array(
'mappings' => $ormMappings,
),
Expand Down Expand Up @@ -798,7 +817,7 @@ public function initPluginEventDispatcher()
public function loadPlugin()
{
// プラグインディレクトリを探索.
$basePath = __DIR__.'/../../app/Plugin';
$basePath = $this->rootDir.'/app/Plugin';
$finder = Finder::create()
->in($basePath)
->directories()
Expand Down
Loading