root/trunk/lib/SGL/Task.php

Revision 3125, 4.3 kB (checked in by demian, 3 weeks ago)

bugfix to trunk merge -3

  • Property svn:eol-style set to native
Line 
1 <?php
2 /* Reminder: always indent with 4 spaces (no tabs). */
3 // +---------------------------------------------------------------------------+
4 // | Copyright (c) 2006, Demian Turner                                         |
5 // | All rights reserved.                                                      |
6 // |                                                                           |
7 // | Redistribution and use in source and binary forms, with or without        |
8 // | modification, are permitted provided that the following conditions        |
9 // | are met:                                                                  |
10 // |                                                                           |
11 // | o Redistributions of source code must retain the above copyright          |
12 // |   notice, this list of conditions and the following disclaimer.           |
13 // | o Redistributions in binary form must reproduce the above copyright       |
14 // |   notice, this list of conditions and the following disclaimer in the     |
15 // |   documentation and/or other materials provided with the distribution.    |
16 // | o The names of the authors may not be used to endorse or promote          |
17 // |   products derived from this software without specific prior written      |
18 // |   permission.                                                             |
19 // |                                                                           |
20 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       |
21 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         |
22 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     |
23 // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
24 // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     |
25 // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT          |
26 // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     |
27 // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
28 // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
29 // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE     |
30 // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.      |
31 // |                                                                           |
32 // +---------------------------------------------------------------------------+
33 // | Seagull 0.6                                                               |
34 // +---------------------------------------------------------------------------+
35 // | Task.php                                                                  |
36 // +---------------------------------------------------------------------------+
37 // | Author:   Demian Turner <demian@phpkitchen.com>                           |
38 // +---------------------------------------------------------------------------+
39 class SGL_Task
40 {
41     /**
42      * @abstract
43      *
44      */
45     function run($data = null)
46     {
47         return;
48     }
49
50    /**
51     * Example ...
52     * @access private
53     */
54     function &_getDal()
55     {
56         $oServiceLocator = &ServiceLocator::instance();
57         $oDal = $oServiceLocator->get('dal');
58         if (!$oDal) {
59             $oDal = &DA_FooBar::singleton();
60             $oServiceLocator->register('dal', $oDal);
61         }
62         return $oDal;
63     }
64 }
65
66 /**
67  * Used for building and running a task list.
68  *
69  */
70 class SGL_TaskRunner
71 {
72    /**
73     * collection of Task objects
74     * @var array
75     */
76     var $aTasks = array();
77     var $data = null;
78
79     function addData($data)
80     {
81         $this->data = $data;
82     }
83
84    /**
85     * Method to register a new Task object in
86     * the runner collection of tasks
87     *
88     * @param object $oTask of type Task
89     * @return boolean true on add success false on failure
90     * @access public
91     */
92     function addTask($oTask)
93     {
94         if (is_a($oTask, 'SGL_Task')) {
95             $this->aTasks[] = & $oTask;
96             return true;
97         }
98         return PEAR::raiseError('an SGL_Task object was expected');
99     }
100
101     function main()
102     {
103         $ret = array();
104         foreach ($this->aTasks as $k => $oTask) {
105             $ret[] = $this->aTasks[$k]->run($this->data);
106         }
107         return implode('', $ret);
108     }
109 }
110
111 ?>
Note: See TracBrowser for help on using the browser.