/** * 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']]; }
/** * 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); }