Public paste
Undefined
By: Guest | Date: Mar 27 2010 12:52 | Format: PHP | Expires: never | Size: 7.4 KB | Hits: 943

  1. <?php
  2.  
  3.         FINAL CLASS ILLI_Constructeur
  4.         {
  5.                 private static $SELF        = NULL;
  6.                 private $INSTANCES           = NULL;
  7.                 private static $initialized = FALSE;
  8.                 private static $executed    = FALSE;
  9.                
  10.                 private static $applicationProfile        = '';
  11.                 private static $applicationConfiguration  = array();
  12.                
  13.                 private function __construct()
  14.                 {
  15.                         $this->INSTANCES =& new ILLI_InstanceLoader;
  16.                                
  17.                         $this->INSTANCES
  18.                                 -> setNameMask('ILLI_Sequence')
  19.                                 -> setReferenceObject($this)
  20.                                 -> load(Api)
  21.                                 -> load(Boot)
  22.                                 -> load(Frontend)
  23.                                 -> load(Output)
  24.                                 -> init();
  25.                 }
  26.                
  27.                 public function __get($name)
  28.                 {
  29.                         return $this->INSTANCES->$name;
  30.                 }
  31.                
  32.                 public static function init(ILLI $ILLI)
  33.                 {
  34.                         try
  35.                         {
  36.                                 if(FALSE === self::$initialized)
  37.                                         self::$initialized = TRUE;
  38.                                 else throw new ILLI_Constructeur_Exception
  39.                                         ('ILLI already initialized..');
  40.                                
  41.                                 if(NULL === self::$SELF)
  42.                                         self::$SELF =& new self;
  43.                                        
  44.                                 return self::$SELF;
  45.                         }
  46.                         catch(ILLI_Constructeur_Exception $e){$e->w();}
  47.                 }
  48.        
  49.                 public function run(ILLI $ILLI)
  50.                 {
  51.                         try
  52.                         {
  53.                                 if(FALSE === self::$initialized)
  54.                                         throw new ILLI_Constructeur_Exception
  55.                                                 ('ILLI not initialized..');
  56.                                        
  57.                                 if(FALSE === self::$executed)
  58.                                         self::$executed = TRUE;
  59.                                 else throw new ILLI_Constructeur_Exception
  60.                                         ('Can not execute ILLI again.');
  61.                                        
  62.                                 $this->defaults();
  63.                                        
  64.                                 $this->INSTANCES->run();
  65.                         }
  66.                         catch(ILLI_Constructeur_Exception $e){$e->w();}
  67.                                
  68.                         return self::$SELF;
  69.                 }
  70.                
  71.                 private function defaults()
  72.                 {                      
  73.                         if(empty(self::$applicationProfile))
  74.                                 $this->setApplicationProfile('localhost');
  75.                 }
  76.                
  77.                 public static function shutdown(ILLI_Constructeur $ILLI_Constructeur)
  78.                 {
  79.                         self::$initialized = FALSE;
  80.                         self::$executed    = FALSE;
  81.                         self::$INSTANCES   = NULL;
  82.                         self::$SELF        = NULL;
  83.                 }
  84.                
  85.                 public function setApplicationProfile($name)
  86.                 {
  87.                         try
  88.                         {
  89.                                 if(!is_scalar($name))
  90.                                         throw new ILLI_Constructeur_Exception
  91.                                                 ('ILLI-applicationprofile is not scalar.');
  92.                                                
  93.                                 self::$applicationProfile = $name;
  94.                         }
  95.                         catch(ILLI_Constructeur_Exception $e){$e->w();}
  96.                 }
  97.                
  98.                 public function getApplicationProfile()
  99.                 {
  100.                         return self::$applicationProfile;
  101.                 }
  102.                
  103.                 public function setApplicationConfiguration($key, $value)
  104.                 {
  105.                         try
  106.                         {
  107.                                 if(!is_string($key))
  108.                                         throw new ILLI_Constructeur_Exception
  109.                                                 ('ILLI-configuration-key is not scalar.');
  110.                                                
  111.                                 self::$applicationConfiguration[strtoupper($key)] = $value;
  112.                         }
  113.                         catch(ILLI_Constructeur_Exception $e){$e->w();}
  114.                 }
  115.                
  116.                 public function getApplicationConfiguration()
  117.                 {
  118.                         return self::$applicationConfiguration;
  119.                 }
  120.         }
  121.  
  122.         ABSTRACT CLASS ILLI_InstanceConstructeur
  123.         {
  124.                 protected $INSTANCES             = NULL;
  125.                 protected $OWNER                 = NULL;
  126.                 protected $_root                 = NULL;
  127.                 protected $fileLocation          = '';
  128.                 protected static $childNameMask = '';
  129.                 protected static $initialized   = array();
  130.                 protected static $executed      = array();
  131.                
  132.                 final public function execute()
  133.                 {
  134.                         self::$initialized[get_class($this)] = TRUE;
  135.                        
  136.                         $this->INSTANCES->run();
  137.                                
  138.                         if(!array_key_exists(get_class($this), self::$executed) || self::$executed[get_class($this)] === FALSE )
  139.                                 if(method_exists($this, 'run'))
  140.                                 {
  141.                                         $this->run();
  142.                                         self::$executed[get_class($this)] = TRUE;
  143.                                 }                                      
  144.                        
  145.                                
  146.                         return $this;
  147.                 }
  148.                
  149.                 final public function __get($name)
  150.                 {
  151.                         return $this->INSTANCES->$name;
  152.                 }
  153.                
  154.                 final public function __call($name, $arguments)
  155.                 {
  156.                         try
  157.                         {
  158.                                 throw new ILLI_Sequence_Exception
  159.                                         ('Method '.$name.' not found in '.get_class($this));
  160.                         }
  161.                         catch(ILLI_Sequence_Exception $e){$e->w();}
  162.                 }
  163.                
  164.                 final protected function &setInstanceLoader(&$fileLocation)
  165.                 {
  166.                         $this->fileLocation =& $fileLocation;
  167.                         $this->INSTANCES =& new ILLI_InstanceLoader($this->fileLocation);
  168.                         return $this;
  169.                 }
  170.                
  171.                 final protected function setInstanceOwner(&$OBJ)
  172.                 {
  173.                         try
  174.                         {
  175.                                 if(!is_object($OBJ))
  176.                                         throw new ILLI_Sequence_Exception
  177.                                                 ('Given variable is not an object');
  178.                         }
  179.                         catch(ILLI_Sequence_Exception $e){$e->w();}
  180.                        
  181.                         $this->OWNER =& $OBJ;
  182.                         return $this;
  183.                 }
  184.                
  185.                 final protected function setChildNameMask($childNameMask = '')
  186.                 {
  187.                         $this->childNameMask = $childNameMask;
  188.                         return $this;
  189.                 }
  190.                
  191.                 final protected function getChildNameMask($childNameMask = '')
  192.                 {
  193.                         return $this->childNameMask;
  194.                 }
  195.                
  196.                 final protected function setRoot(ILLI_Constructeur &$ROOT_OBJ)
  197.                 {
  198.                         $this->_root =& $ROOT_OBJ;
  199.                         return $this;
  200.                 }
  201.                
  202.                 final protected function getRoot()
  203.                 {
  204.                         return $this->_root;
  205.                 }
  206.                
  207.                 final protected function getFileLocation()
  208.                 {
  209.                         return $this->fileLocation;
  210.                 }
  211.                
  212.                 final protected function load($class)
  213.                 {
  214.                         foreach(array('exception', 'abstract', 'class', 'package') as $type)
  215.                                 if(is_file(($file = $this->getFileLocation().$class.'.'.$type.'.php')))
  216.                                         require_once $file;
  217.                                        
  218.                         return $this;
  219.                 }
  220.                                
  221.                
  222.                 abstract public function __construct();
  223.                 abstract public function init();
  224.                 abstract public function run();
  225.                
  226.         }
  227.        
  228.  
  229.         ABSTRACT CLASS ILLI_ShortcutsPrimary EXTENDS ILLI_InstanceConstructeur
  230.         {              
  231.                 final protected function set(&$OWNER, $fileLocation)
  232.                 {
  233.                         $this
  234.                                 ->setChildNameMask('_Link')
  235.                                 ->setInstanceOwner($OWNER)
  236.                                 ->setRoot($OWNER)
  237.                                 ->setInstanceLoader($fileLocation);
  238.                 }
  239.         }
  240.  
  241.        
  242.         ABSTRACT CLASS ILLI_Sequence EXTENDS ILLI_ShortcutsPrimary
  243.         {
  244.                 final public function __construct(ILLI_Constructeur &$ILLI_Constructeur, $fileLocation)
  245.                 {
  246.                         $this->set($ILLI_Constructeur, $fileLocation);
  247.                 }
  248.         }
  249.  
  250.         FINAL CLASS ILLI_SequenceFrontend EXTENDS ILLI_Sequence
  251.         {
  252.                 public function init()
  253.                 {
  254.                         $this->INSTANCES
  255.                                 -> setNameMask(__CLASS__.$this->getChildNameMask())
  256.                                 -> setReferenceObject($this)        
  257.                                 -> load(Form)
  258.                                 -> load(View)
  259.                                 -> init();
  260.  
  261.                         return $this;
  262.                 }
  263.  
  264.                 public function run(){}
  265.         }
  266.  
  267.         ABSTRACT CLASS ILLI_ShortcutsSecondary EXTENDS ILLI_InstanceConstructeur
  268.         {
  269.                 final protected function set(&$OWNER, $fileLocation)
  270.                 {
  271.                         $this
  272.                                 ->setChildNameMask('_Segment')
  273.                                 ->setInstanceOwner($OWNER)
  274.                                 ->setRoot($OWNER->OWNER)
  275.                                 ->setInstanceLoader($fileLocation);
  276.                 }
  277.         }
  278.  
  279.         ABSTRACT CLASS ILLI_SequenceFrontend_Link EXTENDS ILLI_ShortcutsSecondary
  280.         {
  281.                 final public function __construct(ILLI_SequenceFrontend &$ILLI_SequenceFrontend, $fileLocation)
  282.                 {
  283.                         $this->set($ILLI_SequenceFrontend, $fileLocation);
  284.                 }
  285.         }
  286.  
  287.         FINAL CLASS ILLI_SequenceFrontend_LinkForm EXTENDS ILLI_SequenceFrontend_Link
  288.         {
  289.                
  290.                 private $FORMS         = NULL;
  291.                 private $CURRENT_FORM  = NULL;
  292.                 private $CURRENT_FIELD = NULL;
  293.                 private $PATTERNS      = NULL;
  294.                
  295.                 public function init()
  296.                 {
  297.                 }
  298.                
  299.                 public function run()
  300.                 {
  301.                 }
  302.         }
  303.  
  304.         ABSTRACT CLASS ILLI_ShortcutsTertiary EXTENDS ILLI_InstanceConstructeur
  305.         {      
  306.                 final protected function set(&$OWNER, $fileLocation)
  307.                 {
  308.                         $this
  309.                                 ->setChildNameMask('_Sub')
  310.                                 ->setInstanceOwner($OWNER)
  311.                                 ->setRoot($OWNER->OWNER->OWNER)
  312.                                 ->setInstanceLoader($fileLocation);
  313.                 }
  314.         }
  315.  
  316.         ABSTRACT CLASS ILLI_SequenceFrontend_LinkForm_Segment EXTENDS ILLI_ShortcutsTertiary
  317.         {
  318.                 final public function __construct(ILLI_SequenceFrontend_LinkForm &$ILLI_SequenceFrontend_LinkForm, $fileLocation)
  319.                 {
  320.                         $this->set($ILLI_SequenceFrontend_LinkForm, $fileLocation);
  321.                 }
  322.         }