~tariq-daouda/shoof-cms/Very-experimental

« back to all changes in this revision

Viewing changes to modules/Shoof_Submodule.php

  • Committer: tariq
  • Date: 2010-07-25 19:20:06 UTC
  • Revision ID: tariq@sauropode-20100725192006-nwzl83xc58gwbqx2
Refactured module/submodule system :
Class module and class submodule

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
The class that every submodule should extend. A sub module must be php class, in a .php file of the same name.
 
4
It is singleton
 
5
*/
 
6
abstract class Shoof_Submodule{
 
7
        
 
8
        /** You must copy this line into your submodule class*/
 
9
        private static $instance = false;
 
10
        
 
11
        protected $loadTime = false;
 
12
        protected $name;
 
13
        protected $description;
 
14
        
 
15
        protected function __construct()
 
16
        {
 
17
                $this->name = get_class($this);
 
18
                $this->description = 'Submodule with no name, Hang him high';
 
19
                $this->help = 'No help available';
 
20
        }
 
21
        
 
22
        /**
 
23
        In my current version of php (5.2.4-2), self does not behave as it is expect it to bo in case of inheritance. In fact it is never inherited, therefor self::$instance refers to self::$instance of this class instead of refering to child's variable. Instead of using some bad taste crazy workarounds that would make the code clumsy and become completly useless in case php guys decide to fix this, I chosed to define an abstract function. Sorry you'll have to copy paste the singleton code (commented below) in every submodule.
 
24
        @return the current instance, creates it if it has to.
 
25
        */
 
26
        public abstract static function getInstance();
 
27
        /*
 
28
        {
 
29
           if(!self::$instance)
 
30
             self::$instance = new self();
 
31
           
 
32
           return self::$instance;
 
33
        }
 
34
        */
 
35
        
 
36
        /**
 
37
        Performs final actions, default is nothing. This is automaticly called before outputing the final html
 
38
        */
 
39
        public function wrapUp()
 
40
        {
 
41
        }
 
42
        
 
43
        /**
 
44
        Provides help about the submodule
 
45
        */
 
46
        
 
47
        public function help($print = true)
 
48
        {
 
49
                $h = $this->name.':<br>'.$this->help;
 
50
                if ($print)
 
51
                        echo $h;
 
52
                return $h;
 
53
        }
 
54
        
 
55
        /**
 
56
        Get submodule name
 
57
        */
 
58
        public function getName()
 
59
        {
 
60
                return $this->name;
 
61
        }
 
62
        /**
 
63
        Get submodule description
 
64
        */
 
65
        public function getDecription()
 
66
        {
 
67
                return $this->name.':<br>'.$this->description;
 
68
        }
 
69
 
 
70
}
 
71
?>