| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
// Disallow direct access. |
| 7 |
defined('ABSPATH') or die("Access denied"); |
| 8 |
|
| 9 |
/** |
| 10 |
* |
| 11 |
*/ |
| 12 |
class CJTAccessPointsDirectorySpider extends ArrayIterator { |
| 13 |
|
| 14 |
/** |
| 15 |
* put your comment there... |
| 16 |
* |
| 17 |
* @var mixed |
| 18 |
*/ |
| 19 |
protected $aPoints; |
| 20 |
|
| 21 |
/** |
| 22 |
* put your comment there... |
| 23 |
* |
| 24 |
* @var mixed |
| 25 |
*/ |
| 26 |
protected $dir; |
| 27 |
|
| 28 |
/** |
| 29 |
* put your comment there... |
| 30 |
* |
| 31 |
* @var mixed |
| 32 |
*/ |
| 33 |
protected $prefix; |
| 34 |
|
| 35 |
/** |
| 36 |
* put your comment there... |
| 37 |
* |
| 38 |
* @param mixed $dir |
| 39 |
* @return CJTAccessPoints |
| 40 |
*/ |
| 41 |
public function __construct($prefix, $dir) { |
| 42 |
// Initialize specifc! |
| 43 |
$this->prefix = $prefix; |
| 44 |
$this->dir = $dir; |
| 45 |
// Load access points! |
| 46 |
$this->load(); |
| 47 |
// ArrayIterator. |
| 48 |
parent::__construct($this->aPoints); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* put your comment there... |
| 53 |
* |
| 54 |
* @param mixed $prefix |
| 55 |
* @param mixed $dir |
| 56 |
*/ |
| 57 |
public static function getInstance($prefix, $dir) { |
| 58 |
return new CJTAccessPointsDirectorySpider($prefix, $dir); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* put your comment there... |
| 63 |
* |
| 64 |
* @return CJTAccessPointsDirectorySpider Returns $this. |
| 65 |
*/ |
| 66 |
protected function load() { |
| 67 |
// Reset access points! |
| 68 |
$this->aPoints =array(); |
| 69 |
// Get all defined ap inside the specified directory! |
| 70 |
$accessPoints = new DirectoryIterator($this->dir); |
| 71 |
foreach ($accessPoints as $file) { |
| 72 |
if (!$file->isDir()) { |
| 73 |
// Build point info! |
| 74 |
$point = array(); |
| 75 |
$point['file'] = $file->getFilename(); |
| 76 |
$point['name'] = $file->getBaseName('.accesspoint.php'); |
| 77 |
$point['class'] = "{$this->prefix}{$point['name']}AccessPoint"; |
| 78 |
// Add to points list! |
| 79 |
$this->aPoints[$point['name']] = $point; |
| 80 |
} |
| 81 |
} |
| 82 |
return $this; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* put your comment there... |
| 87 |
* |
| 88 |
*/ |
| 89 |
public function point() { |
| 90 |
// Get access point info! |
| 91 |
$point =& $this[$this->key()]; |
| 92 |
// Full absolulte path to access point file! |
| 93 |
$absPath = "{$this->dir}/{$point['file']}"; |
| 94 |
// Instantiate point class, this will put it in action! |
| 95 |
include_once $absPath; |
| 96 |
return new $point['class'](); |
| 97 |
} |
| 98 |
|
| 99 |
} // End class. |
| 100 |
|