Example #1
0
 /**
  * Настраиваем
  * @param array $config конфиг
  */
 protected function _config($config)
 {
     $path = APP . 'Config' . DS . str_replace('\\', '/', __NAMESPACE__);
     @(include $path . DS . 'config.php');
     $field = str_replace('\\', '.', __NAMESPACE__);
     // подключаем конфиг
     $configured = \Configure::read($field);
     if (!empty($configured)) {
         $config = empty($config) ? $configured : array_merge($configured, $config);
     }
     static::$_defaults = Hash::merge(self::$_defaults, static::$_defaults);
     $this->_config = !empty($config) ? Hash::merge(static::$_defaults, $config) : static::$_defaults;
 }
Example #2
0
 public function __construct($namespace = null, $config = [])
 {
     static::$_defaults = Hash::merge(self::$_defaults, static::$_defaults);
     if ($namespace) {
         $config = $this->_config(__NAMESPACE__, $config);
     } else {
         $namespace = __NAMESPACE__;
     }
     parent::__construct($namespace, $config);
     // соединение
     if ($this->_config['connect']) {
         $this->_connect();
     }
 }
Example #3
0
 /**
  * Prepare the model
  *
  * @param string 	$settings	The model properties
  * @param string 	$class 		The class name.
  * @return array
  */
 protected static function _prepare($setting, $class)
 {
     $settings['defaults'] = array();
     $settings['types'] = array();
     // get the default's, fix them and clean them.
     if (property_exists($class, '_defaults')) {
         foreach (static::$_defaults as $key => $value) {
             if (is_numeric($key)) {
                 $settings['defaults'][$value] = null;
             } else {
                 if (is_array($value) && !empty($value)) {
                     $settings['types'][$key] = array_shift($value);
                     $settings['defaults'][$key] = array_shift($value);
                 } else {
                     $settings['defaults'][$key] = $value;
                 }
             }
         }
         static::$_defaults = $settings['defaults'];
     }
     // add also the hidden fields properties
     if (property_exists($class, '_hidden')) {
         $settings['hidden'] = array_flip(static::$_hidden);
     } else {
         $settings['hidden'] = array();
     }
     // and of course the visible ones
     if (property_exists($class, '_visible')) {
         $settings['visible'] = array_flip(static::$_visible);
     } else {
         $settings['visible'] = array();
     }
     // check if the key property isset if not we generate one using
     // the current class name
     if (property_exists($class, '_name')) {
         $settings['name'] = static::$_name;
     } else {
         $settings['name'] = strtolower(str_replace(array("\\", '_'), '/', get_called_class()));
         // if it starts with model remove it
         if (substr($settings['name'], $length = strlen('model/')) == 'model/') {
             $settings['name'] = substr($settings['name'], $length);
         }
     }
     return $settings;
 }
Example #4
0
 public function __construct($namespace = null, $connect = false, $config = array())
 {
     $defaults = static::$_defaults;
     static::$_defaults = \Hash::merge(self::$_defaults, static::$_defaults);
     if ($namespace) {
         $config = $this->_config(__NAMESPACE__, $config);
     } else {
         $namespace = __NAMESPACE__;
     }
     parent::__construct($namespace, $config);
     static::$_defaults = $defaults;
     if ($connect) {
         $this->connect();
     }
     if (empty($this->_table) && !empty($this->_config['table'])) {
         $this->_table = $this->_config['table'];
     }
     // просто соединяемся с БД
     return true;
 }
Example #5
0
 public function __construct($namespace = null, $config = [])
 {
     parent::__construct();
     $namespace = $namespace ?: __NAMESPACE__;
     $defaults = static::$_defaults;
     static::$_defaults = Hash::merge(self::$_defaults, static::$_defaults);
     $this->_config = $this->_config($namespace, $config);
     static::$_defaults = $defaults;
     // настраиваем тестовое окружение
     $connection = defined('TESTING_IS_GOING_ON') && TESTING_IS_GOING_ON && !empty($this->_config['test']) ? $this->_config['test'] : $this->_config['server'];
     // коннектимся
     $this->connect($connection['host'], $connection['port']);
     // если есть пароль то логинимся
     if (!empty($connection['password'])) {
         if (!$this->auth($connection['password'])) {
             throw new Exception('Wrong password');
         }
     }
     if (!empty($connection['database'])) {
         $this->select($connection['database']);
     }
 }
Example #6
0
 public function __construct($config = [])
 {
     static::$_defaults = Hash::merge(self::$_defaults, static::$_defaults);
     $config = $this->_config(__NAMESPACE__, $config);
     parent::__construct(null, $config);
 }
Example #7
0
 /**
  * Init, config loading.
  */
 public static function _init()
 {
     \Config::load('currency', true);
     static::$_defaults = \Config::get('currency');
 }
Example #8
0
 /**
  * Init
  */
 public static function _init()
 {
     \Config::load('supplier', true);
     static::$_defaults = \Config::get('supplier.defaults', array());
 }
Example #9
0
	/**
	 * Init, config loading.
	 */
	public static function _init()
	{
		\Config::load('sms', true);
		static::$_defaults = \Config::get('sms.defaults');
	}
Example #10
0
 /**
  * Initializes the default configuration (or return it if no $defaults array). Can be
  * called statically from your bootstrap, for example.
  *
  * @param  array $defaults  (optionnal) Default configuration
  * @return array                        Default configuration
  */
 public static function defaults(array $defaults = null)
 {
     if (!isset($defaults)) {
         return static::$_defaults;
     }
     static::$_defaults = $defaults + static::$_defaults;
 }