Ejemplo n.º 1
0
 /**
  * our init method, checks for an existing instance, 
  * this means we can refer to our instances from anywhere without globals 
  *
  * @param init_array 	array 	the array of input items
  *
  * @author Paul Whitehead
  * @return object
  */
 public static function init(array $init_array)
 {
     //make sure we have a form ID provided
     if (!isset($init_array['id'])) {
         throw new MeagrException('Form ID must be provided');
     }
     //check for an existing instance
     if (!isset(self::$instance[$init_array['id']])) {
         self::$instance[$init_array['id']] = new self($init_array);
         \Meagr\Debug::init('log')->add(array('message' => 'Create new form instance: ' . $init_array['id'], 'class' => __METHOD__, 'status' => 'success', 'backtrace' => Debug::backtrace()));
     }
     //return our instance, new or old
     return self::$instance[$init_array['id']];
 }
Ejemplo n.º 2
0
 /**
  * check the session exists
  *
  * @return bool
  */
 static function check()
 {
     //get our encrypted session data
     $check = Input::session('member');
     //if the check wasnt found, it returns '-5' (no idea why)
     //check for a positive int and return
     if ((int) $check > 0) {
         \Meagr\Debug::init('log')->add(array('message' => 'Auth check ok', 'class' => __METHOD__, 'status' => 'success', 'backtrace' => Debug::backtrace()));
         return (int) $check;
         //otherwise the user isnt logged in
     } else {
         \Meagr\Debug::init('log')->add(array('message' => 'Auth check failed', 'class' => __METHOD__, 'status' => 'error', 'backtrace' => Debug::backtrace()));
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * write the file from the options previously set
  *
  * @param filename string The filepath to save the image to, if different from the default
  * @param options array Additional options that will be merged with the defaults
  *
  * @return object
  */
 function save($filename = null, $options = array())
 {
     //are we using the cached image
     if ($this->use_cache) {
         return Cache::pathToUri($this->save_filename);
     }
     //merge our options with those passed to the function
     if (!empty($options)) {
         $this->options = $options + $this->options;
     }
     //check if we have a filename specified
     if (!is_null($filename)) {
         $this->save_filename = $filename;
     }
     //if we are creating a thumbnail, 'apply' and return
     if ($this->is_thumb) {
         $this->transform->apply($this->imagine->open($this->filename));
         return Cache::pathToUri($this->thumb_filename);
     }
     try {
         //save our image and return the location of the image
         $this->image->save($this->save_filename, $this->options);
     } catch (Exception $e) {
         \Meagr\Debug::init('log')->add(array('message' => $e->getMessage(), 'class' => __METHOD__, 'status' => 'error', 'backtrace' => Debug::backtrace()));
     }
     return Cache::pathToUri($this->save_filename);
 }
Ejemplo n.º 4
0
namespace Meagr;

class Autoloader
{
    public static function load($classname)
    {
        //we need debug, so include it
        if (!class_exists('Debug')) {
            require_once CORE_PATH . '/debug.php';
        }
        $classname = ltrim($classname, '\\');
        $filename = '';
        $namespace = '';
        if ($lastNsPos = strrpos($classname, '\\')) {
            $namespace = substr($classname, 0, $lastNsPos);
            $classname = substr($classname, $lastNsPos + 1);
            $filename = SITE_PATH . '/' . strtolower(str_replace('\\', DS, $namespace) . DS);
        }
        $filename .= strtolower($classname) . '.php';
        if (file_exists($filename) and !class_exists(basename($classname))) {
            Debug::init('file')->add(array('message' => str_replace(SITE_PATH, '', $filename), 'filesize' => filesize($filename), 'class' => __METHOD__, 'status' => 'success', 'backtrace' => Debug::backtrace()));
            require_once $filename;
            return;
        }
        Debug::init('file')->add(array('message' => 'Failed to load ' . $filename, 'class' => __METHOD__, 'status' => 'error', 'backtrace' => Debug::backtrace()));
        return $filename !== false;
    }
}
spl_autoload_register(__NAMESPACE__ . '\\Autoloader::load');
\Meagr\Debug::init('log')->add(array('message' => 'Register autoloader', 'class' => null, 'status' => 'success', 'backtrace' => Debug::backtrace()));
Ejemplo n.º 5
0
 /**
  * The default method which is run after each other method if no class __after() method is found 
  *
  * @return mixed
  */
 public static function __after()
 {
     \Meagr\Debug::init('log')->add(array('message' => 'Load Controller After', 'class' => __METHOD__, 'status' => 'success', 'backtrace' => Debug::backtrace()));
 }
Ejemplo n.º 6
0
 /**
  * set the body of content to be sent to the browser, 
  * buffer all output and store in $this->body
  *
  * @return object
  */
 function body()
 {
     //if we already have content
     if (!empty($this->body) or $this->cache_exists) {
         //return self and move on
         return $this;
     }
     //get our route object
     $route = $this->router->route;
     //properly capitalise our namespace
     $route = Router::namespaceRoutePattern($route);
     //get our arguments
     $args = $this->router->arguments ?: array();
     //get our class and method
     list($class, $method) = explode('::', $route->getMappedPattern());
     \Meagr\Debug::init('log')->add(array('message' => 'Route: ' . $class . ' ' . $method, 'class' => __METHOD__, 'status' => 'success', 'backtrace' => Debug::backtrace()));
     //start our buffering
     ob_start();
     //our before function
     call_user_func_array(array($class, '__before'), $args);
     //call our function and class
     call_user_func_array(array($class, $method), $args);
     //our after function
     call_user_func_array(array($class, '__after'), $args);
     //assign the buffer to our body variable
     $this->body = ob_get_contents();
     //finish buffering and clean the output
     ob_end_clean();
     //allow for chaining
     return $this;
 }