[Phphtmllib-devel] phphtmllib/scripts AutoloadGenerator.inc, 1.2, 1.3
Status: Beta
Brought to you by:
hemna
From: Walter A. B. I. <he...@us...> - 2006-07-28 03:14:55
|
Update of /cvsroot/phphtmllib/phphtmllib/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25259 Modified Files: AutoloadGenerator.inc Log Message: did a small bit of refactoring to make it more extendable. Added some setter methods to make it more flexible. Index: AutoloadGenerator.inc =================================================================== RCS file: /cvsroot/phphtmllib/phphtmllib/scripts/AutoloadGenerator.inc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- AutoloadGenerator.inc 20 Jul 2006 02:06:52 -0000 1.2 +++ AutoloadGenerator.inc 25 Jul 2006 22:40:50 -0000 1.3 @@ -65,7 +65,10 @@ * * @var array */ - protected $class_map = array(); + protected $class_map = array('class' => array(), + 'renderable' => array(), + 'menuable' => array(), + 'form_content' => array()); /** * List of extensions to scan @@ -80,7 +83,15 @@ * * @var array */ - protected $renderable_parents = array('HTMLPage', 'HTMLPage', 'HTMLDataList'); + protected $renderable_parents = array('HTMLPage', 'HTMLDataList'); + + /** + * list of class names that if extended will + * be added to the list of form_content classes + * + * @var array + */ + protected $formcontent_parents = array('FormContent', 'StandardFormContent'); /** * Keeps a list of files and directories to @@ -121,6 +132,66 @@ } /** + * Add an excluded file or directory path + * + * @param string + */ + public function add_exclude($path) { + $this->excluded_files[] = $path; + } + + /** + * This method is used to set the Project + * name. + * + * @param string $name + */ + public function set_project_name($name) { + $this->project_name = $name; + } + + /** + * This method allows you to add a new + * allowed extension to the list of + * acceptable files. + * + * @param string $extension (ie. .php) + */ + public function add_extension($extension) { + $this->allowed_extensions[] = $extension; + } + + /** + * Sets the path where to store the new + * autoload.inc file + * + * @param string $path + */ + public function set_autoload_path($path) { + $this->autoload_path = $path; + } + + /** + * add an entry to the list of Renderable + * parent classes + * + * @param string $class_name + */ + public function add_renderable_parent($class_name) { + $this->renderable_parents[] = $class_name; + } + + /** + * add an entry to the list of FormContent + * parent classes + * + * @param string $class_name + */ + public function add_form_content_parent($class_name) { + $this->formcontent_parents[] = $class_name; + } + + /** * Prints an error message and exits * * @param string $str @@ -184,11 +255,7 @@ $this->data[$class_name]['FILE_NAME']); } else { - $this->data[$class_name] = array('FILE_NAME' => $file_name); - - // here we store autoload data used - // by our temporary autoload function - self::$autoload_data[$class_name] = $file_name; + $this->add_file($class_name, $file_name); } } } @@ -196,6 +263,51 @@ } } + /** + * This method adds a new entry to the autoload table. + * + * @param string $class_name + * @param string $file_name + */ + protected function add_file($class_name, $file_name) { + $this->data[$class_name] = array('FILE_NAME' => $file_name); + + // here we store autoload data used + // by our temporary autoload function + self::$autoload_data[$class_name] = $file_name; + } + + + /** + * This method allows us to filter where the file gets + * placed in the classmap. + * + * @param ReflectionClass $reflect + * @param string $class_name + */ + protected function place_class($reflect, $class_name) { + // we do not analyze abstract classes + if ($reflect->implementsInterface('Menuable')) { + $this->class_map['menuable'][] = "'".$class_name."'"; + } + + foreach ($this->renderable_parents as $parent) { + if ($reflect->isSubclassOf($parent)) { + $this->class_map['renderable'][] = "'".$class_name."'"; + } + } + + foreach($this->formcontent_parents as $parent) { + if ($reflect->isSubclassOf($parent)) { + $this->class_map['form_content'][] = "'".$class_name."'"; + } + } + + //if ($reflect->implementsInterface('Soapable')) { + // $this->class_map['soapable'][] = $class_name; + //} + } + protected function write_autoload() { $str = "<?php\n" . "/**\n" . @@ -207,13 +319,16 @@ $str .= "class ClassMap {\n\n"; foreach ($this->class_map as $key => $data) { - $str .= 'static $' . $key . ' = array(' . "\n" . implode(",\n", $data). "\n\n);"; + $str .= 'static $' . $key . ' = array(' . "\n" . implode(",\n", $data). "\n\n);\n"; } $str .= "\n\n}\n\n". 'function __autoload($c) {require(ClassMap::$class[$c]);}' . "\n\n?>"; - file_put_contents($this->autoload_path . self::AUTOLOAD_FILENAME, $str); + + $path = $this->autoload_path . self::AUTOLOAD_FILENAME; + echo $path; + file_put_contents($path, $str); } /** @@ -225,7 +340,7 @@ print('Scanning ' . $this->scan_dir . ' ...'); $this->scan($this->scan_dir); - print("\nAnalyzing classes ..."); + print("\nAnalyzing classes ...(".count($this->data).")"); // now we analyze each class that we found foreach ($this->data as $class_name=>$data) { @@ -236,21 +351,7 @@ $reflect = new ReflectionClass($class_name); if (!$reflect->isAbstract()) { - // we do not analyze abstract classes - - if ($reflect->implementsInterface('Menuable')) { - $this->class_map['menuable'][] = $class_name; - } - -// if ($reflect->implementsInterface('Soapable')) { -// $this->class_map['soapable'][] = $class_name; -// } - - foreach ($this->renderable_parents as $parent) { - if ($reflect->isSubclassOf($parent)) { - $this->class_map['renderable'][] = $class_name; - } - } + $this->place_class($reflect, $class_name); } } print ("\n"); @@ -266,8 +367,7 @@ function __autoload($class_name) { require(AutoloadGenerator::$autoload_data[$class_name]); } +//$a = new AutoloadGenerator('/home/wboring/devel/phphtmllib'); +//$a->execute(); -$a = new AutoloadGenerator('/home/suren/devel/phphtmllib'); -$a->execute(); - -?> \ No newline at end of file +?> |