Bootstrap 的运行初始化
利用 Zend Framework 编程,个人一般偏爱以下方式作为程序入口,而不用完全自己组装
abstract class Zend_Application_Bootstrap_BootstrapAbstract implements Zend_Application_Bootstrap_Bootstrapper, Zend_Application_Bootstrap_ResourceBootstrapper{//... public function getClassResources() { if (null === $this->_classResources) { if (version_compare(PHP_VERSION, '5.2.6') === -1) { $class = new ReflectionObject($this); $classMethods = $class->getMethods(); $methodNames = array(); foreach ($classMethods as $method) { $methodNames[] = $method->getName(); } } else { $methodNames = get_class_methods($this); } $this->_classResources = array(); foreach ($methodNames as $method) { if (5 < strlen($method) && '_init' === substr($method, 0, 5)) { $this->_classResources[strtolower(substr($method, 5))] = $method; } } } return $this->_classResources; } //...}?
注册为类资源后,将会被自动调用,代码如下:
写道protected function _bootstrap($resource = null)
{
if (null === $resource) {
foreach ($this->getClassResourceNames() as $resource) {
$this->_executeResource($resource);
}
foreach ($this->getPluginResourceNames() as $resource) {
?? $this->_executeResource($resource);
}
} elseif (is_string($resource)) {
$this->_executeResource($resource);
} elseif (is_array($resource)) {
foreach ($resource as $r) {
$this->_executeResource($r);
}
} else {
throw new Zend_Application_Bootstrap_Exception('Invalid argument passed to ' . __METHOD__);
}
}?
?
?
?