/[drupal]/contributions/modules/drake/lib/drake.class.php
ViewVC logotype

Contents of /contributions/modules/drake/lib/drake.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sun Feb 25 18:10:10 2007 UTC (2 years, 9 months ago) by mgiglesias
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Initial Release for Drupal 5.0
1 <?php
2
3 /**
4 * Drake class file.
5 *
6 * Class that offers Drake callables.
7 *
8 * @filesource
9 * @link http://dev.sypad.com/projects/drake Drake
10 * @package drake
11 * @subpackage drupal.lib
12 * @since 1.0
13 */
14
15 /**
16 * Drake Callables.
17 *
18 * @author Mariano Iglesias - mariano@cricava.com
19 * @package drake
20 * @subpackage drupal.lib
21 */
22 class Drake
23 {
24 /**#@+
25 * @access private
26 */
27 /**
28 * Drupal's root URL.
29 *
30 * @since 1.0
31 * @var string
32 */
33 var $drupalUrl;
34
35 /**
36 * Current CakePHP application identifier.
37 *
38 * @since 1.0
39 * @var string
40 */
41 var $application;
42 /**#@-*/
43
44 /**
45 * Singleton implementation (PHP4/PHP5)
46 *
47 * @return mixed A shared instance
48 *
49 * @access public
50 * @static
51 * @since 1.0
52 */
53 function &getInstance()
54 {
55 static $instances = array();
56
57 $className = __CLASS__;
58
59 if (!isset($instances[$className]))
60 {
61 $instances[$className] = new $className();
62 }
63
64 return $instances[$className];
65 }
66
67 function Object()
68 {
69 $args = func_get_args();
70
71 if (method_exists($this, '__destruct'))
72 {
73 register_shutdown_function(array(&$this, '__destruct'));
74 }
75
76 call_user_func_array(array(&$this, '__construct'), $args);
77 }
78
79 function __construct()
80 {
81 }
82
83 /**
84 * Set Drupal's URL.
85 *
86 * @param string $drupalUrl Drupal's URL
87 *
88 * @access public
89 * @since 1.0
90 */
91 function setDrupalUrl($drupalUrl)
92 {
93 $this->drupalUrl = $drupalUrl;
94 }
95
96 /**
97 * Set current CakePHP application.
98 *
99 * @param string $application Current application
100 *
101 * @access public
102 * @since 1.0
103 */
104 function setApplication($application)
105 {
106 $this->application = $application;
107 }
108
109 /**
110 * Returns if CakePHP application is being run on Drake.
111 *
112 * @return bool true if it is running on Drake, false otherwise
113 *
114 * @access public
115 * @since 1.0
116 */
117 function isDrake()
118 {
119 return defined('DRAKE');
120 }
121
122 /**
123 * Gets the URL to execute the specified CakePHP action with Drake
124 *
125 * @param string $action CakePHP URL. (leave empty for default cake action)
126 * @param string $application The identifier of the application in the configuration file (leave empty for default)
127 *
128 * @return string A valid Drake URL
129 *
130 * @access public
131 * @since 1.0
132 */
133 function getUrl($action = null, $application = null)
134 {
135 if ($this->isDrake() && isset($this->cakeApplicationId))
136 {
137 $application = $this->cakeApplicationId;
138 }
139
140 $url = $this->drupalUrl . (isset($application) ? '/' . $application : '');
141
142 if (isset($action))
143 {
144 $url .= (strpos($url, '?') !== false ? '&' : '?');
145 $url .= 'run=' . urlencode($action);
146 }
147
148 return $url;
149 }
150 }
151
152 ?>

  ViewVC Help
Powered by ViewVC 1.1.2