-
- header("Content-type:text/html; charset=utf-8");
-
- class Collection{
- private $_members=array();
- private $_onload;
- private $_isLoaded=false;
-
- パブリック関数 startLoad(){
- $this->_checkCallback();
- }
-
- パブリック関数 addItem($obj,$key=NULL){
- $this->_checkCallback();
- if($key){
- if(isset($this->_members[$key])){
- throw new Exception("キー \"$key\" はすでに使用されています!");
- }else{
- $this->_members[$key]=$obj;
- }
- }else{
- $this->_members[]=$obj;
- }
- }
-
- public function RemoveItem($key){
- $this ->_checkCallback();
- if(isset($this->_members[$key])){
- unset($this->_members[$key]);
- }else{
- throw new Exception("無効なキー \"$key\"!");
- }
- }
-
- public function getItem($key){
- $this->_checkCallback();
- if(isset($this->_members[$key ])){
- return $this->_members[$key];
- }else{
- throw new Exception("無効なキー \"$key\"!");
- }
- }
-
- パブリック ファンクション キー() {
- $this->_checkCallback();
- return array_keys($this->_members);
- }
-
- public 関数 length(){
- $this->_checkCallback();
- return sizeof($this- >_members);
- }
-
- public 関数存在します($key){
- $this->_checkCallback();
- return (isset($this->_members[$key]));
- }
-
- public function setLoadCallback($functionName,$objOrClass=NULL){
- if($objOrClass){
- $callback=array($objOrClass,$functionName);
- }else{
- $callback=$functionName;
- }
-
- if(! is_callable($callback)){
- /*throw new Exception("$callableName is not callable"."as aparameter to oonload");*/
- echo "$callback is not callable
";
- return false;
- }
-
- $this->onload=$callback;
- }
-
- プライベート関数 _checkCallback(){
- if(isset($this->onload)&&!$this->_isLoaded){
- $this- >_isLoaded=true;
- call_user_func($this->_onload,$this);
- }
- }
- }
-
-
复制代
|