Skip to content

Commit

Permalink
Merge pull request #1 from samsonos/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
Pavlo Onysko committed Feb 9, 2016
2 parents 7fc31f3 + 705d062 commit e9b135e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
52 changes: 36 additions & 16 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 Down Expand Up @@ -489,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 @@ -504,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 @@ -520,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
15 changes: 15 additions & 0 deletions src/shortcuts.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,21 @@ function url_base()
echo call_user_func_array('url_build', $args);
}

/**
* Echo builded URL from passed parameters
* @see url_build
*/
function url_hash()
{
$args = func_get_args();

// Call URL builder and echo its result
$returnUrl = call_user_func_array('url_build', $args);

// Return url with hash
echo substr($returnUrl, 0, -1);
}

/**
* Echo builded URL from passed parameters, prepending first parameter as current module identifier
* @see url_build()
Expand Down

0 comments on commit e9b135e

Please sign in to comment.