Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 145 lines (128 sloc) 2.772 kb
3bc7523d »
2012-01-18 First commit
1 <?php
2 /**
c2378e5b »
2012-01-20 Remove all autoloading functionality
3 * Manages loading of classes.
3bc7523d »
2012-01-18 First commit
4 *
5 * @copyright Copyright (c) 2011 Poluza.
6 * @author Andrew Udvare [au] <andrew@poluza.com>
7 * @license http://www.opensource.org/licenses/mit-license.php
8 *
9 * @package Sutra
10 * @link http://www.example.com/
11 *
22e9cecf »
2012-04-05 Bump version
12 * @version 1.2
3bc7523d »
2012-01-18 First commit
13 */
14 class sLoader extends fLoader {
15 /**
16 * Path where Sutra is installed.
17 *
18 * @var string
19 */
20 private static $path = '';
21
22 /**
1b12bb4a »
2012-04-05 sLoader now only loads the Sutra classes; no model or router classes
23 * All the Sutra classes.
3bc7523d »
2012-01-18 First commit
24 *
25 * @var array
26 */
27 private static $classes = array(
3772a4fb »
2012-03-30 Add sArray static class for array-handling methods
28 'sArray',
b30938a5 »
2012-04-05 Update loader class; add sAuthorization to stable classes
29 'sAuthorization',
3bc7523d »
2012-01-18 First commit
30 'sCache',
1b12bb4a »
2012-04-05 sLoader now only loads the Sutra classes; no model or router classes
31 'sGrammar',
3bc7523d »
2012-01-18 First commit
32 'sHTML',
33 'sImage',
34 'sJSONP',
b30938a5 »
2012-04-05 Update loader class; add sAuthorization to stable classes
35 'sNumber',
7e583717 »
2012-03-22 Add sORMJSON; extension to fORMJSON with method to create a JSON seri…
36 'sORMJSON',
3bc7523d »
2012-01-18 First commit
37 'sProcess',
1b12bb4a »
2012-04-05 sLoader now only loads the Sutra classes; no model or router classes
38 'sProcessException',
88ec9cc0 »
2012-04-05 Update class loader
39 'sRequest',
40 'sResponse',
3bc7523d »
2012-01-18 First commit
41 'sTemplate',
42 'sTimestamp',
43 );
44
45 /**
de2e89c9 »
2012-04-05 Be a bit more like fLoader
46 * Override best() method.
3bc7523d »
2012-01-18 First commit
47 *
48 * @return void
c2378e5b »
2012-01-20 Remove all autoloading functionality
49 * @see sLoader::eagar()
3bc7523d »
2012-01-18 First commit
50 */
51 public static function best() {
de2e89c9 »
2012-04-05 Be a bit more like fLoader
52 if (self::hasOpcodeCache()) {
53 return sLoader::eagar();
54 }
55
56 self::lazy();
57 }
58
59 /**
60 * Creates constructor functions. This makes it possible to write:
61 *
62 * <code>new sProcess('node myscript')->execute();</code>
63 *
64 * @return void
65 */
66 private static function createConstructorFunctions() {
67 if (function_exists('sImage')) {
68 return;
69 }
70
71 function sImage($file_path, $skip_checks = FALSE) {
72 return new sImage($file_path, $skip_checks);
73 }
74
75 // Limited signature support
76 function sProcess($name) {
77 return new sProcess($name);
78 }
79
80 function sTimestamp($datetime, $timezone = NULL) {
6066cdb5 »
2012-04-05 Fix passing parameter in constructor function for sTimestamp
81 return new sTimestamp($datetime, $timezone);
de2e89c9 »
2012-04-05 Be a bit more like fLoader
82 }
3bc7523d »
2012-01-18 First commit
83 }
84
85 /**
b7d18c43 »
2012-01-29 Separate the loading of each type of class into separate methods
86 * Override eager() method to load Sutra classes after Flourish's.
87 *
88 * @return void
89 */
90 public static function eagar() {
91 parent::eager();
de2e89c9 »
2012-04-05 Be a bit more like fLoader
92
1b12bb4a »
2012-04-05 sLoader now only loads the Sutra classes; no model or router classes
93 self::setPath();
de2e89c9 »
2012-04-05 Be a bit more like fLoader
94 self::createConstructorFunctions();
95
1b12bb4a »
2012-04-05 sLoader now only loads the Sutra classes; no model or router classes
96 foreach (self::$classes as $class) {
97 require self::$path.$class.'.php';
98 }
27ddbc9b »
2012-01-21 Add method to retrieve path to the model classes
99 }
100
101 /**
3bc7523d »
2012-01-18 First commit
102 * Determines where Sutra is installed.
103 *
104 * @return void
105 */
1b12bb4a »
2012-04-05 sLoader now only loads the Sutra classes; no model or router classes
106 private static function setPath() {
3bc7523d »
2012-01-18 First commit
107 if (!self::$path) {
1b12bb4a »
2012-04-05 sLoader now only loads the Sutra classes; no model or router classes
108 self::$path = realpath(dirname(__FILE__)).'/';
3bc7523d »
2012-01-18 First commit
109 }
110 }
de2e89c9 »
2012-04-05 Be a bit more like fLoader
111
112 /**
113 * Registers a class auto-loader to load Sutra classes.
114 *
115 * @return void
116 */
117 public static function lazy() {
118 parent::lazy();
119
120 self::setPath();
121 self::createConstructorFunctions();
122
123 spl_autoload_register(array('sLoader', 'autoload'));
124 }
125
126 /**
127 * Tries to load a Sutra class.
128 *
129 * @internal
130 *
131 * @param string $class The class to load.
132 * @return void
133 */
134 public static function autoload($class) {
135 if ($class[0] != 's' || ord($class[1]) < 65 || ord($class[1]) > 90) {
136 return;
137 }
138
139 if (!in_array($class, self::$classes)) {
140 return;
141 }
142
143 require self::$path.$class.'.php';
144 }
3bc7523d »
2012-01-18 First commit
145 }
Something went wrong with that request. Please try again.