示例#1
0
 public function __construct($kwargs)
 {
     if (!isset($kwargs['rel']) || isset($kwargs['rel']) && $kwargs['rel'] === null) {
         $kwargs['rel'] = ManyToManyRel::createObject(['fromField' => $this, 'to' => ArrayHelper::getValue($kwargs, 'to'), 'through' => ArrayHelper::getValue($kwargs, 'through'), 'throughFields' => ArrayHelper::getValue($kwargs, 'throughFields'), 'dbConstraint' => ArrayHelper::getValue($kwargs, 'dbConstraint', true)]);
     }
     $this->hasNullKwarg = ArrayHelper::hasKey($kwargs, 'null');
     parent::__construct($kwargs);
 }
示例#2
0
 public function __construct($kwargs)
 {
     $kwargs['unique'] = true;
     if (!isset($kwargs['rel']) || isset($kwargs['rel']) && $kwargs['rel'] == null) {
         $kwargs['rel'] = OneToOneRel::createObject(['fromField' => $this, 'to' => ArrayHelper::getValue($kwargs, 'to'), 'toField' => ArrayHelper::getValue($kwargs, 'toField'), 'parentLink' => ArrayHelper::getValue($kwargs, 'parentLink'), 'onDelete' => ArrayHelper::getValue($kwargs, 'onDelete', Delete::CASCADE)]);
     }
     parent::__construct($kwargs);
 }
示例#3
0
 public function toLevel($level)
 {
     $level = $level === null ? static::ERROR : $level;
     if (is_string($level)) {
         $level = ArrayHelper::getValue($this->levelsMap, strtolower($level));
     }
     return $level;
 }
示例#4
0
 public function __construct($kwargs)
 {
     if (!isset($kwargs['rel']) || isset($kwargs['rel']) && $kwargs['rel'] == null) {
         $kwargs['rel'] = ManyToOneRel::createObject(['fromField' => $this, 'to' => ArrayHelper::getValue($kwargs, 'to'), 'toField' => ArrayHelper::getValue($kwargs, 'toField'), 'parentLink' => ArrayHelper::getValue($kwargs, 'parentLink'), 'onDelete' => ArrayHelper::getValue($kwargs, 'onDelete', Delete::CASCADE)]);
     }
     $this->toField = ArrayHelper::getValue($kwargs, 'toField');
     $this->fromField = 'this';
     parent::__construct($kwargs);
 }
示例#5
0
 public function execute()
 {
     if (ArrayHelper::isEmpty(ArrayHelper::getValue($this->qb->getQueryParts(), 'select', null))) {
         $this->qb->select('*');
     }
     if (ArrayHelper::isEmpty(ArrayHelper::getValue($this->qb->getQueryParts(), 'from', null))) {
         $this->qb->from($this->model->meta->dbTable);
     }
     return $this->qb->execute()->fetchAll(PDO::FETCH_ASSOC);
 }
示例#6
0
 public function getRegisteredModel($name)
 {
     $model = ArrayHelper::getValue($this->allModels, $name);
     if ($model == null) {
         throw new LookupError(sprintf("Model '%s' not registered.", $name));
     }
     return $model;
 }
示例#7
0
 /**
  * Model constructor.
  *
  * @param array $kwargs the kwargs is an associative array of configurations passed to the model,
  *                      this configurations are all optional.
  *
  * The following are valid configurations:
  *  - db - the database connection to use
  *  - config - to
  */
 public function __construct($kwargs = [])
 {
     $this->constructorArgs = $kwargs;
     $this->init();
     if ($kwargs) {
         $fields = $this->meta->getConcreteFields();
     } else {
         $fields = $this->meta->getFields();
     }
     /** @var $field Field */
     foreach ($fields as $name => $field) {
         $val = null;
         $isRelated = false;
         if ($kwargs) {
             if ($field instanceof RelatedField) {
                 //todo
                 $isRelated = true;
             } else {
                 $val = ArrayHelper::getValue($kwargs, $field->getAttrName(), $field->getDefault());
             }
         } else {
             $val = $field->getDefault();
         }
         if ($isRelated) {
             //todo
         } else {
             $this->{$field->getAttrName()} = $val;
         }
     }
 }
示例#8
0
 public function __construct($config = [])
 {
     // max_length=254 to be compliant with RFCs 3696 and 5321
     $config['maxLength'] = ArrayHelper::getValue($config, 'maxLength', 254);
     parent::__construct($config);
 }
示例#9
0
 /**
  * @dataProvider providerGetArraysValue
  *
  * @param $array
  * @param $key
  * @param $expectedValue
  * @param $default
  *
  * @since 1.1.0
  *
  * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**>
  */
 public function testGetValue($array, $key, $expectedValue, $default)
 {
     $value = ArrayHelper::getValue($array, $key, $default);
     $this->assertEquals($expectedValue, $value);
 }
示例#10
0
 public function getFieldByName($name)
 {
     if (ArrayHelper::hasKey($this->fields, $name)) {
         return ArrayHelper::getValue($this->fields, $name);
     }
     throw new ValueError(sprintf('No field called [ %s ] on model [ %s ]', $name, $this->name));
 }