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

Commit 0aca153

Browse files
committed
Merge branch 'release/2.0.0'
2 parents 3b34a59 + ca82bfa commit 0aca153

File tree

5 files changed

+115
-26
lines changed

5 files changed

+115
-26
lines changed

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ CHANGELOG
44
To get the diff for a specific change, go to https://github.com/nooku/nooku-installer/commit/xxx where xxx is the change hash.
55
To view the diff between two versions, go to https://github.com/nooku/nooku-installer/compare/v0.1.0...v0.1.1
66

7+
## 2.0.0 (2015-05-11)
8+
9+
* Added - Support for Nooku Framework Joomla repository
10+
* Added - Support for moving Nooku component assets
11+
12+
## 1.0.5 (2015-05-04)
13+
14+
* Fixed - PHP Fatal error: Cannot redeclare Composer\Autoload\includeFile()
15+
716
## 1.0.4 (2015-04-21)
817

918
* Added - Support for `nooku-framework-joomla` package

src/Nooku/Composer/Installer/JoomlaExtension.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected function _initialize()
6464
$this->_credentials = array_merge($defaults, $config);
6565

6666
$this->_bootstrap();
67-
$this->_loadKoowaPlugin();
67+
$this->_loadFramework();
6868
}
6969

7070
/**
@@ -248,24 +248,22 @@ protected function _bootstrap()
248248
}
249249

250250
/**
251-
* Initializes the Koowa plugin
251+
* Load the framework if the autoloader.php file is available
252+
* and the Koowa class does not exist yet
252253
*/
253-
protected function _loadKoowaPlugin()
254+
protected function _loadFramework()
254255
{
255256
if (class_exists('Koowa')) {
256257
return;
257258
}
258259

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

261262
if (!file_exists($path)) {
262263
return;
263264
}
264265

265266
require_once $path;
266-
267-
$dispatcher = \JEventDispatcher::getInstance();
268-
new \PlgSystemKoowa($dispatcher, array());
269267
}
270268

271269
public function __destruct()

src/Nooku/Composer/Installer/NookuComponent.php

+96-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
3535
parent::install($repo, $package);
3636

3737
$this->_installAutoloader($package);
38+
$this->_copyAssets($package);
3839
}
3940

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

4950
$this->_installAutoloader($target);
51+
$this->_copyAssets($target);
5052
}
51-
5253
/**
5354
* Installs the default autoloader if no autoloader is supplied.
5455
*
@@ -57,14 +58,7 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
5758
protected function _installAutoloader(PackageInterface $package)
5859
{
5960
$path = $this->_getAutoloaderPath($package);
60-
$manifest = $this->_getKoowaManifest($this->getInstallPath($package));
61-
62-
if (!($manifest instanceof \SimpleXMLElement))
63-
{
64-
throw new \InvalidArgumentException(
65-
'Failed to load `koowa-component.xml` manifest for package `'.$package->getPrettyName().'`.'
66-
);
67-
}
61+
$manifest = $this->_getKoowaManifest($package);
6862

6963
if(!file_exists($path))
7064
{
@@ -79,11 +73,13 @@ protected function _installAutoloader(PackageInterface $package)
7973
* You can override this autoloader by supplying an autoload.php file in the root of the relevant component.
8074
**/
8175
76+
KoowaAutoloader::bootstrap();
77+
8278
$classname::getInstance()
8379
->getObject('lib:object.bootstrapper')
8480
->registerComponent(
8581
'$component',
86-
dirname(__FILE__),
82+
__DIR__,
8783
'$vendor'
8884
);
8985
EOL;
@@ -116,9 +112,11 @@ protected function _removeAutoloader(PackageInterface $package)
116112
*
117113
* @param PackageInterface $package
118114
* @return bool|\SimpleXMLElement Instance of SimpleXMLElement or false on failure
115+
* @throws `InvalidArgumentException` on failure to load the XML manifest
119116
*/
120-
protected function _getKoowaManifest($path)
117+
protected function _getKoowaManifest(PackageInterface $package)
121118
{
119+
$path = $this->getInstallPath($package);
122120
$directory = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::KEY_AS_PATHNAME);
123121
$iterator = new \RecursiveIteratorIterator($directory);
124122
$regex = new \RegexIterator($iterator, '/koowa-component\.xml/', \RegexIterator::GET_MATCH);
@@ -131,6 +129,13 @@ protected function _getKoowaManifest($path)
131129
$manifests = array_keys($files);
132130
$manifest = simplexml_load_file($manifests[0]);
133131

132+
if (!($manifest instanceof \SimpleXMLElement))
133+
{
134+
throw new \InvalidArgumentException(
135+
'Failed to load `koowa-component.xml` manifest for package `'.$package->getPrettyName().'`.'
136+
);
137+
}
138+
134139
return $manifest;
135140
}
136141

@@ -170,4 +175,84 @@ protected function _getObjectManagerClassName()
170175

171176
return $platform ? 'Nooku\Library\ObjectManager' : 'KObjectManager';
172177
}
178+
179+
/**
180+
* Copy assets into the media folder if the installation is running in a Joomla context
181+
*
182+
* @param PackageInterface $package
183+
*/
184+
protected function _copyAssets(PackageInterface $package)
185+
{
186+
$path = rtrim($this->getInstallPath($package), '/');
187+
$asset_path = $path.'/resources/assets';
188+
$vendor_dir = dirname(dirname($path));
189+
190+
// Check for libraries/joomla. vendor directory sits in libraries/ folder in Joomla 3.4+
191+
$is_joomla = is_dir(dirname($vendor_dir).'/joomla') || is_dir(dirname($vendor_dir).'/libraries/joomla');
192+
193+
if ($is_joomla && is_dir($asset_path))
194+
{
195+
$manifest = $this->_getKoowaManifest($package);
196+
197+
$root = is_dir(dirname($vendor_dir).'/joomla') ? dirname(dirname($vendor_dir)) : dirname($vendor_dir);
198+
$destination = $root.'/media/koowa/com_'.$manifest->name;
199+
200+
$this->_copyDirectory($asset_path, $destination);
201+
}
202+
}
203+
204+
/**
205+
* Copy source folder into target. Clears the target folder first.
206+
*
207+
* @param $source
208+
* @param $target
209+
* @return bool
210+
*/
211+
protected function _copyDirectory($source, $target)
212+
{
213+
$result = false;
214+
215+
if (!is_dir($target)) {
216+
$result = mkdir($target, 0755, true);
217+
}
218+
else
219+
{
220+
// Clear directory
221+
$iter = new \RecursiveDirectoryIterator($target);
222+
foreach (new \RecursiveIteratorIterator($iter, \RecursiveIteratorIterator::CHILD_FIRST) as $f)
223+
{
224+
if ($f->isDir())
225+
{
226+
if (!in_array($f->getFilename(), array('.', '..'))) {
227+
rmdir($f->getPathname());
228+
}
229+
} else {
230+
unlink($f->getPathname());
231+
}
232+
}
233+
}
234+
235+
if (is_dir($target))
236+
{
237+
$result = true; // needed for empty directories
238+
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
239+
foreach ($iterator as $f)
240+
{
241+
if ($f->isDir()) {
242+
$path = $target.'/'.$iterator->getSubPathName();
243+
if (!is_dir($path)) {
244+
$result = mkdir($path);
245+
}
246+
} else {
247+
$result = copy($f, $target.'/'.$iterator->getSubPathName());
248+
}
249+
250+
if ($result === false) {
251+
break;
252+
}
253+
}
254+
}
255+
256+
return $result;
257+
}
173258
}

src/Nooku/Composer/Installer/NookuFramework.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
3838
$query = 'UPDATE #__extensions SET enabled = 1 WHERE type = \'plugin\' AND element = \'koowa\' AND folder = \'system\'';
3939
\JFactory::getDBO()->setQuery($query)->query();
4040

41-
$this->_loadKoowaPlugin();
41+
$this->_loadFramework();
4242
}
4343

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

5252
protected function _isValidName($packageName)
5353
{
54-
return in_array($packageName, array('nooku/nooku-framework', 'nooku/nooku-framework-joomla'));
54+
return $packageName === 'nooku/nooku-framework-joomla';
5555
}
5656
}

src/Nooku/Composer/Joomla/Application.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use \JDispatcher as JDispatcher;
1414
use \JFactory as JFactory;
1515
use \JInstaller as JInstaller;
16-
use \JPluginHelper as JPluginHelper;
1716
use \JSession as JSession;
1817
use \JRouter as JRouter;
1918
use \JVersion as JVersion;
@@ -75,6 +74,7 @@ protected function _initialize()
7574
jimport('joomla.utilities.arrayhelper');
7675

7776
jimport('joomla.application.module.helper');
77+
jimport('joomla.application.router');
7878

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

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

120117
/**

0 commit comments

Comments
 (0)