Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
nik-os committed Feb 7, 2016
1 parent 520f8e4 commit 705d062
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,18 +420,31 @@ public function composer($dependencyFilePath = null)
)
);

$modulesToLoad = array();

// Iterate requirements
foreach ($composerModules as $requirement => $parameters) {
// Load module
$this->load(
__SAMSON_CWD__ . __SAMSON_VENDOR_PATH . $requirement,
array_merge(
is_array($parameters) ? $parameters : array($parameters),
array('module_id' => $requirement)
)
$modulesToLoad[__SAMSON_CWD__ . __SAMSON_VENDOR_PATH . $requirement] = array_merge(
is_array($parameters) ? $parameters : array($parameters),
array('module_id' => $requirement)
);
}

$localModulesPath = '../src';

$resourceMap = ResourceMap::get($localModulesPath);

foreach ($resourceMap->modules as $moduleFile) {
$modulePath = str_replace(realpath($localModulesPath), '', $moduleFile[1]);
$modulePath = explode('/', $modulePath);
$modulePath = $localModulesPath.'/'.$modulePath[1];
$modulesToLoad[$modulePath] = array();
}

foreach($modulesToLoad as $path => $parameters) {
$this->load($path, $parameters);
}

// Create local module and set it as active
$this->active = new CompressableLocalModule('local', $this->system_path, $this->map, $this);

Expand All @@ -451,17 +464,6 @@ public function composer($dependencyFilePath = null)
new CompressableLocalModule(basename($controller, '.php'), $this->system_path, $this->map, $this);
}

$modulesPath = '../src';

$resourceMap = ResourceMap::get($modulesPath);

foreach ($resourceMap->modules as $moduleFile) {
$modulePath = str_replace(realpath($modulesPath), '', $moduleFile[1]);
$modulePath = explode('/', $modulePath);
$modulePath = $modulesPath.'/'.$modulePath[1];
$this->load($modulePath);
}

return $this;
}

Expand Down Expand Up @@ -500,6 +502,16 @@ public function load($path, $parameters = array())

/** @var ExternalModule $connector Create module controller instance */
$connector = new $moduleClass($path, $resourceMap, $this);
} elseif (is_array($parameters) && isset($parameters['samsonphp_package_compressable']) && ($parameters['samsonphp_package_compressable'] == 1)) {
/** @var \samson\core\ExternalModule $connector Create module controller instance */
$connector = new VirtualModule($path, $resourceMap, $this,
str_replace('/', '', $parameters['module_id']));

// Set composer parameters
$connector->composerParameters = $parameters;
}

if (is_object($connector)) {

// Set composer parameters
$connector->composerParameters = $parameters;
Expand All @@ -515,13 +527,15 @@ public function load($path, $parameters = array())

// TODO: Think how to decouple this
// Call module preparation handler
if (!$connector->prepare()) {
if ( ! $connector->prepare()) {
// Handle module failed preparing
}

// Trying to find parent class for connecting to it to use View/Controller inheritance
$parentClass = get_parent_class($connector);
if (!in_array($parentClass, array('samson\core\ExternalModule', 'samson\core\CompressableExternalModule'))) {
if ( ! in_array($parentClass,
array('samson\core\ExternalModule', 'samson\core\CompressableExternalModule'))
) {
// Переберем загруженные в систему модули
foreach ($this->module_stack as &$m) {
// Если в систему был загружен модуль с родительским классом
Expand All @@ -531,13 +545,8 @@ public function load($path, $parameters = array())
}
}
}
} elseif (is_array($parameters) && isset($parameters['samsonphp_package_compressable']) && ($parameters['samsonphp_package_compressable'] == 1)) {
/** @var \samson\core\ExternalModule $connector Create module controller instance */
$connector = new VirtualModule($path, $resourceMap, $this, str_replace('/','',$parameters['module_id']));

// Set composer parameters
$connector->composerParameters = $parameters;
} else { // Signal error
}
else { // Signal error
return e('Cannot load module from: "##"', E_SAMSON_FATAL_ERROR, $path);
}

Expand Down

0 comments on commit 705d062

Please sign in to comment.