/** * * @param string $moduleName * @param array $defaults * @return Ac_Module */ public static function factory($moduleName, $defaults = array()) { $path = $moduleName == "app" ? AC_PATH_APP : AC_PATH_MODULES . $moduleName . _DS; if (!is_dir($path)) { Ac::log()->fatal($path, "Module not found at given path", __FILE__, __LINE__); } $moduleClass = 'Module_' . ucfirst($moduleName); $classFound = false; //Try to load the moduleClass using the HMVC power if (Ac::loader()->autoload($moduleClass)) { $classFound = true; } else { //Lookup under the module /classes dir $moduleFile = $path . 'classes' . _DS . 'module' . _DS . strtolower($moduleName) . '.php'; if (is_readable($moduleFile)) { include_once $moduleFile; if (class_exists($moduleClass, false)) { $classFound = true; } } } if ($classFound) { return new $moduleClass($defaults); } else { return new Ac_Module($moduleName, $defaults); } }
/** * Process a template and return its content * @param string $template Template filename * @param array $vars Variables passed to the template * @return string|false The template contents */ public static function process($template, array $vars = array()) { static::$level++; extract($vars, EXTR_OVERWRITE); ob_start(); try { include $template; $content = ob_get_contents(); ob_end_clean(); static::$level--; } catch (Exception $e) { Ac::log()->error($e->getMessage(), "Ac_View error " . $e->getCode(), $e->getFile(), $e->getLine()); $content = false; @ob_end_clean(); static::$level--; } return $content; }
public function __construct($data = null) { $this->table = static::tableName(); $this->primary = static::constant("PRIMARY_KEY"); if (is_numeric($data)) { $properties = Ac::db()->findBy($this->table, $this->primary, $data, null, 1, null, Ac_Storage_Database_PDO::FETCH_ASSOC_FIRST); if (!$this->exists($properties)) { Ac::log()->error(array($data, $this), "This {$this->table} record does not exist", __FILE__, __LINE__); $properties = array(); } } elseif ($data instanceof Ac_Model_Record_PDO) { $properties = $data->properties(); } elseif ($data instanceof stdClass) { $properties = (array) $data; } else { $properties = $data; //array ? } if (empty($properties)) { $properties = array(); } parent::__construct($properties); }
/** * Returns the Ac_Log instance or calls the Ac_Log::log() function if some parameter is passed * @param mixed $data * @param string $label * @param array $options * @return Ac_Log|void */ public static function log() { if (empty(self::$log)) { $log_class = self::config("log.class", "Ac_Log_File"); self::$log = new $log_class(); if (!self::$log instanceof Ac_Log) { self::exception("{$log_class} is not a valid Ac_Log instance"); } } if (func_num_args() > 0) { return call_user_func_array(array(self::$log, 'log'), func_get_args()); } return self::$log; }
/** * Clean all existing output buffers * @return string The resulting output buffer. */ public function cleanOb() { $ob = ""; while (ob_get_level() > 0) { $ob .= ob_get_clean(); } $ob = trim($ob); if (!empty($ob)) { Ac::log()->log($ob, "Output Buffer detected before send response", array("filename" => "output.log")); } return $ob; }