diff options
author | Steve Dibb <beandog@gentoo.org> | 2010-02-03 13:41:17 +0000 |
---|---|---|
committer | Steve Dibb <beandog@gentoo.org> | 2010-02-03 13:41:17 +0000 |
commit | f1077f05773037ea78d2d62c7367cdc3eecd6e09 (patch) | |
tree | 889c667d3b84911b9a4724a6d7aee27b377b44c7 /class.portage.tree.php | |
parent | Use singleton (diff) | |
download | znurt-org-backend-f1077f05773037ea78d2d62c7367cdc3eecd6e09.tar.gz znurt-org-backend-f1077f05773037ea78d2d62c7367cdc3eecd6e09.tar.bz2 znurt-org-backend-f1077f05773037ea78d2d62c7367cdc3eecd6e09.zip |
Stop extending PortageTree and use singleton instead
git-svn-id: file:///var/svn/portage@80 3218660a-b0cf-4799-a991-8ddcc5b9e0f3
Diffstat (limited to 'class.portage.tree.php')
-rw-r--r-- | class.portage.tree.php | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/class.portage.tree.php b/class.portage.tree.php index c9ba655..e413990 100644 --- a/class.portage.tree.php +++ b/class.portage.tree.php @@ -2,27 +2,42 @@ class PortageTree { + private static $instance; + // Strings protected $tree; // Arrays protected $arr_licenses; - function __construct($tree = "/usr/portage") { + public function __construct($tree = "/usr/portage") { + + global $hits; + $hits['tree']++; + if($tree) $this->setTree($tree); } - function getTree() { + public static function singleton() { + if (!isset(self::$instance)) { + $c = __CLASS__; + self::$instance = new $c; + } + + return self::$instance; + } + + public function getTree() { return $this->tree; } - function setTree($x) { + public function setTree($x) { if(is_string($x) && is_dir($x)) $this->tree = $x; } - function getArches($prefix = false) { + public function getArches($prefix = false) { $filename = $this->getTree().'/profiles/arch.list'; $arr = file($filename, FILE_IGNORE_NEW_LINES); @@ -79,7 +94,7 @@ } - function getLicenses() { + public function getLicenses() { $scandir = scandir($this->getTree().'/licenses/'); $scandir = preg_grep('/^\.{1,2}$/', $scandir, PREG_GREP_INVERT); @@ -132,7 +147,7 @@ * * @return array */ - function getHerds() { + public function getHerds() { $arr = array(); |