Skip to content

Commit

Permalink
optimized I/O methods
Browse files Browse the repository at this point in the history
  • Loading branch information
oohnoitz committed Jan 22, 2015
1 parent 245ec63 commit f777b3e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
46 changes: 29 additions & 17 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public function addDir($dir = null)
throw new \DomainException('Directory not found.');
}

$this->dirs[] = rtrim($dir, '/');

// set the flag to reload packages on demand
$this->reload = true;
$this->dirs[] = ['path' => rtrim($dir, '/'), 'loaded' => false];

return $this;
}
Expand All @@ -120,21 +117,24 @@ public function find()
$this->packages = array();
}

foreach ($this->dirs as $dir) {
$vendor_paths = $this->findDirs($dir);
foreach ($this->dirs as $pack => $dir) {
if ($dir['loaded'] === false) {
$vendors = $this->findDirs($dir['path']);

foreach ($vendor_paths as $vendor_name => $vendor_path) {
$package_paths = $this->findDirs($vendor_path);
foreach ($vendors as $vendor_name => $vendor_path) {
$packages = $this->findDirs($vendor_path);

foreach ($package_paths as $package_name => $package_path) {
if (!isset($this->packages[$vendor_name.'/'.$package_name])) {
/* @var $package \Foolz\Package\Package */
$package = new $this->type_class($package_path);
$package->setLoader($this);
foreach ($packages as $package_name => $package_path) {
if (!isset($this->packages[$vendor_name.'/'.$package_name])) {
$package = new $this->type_class($package_path);
$package->setLoader($this);

$this->packages[$vendor_name.'/'.$package_name] = $package;
$this->packages[$vendor_name.'/'.$package_name] = $package;
}
}
}

$this->dirs[$pack]['loaded'] = true;
}
}
}
Expand Down Expand Up @@ -175,9 +175,7 @@ protected function findDirs($path)
*/
public function getAll()
{
if ($this->reload === true) {
$this->find();
}
$this->find();

return $this->packages;
}
Expand Down Expand Up @@ -258,4 +256,18 @@ public function getBaseUrl()

return $this->base_url;
}

/**
* @return \Foolz\Theme\Loader
*/
public function reload()
{
foreach ($this->dirs as $pack => $dir) {
$this->dirs[$pack]['loaded'] = false;
}

$this->packages = array();

return $this;
}
}
3 changes: 2 additions & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class Package
*/
public function __construct($dir)
{
$dir = rtrim($dir,'/').'/';
$dir = rtrim($dir, '/').'/';

if (!file_exists($dir.'composer.json')) {
throw new \DomainException('Directory not found.');
}
Expand Down

0 comments on commit f777b3e

Please sign in to comment.