Example #1
0
 /**
  * Load crude configuration.
  *
  * @return  bool  returns true on success or sets error messages and returns false.
  */
 public static function config()
 {
     // load crude configuration
     $config_path = CRUDEPATH . 'config' . DS . 'crude.php';
     if (!File::file_exists($config_path)) {
         Error::set(CRUDE_ERROR, 'Crude config file was not found');
         Error::set(CRUDE_SOLUTION, 'Check that <code>CRUDEPATH' . DS . 'config' . DS . 'crude.php</code> exists, is readable and is properly formatted');
         return false;
     } else {
         // file must be readable
         if (!is_readable($config_path)) {
             Error::set(CRUDE_ERROR, 'Crude config file is not readable');
             Error::set(CRUDE_SOLUTION, 'Check that <code>CRUDEPATH' . DS . 'config' . DS . 'crude.php</code> is readable');
             return false;
         }
         // file size must be greater than 700 bytes
         $filesize = filesize($config_path);
         if ($filesize < 700) {
             Error::set(CRUDE_ERROR, 'Crude config file appears to be corrupt. File size less than 700 bytes. ' . $filesize . ' bytes found');
             Error::set(CRUDE_SOLUTION, 'Check that <code>CRUDEPATH' . DS . 'config' . DS . 'crude.php</code> is properly formatted');
             return false;
         }
         // load crude configuration
         \Config::load('crude', true);
     }
     return true;
 }
Example #2
0
 /**
  * Get stencil data.
  *
  * @return  mixed   returns the array or string on success or false on failure
  */
 public static function get($stencil_name, $key = null)
 {
     $stencil_path = STENCILSPATH . $stencil_name . DS . 'config.php';
     if (!File::file_exists($stencil_path)) {
         return false;
     }
     if (!($stencil_data = \Fuel::load($stencil_path))) {
         return false;
     }
     // return value if key found
     if (isset($key)) {
         if (isset($stencil_data[$key])) {
             return $stencil_data[$key];
         } else {
             return false;
         }
     }
     // build inflections replacement array
     $tbl_singular = Table::get('crud.TBL_SINGULAR');
     $tbl_plural = Table::get('crud.TBL_PLURAL');
     if ($tbl_prefix = Table::get('crud.TBL_PREFIX')) {
         $pfx_path = str_replace('_', DS, $tbl_prefix);
         $tbl_singular = str_replace($tbl_prefix, $pfx_path, $tbl_singular);
         $tbl_plural = str_replace($tbl_prefix, $pfx_path, $tbl_plural);
     }
     $inflections = array(':SINGULAR' => $tbl_singular, ':PLURAL' => $tbl_plural);
     // make the replacements
     foreach ($stencil_data['files'] as $key => $value) {
         $stencil_data['files'][$key]['output_path'] = str_replace(array_keys($inflections), array_values($inflections), $value['output_path']);
     }
     return $stencil_data;
 }