/** * Ajout un nouvelle evenement * * @param string $eventName * @param Callable|string $bindFunction * @param string $eventType */ private static function addEvent($eventName, $bindFunction, $eventType) { $ref =& static::${$eventType}; if ($ref === null) { $ref = new Collection(); } if (!$ref->has($eventName)) { $ref->add($eventName, $bindFunction); } else { $ref->add($eventName, $bindFunction); } }
/** * addField * * @param string $method * @param string $field * @param string $data * @throws ModelException * @return Fields */ private function addField($method, $field, $data) { $method = strtolower($method); if (!$this->fields->has($method)) { $this->fields->add($method, new Collection()); } if (!is_array($this->dataBind)) { $this->dataBind = []; } $bind = ['field' => $field, 'type' => $method, 'size' => isset($data['size']) ? $data['size'] : 0, 'auto' => false]; if ($this->getAutoincrement() !== false) { if ($this->getAutoincrement()->field == $field) { $bind['auto'] = true; } } if ($method == 'enum') { $bind['default'] = $data['default'] != null ? $data['default'] : $data['value'][0]; } $this->dataBind[$field] = $bind; if ($this->fields->get($method)->has($field)) { return $this; } // default index are at false $data['primary'] = false; $data['unique'] = false; $data['indexe'] = false; $this->fields->get($method)->add($field, $data); $this->lastField = (object) ['method' => $method, 'field' => $field]; return $this; }
/** * retourne une instance de collection * * @param array $data [optional] * @return \Bow\Support\Collection */ function collect(array $data = []) { $col = new Collection(); foreach ($data as $key => $param) { $col->add($key, $param); } return $col; }
/** * toCollection, retourne les données de la DB sous en instance de Collection * * @return Collection */ public function toCollection() { $data = $this->get(); $coll = new Collection(); foreach ($data as $key => $value) { $coll->add($key, $value); } return $coll; }