2 // @title Conventions (class of configurations and all)
3 // @author Matt Todd <matt@matttoddphoto.com>
5 // @desc Conventions and default values to be used throughout the system
6 // @requires stdexception.php (StdException class)
7 // @note Yes, it came a little late in the game.
9 // This file is to be clean
12 public static $app_dir = '';
14 // path info (for routing)
15 public static function path_info() {
16 return substr($_SERVER['PATH_INFO'], 1);
19 // 'directories' contains the directory names for various components.
20 // It will appear to be repetitive, but this is due to the fact that
21 // the keys are the same as the default so that the internal system
22 // never has to know it's something different!
23 public static $directories = array(
24 'library'=>'library', // standard and concrete for now
25 'adapters'=>'library/adapters',
26 'controllers'=>'controllers',
32 'extensions'=>'extensions',
35 // static method to get the directory name
36 public static function directory($name) {
37 return self
::$directories[$name];
40 // 'names' contains specifications for how names should be formed
41 // and derived. If custom functionality is desired, modify the
42 // names and the functions, such as to Camelize names for names
43 // as 'PublicController' instead of 'public_controller'
44 public static $names = array(
48 'cache'=> 'config.cache',
50 // the generic file (for non-specific config-files)
55 'routes'=> 'routes.php',
60 'controllers'=> array(
61 'class'=> '%s_controller',
62 'file'=> '%s_controller.php',
76 'file'=> '%s_view.php',
79 'layout' => 'layout.php',
84 'class'=> '%s_helper',
85 'file'=> '%s_helper.php',
102 'separate_file'=> '%s.%s.log'
106 // naming methods ///////////////////////////////////////////////////////////////////////////////////////////////////
107 // form standard names
109 // controller naming functions
110 public static function controller_name($name) {
111 return sprintf(self
::$names['controllers']['class'], $name);
113 public static function controller_class_name($name) {
114 return self
::controller_name($name);
116 public static function controller_file_name($name) {
117 return sprintf(self
::$names['controllers']['file'], $name);
120 public static function action_name($name) {
121 return sprintf(self
::$names['controllers']['action'], $name);
124 // model naming functions
125 public static function model_name($name) {
126 return sprintf(self
::$names['models']['class'], $name);
128 public static function model_class_name($name) {
129 return self
::model_name($name);
131 public static function model_file_name($name) {
132 return sprintf(self
::$names['models']['file'], $name);
135 // view naming functions
136 public static function view_name($name) {
137 return sprintf(self
::$names['views']['name'], $name);
139 public static function view_class_name($name) {
140 return sprintf(self
::$names['views']['class'], $name);
142 public static function view_class_file_name($name) {
143 return sprintf(self
::$names['views']['file'], $name);
145 public static function view_file_name($name) {
146 return sprintf(self
::$names['views']['action'], $name);
148 public static function view_controller_name($name) {
149 return sprintf(self
::$names['views']['controller'], $name);
151 public static function view_layout_file_name() {
152 return self
::$names['views']['layout'];
155 // helper naming functions
156 public static function helper_name($name) {
157 return sprintf(self
::$names['helpers']['class'], $name);
159 public static function helper_class_name($name) {
160 return self
::helper_name($name);
162 public static function helper_file_name($name) {
163 return sprintf(self
::$names['helpers']['file'], $name);
166 // extensions and libraries
167 public static function library_file_name($name) {
168 return sprintf(self
::$names['library']['file'], $name);
170 public static function extension_file_name($name) {
171 return sprintf(self
::$names['extensions']['file'], $name);
175 public static function adapter_file_name($name) {
176 return sprintf(self
::$names['library']['adapter'], strtolower($name));
179 // paths methods //////////////////////////////////////////////////////////////////////////////////////////////////////
181 // generic path function
182 public static function path($dir, $file) {
183 return self
::$app_dir . self
::directory($dir) . '/' . $file;
187 public static function controller_path($name) {
188 return self
::path('controllers', self
::controller_file_name($name));
191 public static function model_path($name) {
192 return self
::path('models', self
::model_file_name($name));
195 public static function view_path($controller, $name) {
196 return self
::path('views', (self
::view_controller_name($controller) . '/' . self
::view_file_name($name)));
198 public static function view_class_path($name) {
199 return self
::path('views', self
::view_class_name($name));
201 public static function view_class_file_path($name) {
202 return self
::path('views', self
::view_class_file_name($name));
205 public static function helper_path($name) {
206 return self
::path('helpers', self
::helper_file_name($name));
209 public static function library_path($name) {
210 return self
::path('library', self
::library_file_name($name));
213 public static function extension_path($name) {
214 return self
::path('extensions', self
::extension_file_name($name));
217 public static function adapter_path($name) {
218 return self
::path('adapters', self
::adapter_file_name($name));
221 // specific file methods //
224 public static function config_cache_file() {
225 return self
::path('config', self
::$names['config']['cache']);
228 public static function config_file($name) {
229 // if the filename is explicitly set, return that value
230 if(!empty(self
::$names['config']['files'][$name]))
231 return self
::path('config', self
::$names['config']['files'][$name]);
233 // otherwise, return the default form of the config file (such as '{$name}.yml')
234 return self
::path('config', sprintf(self
::$names['config']['file'], $name));
239 public static function log_file($name) {
240 return self
::path('logs', sprintf(self
::$names['logs']['file'], $name));
242 public static function separate_log_file($section, $name) {
243 return self
::path('logs', sprintf(self
::$names['logs']['separate_file'], $section, $name));