Example #1
0
 /**
  * Gets a new instance of the Asset class.
  *
  * @param   string  instance name
  * @param   array  $config  default config overrides
  * @return  Asset_Instance
  */
 public static function forge($name = 'default', array $config = array())
 {
     if ($exists = static::instance($name)) {
         \Error::notice('Asset with this name exists already, cannot be overwritten.');
         return $exists;
     }
     static::$_instances[$name] = new \Asset_Instance(array_merge(static::$default_config, \Config::get('asset'), $config));
     if ($name == 'default') {
         static::$_instance = static::$_instances[$name];
     }
     return static::$_instances[$name];
 }
Example #2
0
 /**
  * Gets a new instance of the Messages class.
  *
  * @param   string  instance name
  * @return  Messages
  */
 public static function forge($name = 'messages')
 {
     if ($exists = static::instance($name)) {
         \Error::notice('Messages instance with this name exists already, cannot be overwritten.');
         return $exists;
     }
     static::$_instances[$name] = new \Messages_Instance($name);
     if ($name == 'messages') {
         static::$_instance = static::$_instances[$name];
     }
     return static::$_instances[$name];
 }
Example #3
0
 /**
  * Forge
  * 
  * @param  string $service
  * @param  string $name
  * @param  array $config
  * @return Gdata
  */
 public static function forge($service = null, $name = 'default', array $config = array())
 {
     if ($exists = static::instance($name)) {
         \Error::notice('Gdata with this name exists already, cannot be overwritten.');
         return $exists;
     }
     static::$_instances[$name] = new static($service, $config);
     if ($name == 'default') {
         static::$_instance = static::$_instances[$name];
     }
     return static::$_instances[$name];
 }
 /**
  * forge a new pagination instance
  *
  * @return	\Pagination	a new pagination instance
  */
 public static function forge($name = 'default', $config = array())
 {
     \Config::load('auto_response_emails', true);
     if ($exists = static::instance($name)) {
         \Error::notice('Autoresponder with this name exists already, cannot be overwritten.');
         return $exists;
     }
     static::$_instances[$name] = new static($config);
     if ($name == 'default') {
         static::$_instance = static::$_instances[$name];
     }
     return static::$_instances[$name];
 }
 public function handle()
 {
     // handle the error based on the config and the environment we're in
     if (static::$count <= Config::get('errors.throttle', 10)) {
         logger(\Fuel::L_ERROR, $this->code . ' - ' . $this->message . ' in ' . $this->file . ' on line ' . $this->line);
         if (\Fuel::$env != \Fuel::PRODUCTION and ($this->code & error_reporting()) == $this->code) {
             static::$count++;
             \Error::show_php_error(new \ErrorException($this->message, $this->code, 0, $this->file, $this->line));
         }
     } elseif (\Fuel::$env != \Fuel::PRODUCTION and static::$count == \Config::get('errors.throttle', 10) + 1 and ($this->severity & error_reporting()) == $this->severity) {
         static::$count++;
         \Error::notice('Error throttling threshold was reached, no more full error reports are shown.', true);
     }
 }
Example #6
0
    /**
     * Factory for Fieldset_Field objects
     *
     * @param   string
     * @param   string
     * @param   array
     * @param   array
     * @return  Fieldset_Field
     */
    public function add($name, $label = '', array $attributes = array(), array $rules = array()) {
        if ($name instanceof Fieldset_Field) {
            if ($name->name == '' or $this->field($name->name) !== false) {
                throw new \RuntimeException('Fieldname empty or already exists in this Fieldset: "' . $name->name . '".');
            }

            $name->set_fieldset($this);
            $this->fields[$name->name] = $name;
            return $name;
        } elseif ($name instanceof Fieldset) {
            if (empty($name->name) or $this->field($name->name) !== false) {
                throw new \RuntimeException('Fieldset name empty or already exists in this Fieldset: "' . $name->name . '".');
            }

            $name->set_parent($this);
            $this->fields[$name->name] = $name;
            return $name;
        }

        if (empty($name) || (is_array($name) and empty($name['name']))) {
            throw new \InvalidArgumentException('Cannot create field without name.');
        }

        // Allow passing the whole config in an array, will overwrite other values if that's the case
        if (is_array($name)) {
            $attributes = $name;
            $label      = isset($name['label']) ? $name['label'] : '';
            $rules      = isset($name['rules']) ? $name['rules'] : array();
            $name = $name['name'];
        }

        // Check if it exists already, if so: return and give notice
        if (($field = $this->field($name))) {
            \Error::notice('Field with this name exists already in this fieldset: "' . $name . '".');
            return $field;
        }

        $field = new \ViewForm\Fieldset_Field($name, $label, $attributes, $rules, $this);
        $this->fields[$name] = $field;


        return $field;
    }
Example #7
0
File: field.php Project: hymns/fuel
 /**
  * Add a validation rule
  * any further arguements after the callback will be used as arguements for the callback
  *
  * @param	string|Callback	either a validation rule or full callback
  * @return	Fieldset_Field	this, to allow chaining
  */
 public function add_rule($callback)
 {
     $args = array_slice(func_get_args(), 1);
     // Rules are validated and only accepted when given as an array consisting of
     // array(callback, params) or just callbacks in an array.
     $callable_rule = false;
     if (is_string($callback)) {
         $callback_method = '_validation_' . $callback;
         $callables = $this->fieldset->validation()->callables();
         foreach ($callables as $callback_class) {
             if (method_exists($callback_class, $callback_method)) {
                 $callable_rule = true;
                 $this->rules[] = array(array($callback_class, $callback_method), $args);
             }
         }
     }
     // when no callable function was found, try regular callbacks
     if (!$callable_rule) {
         if (is_callable($callback)) {
             $this->rules[] = array($callback, $args);
         } else {
             $string = !is_array($callback) ? $callback : (is_object(@$callback[0]) ? get_class(@$callback[0]) . '->' . @$callback[1] : @$callback[0] . '::' . @$callback[1]);
             Error::notice('Invalid rule "' . $string . '" passed to Validation, not used.');
         }
     }
     // Set required setting for forms when rule was applied
     if ($callback === 'required') {
         $this->set_attribute('required', true);
     }
     return $this;
 }
Example #8
0
 /**
  * Insert value(s) into an array after a specific value (first found in array)
  *
  * @param   array        the original array (by reference)
  * @param   array|mixed  the value(s) to insert, if you want to insert an array it needs to be in an array itself
  * @param   string|int   the value after which to insert
  * @return  bool         false when value isn't found in the array, otherwise true
  */
 public static function insert_after_value(array &$original, $value, $search)
 {
     $key = array_search($search, $original);
     if ($key === false) {
         \Error::notice('Unknown value after which to insert the new value into the array.');
         return false;
     }
     return static::insert_after_key($original, $value, $key);
 }
Example #9
0
 /**
  * Takes the rule input and formats it into a name & callback
  *
  * @param   string|array  short rule to be called on Validation callables array or full callback
  * @return  array|bool    rule array or false when it fails to find something callable
  */
 protected function _find_rule($callback)
 {
     // Rules are validated and only accepted when given as an array consisting of
     // array(callback, params) or just callbacks in an array.
     if (is_string($callback)) {
         $callback_method = '_validation_' . $callback;
         foreach ($this->callables as $callback_class) {
             if (method_exists($callback_class, $callback_method)) {
                 return array($callback => array($callback_class, $callback_method));
             }
         }
     }
     // when no callable function was found, try regular callbacks
     if (is_callable($callback)) {
         if ($callback instanceof \Closure) {
             $callback_name = 'closure';
         } elseif (is_array($callback)) {
             $callback_name = preg_replace('#^([a-z_]*\\\\)*#i', '', is_object($callback[0]) ? get_class($callback[0]) : $callback[0]) . ':' . $callback[1];
         } else {
             $callback_name = preg_replace('#^([a-z_]*\\\\)*#i', '', str_replace('::', ':', $callback));
         }
         return array($callback_name => $callback);
     } elseif (is_array($callback) and is_callable(reset($callback))) {
         return $callback;
     } else {
         $string = !is_array($callback) ? $callback : (is_object(@$callback[0]) ? get_class(@$callback[0]) . '->' . @$callback[1] : @$callback[0] . '::' . @$callback[1]);
         \Error::notice('Invalid rule "' . $string . '" passed to Validation, not used.');
         return false;
     }
 }
Example #10
0
 /**
  * Unregister a driver type
  *
  * @param	string	name of the driver type
  * @return	bool
  */
 public static function unregister_driver_type($type)
 {
     if (in_array('login', 'group', 'acl')) {
         \Error::notice('Cannot remove driver type, included drivers login, group and acl cannot be removed.');
         return false;
     }
     unset(static::$_drivers[$type]);
     return true;
 }
Example #11
0
File: date.php Project: nasumi/fuel
	/**
	 * Returns the number of days in the requested month
	 * (Based on CodeIgniter function)
	 *
	 * @param	int	month as a number (1-12)
	 * @param	int	the year, leave empty for current
	 * @return	int	the number of days in the month
	 */
	public static function days_in_month($month, $year = null)
	{
		$year	= ! empty($year) ? (int) $year : (int) date('Y');
		$month	= (int) $month;

		if ($month < 1 || $month > 12)
		{
			\Error::notice('Invalid input for month given.');
			return false;
		}
		elseif ($month == 2)
		{
			if ($year % 400 == 0 || ($year % 4 == 0 && $year % 100 != 0))
			{
				return 29;
			}
		}

		$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		return $days_in_month[$month-1];
	}
Example #12
0
File: arr.php Project: wushian/MDD
 /**
  * Insert value(s) into an array before a specific value (first found in array)
  *
  * @param   array        the original array (by reference)
  * @param   array|mixed  the value(s) to insert, if you want to insert an array it needs to be in an array itself
  * @param   string|int   the value after which to insert
  * @param   bool         wether the input is an associative array
  * @return  bool         false when value isn't found in the array, otherwise true
  */
 public static function insert_before_value(array &$original, $value, $search, $is_assoc = false)
 {
     $key = array_search($search, $original);
     if ($key === false) {
         \Error::notice('Unknown value before which to insert the new value into the array.');
         return false;
     }
     return static::insert_before_key($original, $value, $key, $is_assoc);
 }
Example #13
0
 /**
  * Factory for Fieldset_Field objects
  *
  * @param	string
  * @param	string
  * @param	array
  * @param	array
  * @return	Fieldset_Field
  */
 public function add($name, $label = '', array $attributes = array(), array $rules = array())
 {
     if (empty($name) || (is_array($name) and empty($name['name']))) {
         throw new \InvalidArgumentException('Cannot create field without name.');
     }
     // Allow passing the whole config in an array, will overwrite other values if that's the case
     if (is_array($name)) {
         $attributes = $name;
         $label = isset($name['label']) ? $name['label'] : '';
         $rules = isset($name['rules']) ? $name['rules'] : array();
         $name = $name['name'];
     }
     // Check if it exists already, if so: return and give notice
     if ($field = static::field($name)) {
         \Error::notice('Field with this name exists already, cannot be overwritten through add().');
         return $field;
     }
     $field = new \Fieldset_Field($name, $label, $attributes, $rules, $this);
     $this->fields[$name] = $field;
     return $field;
 }
Example #14
0
 /**
  * Sets a variable on the template without sanitizing
  *
  * @param	string
  * @param	mixed
  */
 public function set_raw($name, $val)
 {
     \Error::notice('The ViewModel::set_safe() method is depricated and will be removed at 1.0. Use set(name, var, false) instead.');
     $this->_template->set($name, $val, false);
     return $this;
 }