Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ercanozkaya committed May 11, 2015
2 parents 3b34a59 + ca82bfa commit 0aca153
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,15 @@ CHANGELOG
To get the diff for a specific change, go to https://github.com/nooku/nooku-installer/commit/xxx where xxx is the change hash.
To view the diff between two versions, go to https://github.com/nooku/nooku-installer/compare/v0.1.0...v0.1.1

## 2.0.0 (2015-05-11)

* Added - Support for Nooku Framework Joomla repository
* Added - Support for moving Nooku component assets

## 1.0.5 (2015-05-04)

* Fixed - PHP Fatal error: Cannot redeclare Composer\Autoload\includeFile()

## 1.0.4 (2015-04-21)

* Added - Support for `nooku-framework-joomla` package
Expand Down
12 changes: 5 additions & 7 deletions src/Nooku/Composer/Installer/JoomlaExtension.php
Expand Up @@ -64,7 +64,7 @@ protected function _initialize()
$this->_credentials = array_merge($defaults, $config);

$this->_bootstrap();
$this->_loadKoowaPlugin();
$this->_loadFramework();
}

/**
Expand Down Expand Up @@ -248,24 +248,22 @@ protected function _bootstrap()
}

/**
* Initializes the Koowa plugin
* Load the framework if the autoloader.php file is available
* and the Koowa class does not exist yet
*/
protected function _loadKoowaPlugin()
protected function _loadFramework()
{
if (class_exists('Koowa')) {
return;
}

$path = JPATH_PLUGINS . '/system/koowa/koowa.php';
$path = $this->vendorDir . '/nooku/nooku-framework-joomla/autoload.php';

if (!file_exists($path)) {
return;
}

require_once $path;

$dispatcher = \JEventDispatcher::getInstance();
new \PlgSystemKoowa($dispatcher, array());
}

public function __destruct()
Expand Down
107 changes: 96 additions & 11 deletions src/Nooku/Composer/Installer/NookuComponent.php
Expand Up @@ -35,6 +35,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
parent::install($repo, $package);

$this->_installAutoloader($package);
$this->_copyAssets($package);
}

/**
Expand All @@ -47,8 +48,8 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
parent::update($repo, $initial, $target);

$this->_installAutoloader($target);
$this->_copyAssets($target);
}

/**
* Installs the default autoloader if no autoloader is supplied.
*
Expand All @@ -57,14 +58,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
protected function _installAutoloader(PackageInterface $package)
{
$path = $this->_getAutoloaderPath($package);
$manifest = $this->_getKoowaManifest($this->getInstallPath($package));

if (!($manifest instanceof \SimpleXMLElement))
{
throw new \InvalidArgumentException(
'Failed to load `koowa-component.xml` manifest for package `'.$package->getPrettyName().'`.'
);
}
$manifest = $this->_getKoowaManifest($package);

if(!file_exists($path))
{
Expand All @@ -79,11 +73,13 @@ protected function _installAutoloader(PackageInterface $package)
* You can override this autoloader by supplying an autoload.php file in the root of the relevant component.
**/
KoowaAutoloader::bootstrap();
$classname::getInstance()
->getObject('lib:object.bootstrapper')
->registerComponent(
'$component',
dirname(__FILE__),
__DIR__,
'$vendor'
);
EOL;
Expand Down Expand Up @@ -116,9 +112,11 @@ protected function _removeAutoloader(PackageInterface $package)
*
* @param PackageInterface $package
* @return bool|\SimpleXMLElement Instance of SimpleXMLElement or false on failure
* @throws `InvalidArgumentException` on failure to load the XML manifest
*/
protected function _getKoowaManifest($path)
protected function _getKoowaManifest(PackageInterface $package)
{
$path = $this->getInstallPath($package);
$directory = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::KEY_AS_PATHNAME);
$iterator = new \RecursiveIteratorIterator($directory);
$regex = new \RegexIterator($iterator, '/koowa-component\.xml/', \RegexIterator::GET_MATCH);
Expand All @@ -131,6 +129,13 @@ protected function _getKoowaManifest($path)
$manifests = array_keys($files);
$manifest = simplexml_load_file($manifests[0]);

if (!($manifest instanceof \SimpleXMLElement))
{
throw new \InvalidArgumentException(
'Failed to load `koowa-component.xml` manifest for package `'.$package->getPrettyName().'`.'
);
}

return $manifest;
}

Expand Down Expand Up @@ -170,4 +175,84 @@ protected function _getObjectManagerClassName()

return $platform ? 'Nooku\Library\ObjectManager' : 'KObjectManager';
}

/**
* Copy assets into the media folder if the installation is running in a Joomla context
*
* @param PackageInterface $package
*/
protected function _copyAssets(PackageInterface $package)
{
$path = rtrim($this->getInstallPath($package), '/');
$asset_path = $path.'/resources/assets';
$vendor_dir = dirname(dirname($path));

// Check for libraries/joomla. vendor directory sits in libraries/ folder in Joomla 3.4+
$is_joomla = is_dir(dirname($vendor_dir).'/joomla') || is_dir(dirname($vendor_dir).'/libraries/joomla');

if ($is_joomla && is_dir($asset_path))
{
$manifest = $this->_getKoowaManifest($package);

$root = is_dir(dirname($vendor_dir).'/joomla') ? dirname(dirname($vendor_dir)) : dirname($vendor_dir);
$destination = $root.'/media/koowa/com_'.$manifest->name;

$this->_copyDirectory($asset_path, $destination);
}
}

/**
* Copy source folder into target. Clears the target folder first.
*
* @param $source
* @param $target
* @return bool
*/
protected function _copyDirectory($source, $target)
{
$result = false;

if (!is_dir($target)) {
$result = mkdir($target, 0755, true);
}
else
{
// Clear directory
$iter = new \RecursiveDirectoryIterator($target);
foreach (new \RecursiveIteratorIterator($iter, \RecursiveIteratorIterator::CHILD_FIRST) as $f)
{
if ($f->isDir())
{
if (!in_array($f->getFilename(), array('.', '..'))) {
rmdir($f->getPathname());
}
} else {
unlink($f->getPathname());
}
}
}

if (is_dir($target))
{
$result = true; // needed for empty directories
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $f)
{
if ($f->isDir()) {
$path = $target.'/'.$iterator->getSubPathName();
if (!is_dir($path)) {
$result = mkdir($path);
}
} else {
$result = copy($f, $target.'/'.$iterator->getSubPathName());
}

if ($result === false) {
break;
}
}
}

return $result;
}
}
4 changes: 2 additions & 2 deletions src/Nooku/Composer/Installer/NookuFramework.php
Expand Up @@ -38,7 +38,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
$query = 'UPDATE #__extensions SET enabled = 1 WHERE type = \'plugin\' AND element = \'koowa\' AND folder = \'system\'';
\JFactory::getDBO()->setQuery($query)->query();

$this->_loadKoowaPlugin();
$this->_loadFramework();
}

/**
Expand All @@ -51,6 +51,6 @@ public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface

protected function _isValidName($packageName)
{
return in_array($packageName, array('nooku/nooku-framework', 'nooku/nooku-framework-joomla'));
return $packageName === 'nooku/nooku-framework-joomla';
}
}
9 changes: 3 additions & 6 deletions src/Nooku/Composer/Joomla/Application.php
Expand Up @@ -13,7 +13,6 @@
use \JDispatcher as JDispatcher;
use \JFactory as JFactory;
use \JInstaller as JInstaller;
use \JPluginHelper as JPluginHelper;
use \JSession as JSession;
use \JRouter as JRouter;
use \JVersion as JVersion;
Expand Down Expand Up @@ -75,6 +74,7 @@ protected function _initialize()
jimport('joomla.utilities.arrayhelper');

jimport('joomla.application.module.helper');
jimport('joomla.application.router');

// Tell JFactory where to find the current application object
JFactory::$application = $this;
Expand Down Expand Up @@ -110,11 +110,8 @@ public function authenticate($credentials)
$user->$key = $value;
}

// If we're on Joomla 3, explicitely push the JUser object into the session
// otherwise getUser() always returns a new instance of JUser.
if(version_compare(JVERSION, '3.0.0', '>=')) {
JFactory::getSession()->set('user', $user);
}
// Push the JUser object into the session otherwise getUser() always returns a new instance of JUser.
JFactory::getSession()->set('user', $user);
}

/**
Expand Down

0 comments on commit 0aca153

Please sign in to comment.