protected function doDelete(\Owl\DataMapper\Data $data, \Owl\Service $service = null, $collection = null) { $service = $service ?: $this->getService(); $collection = $collection ?: $this->getCollection(); list($where, $params) = $this->whereID($service, $data->id(true)); return $service->delete($collection, $where, $params); }
protected function doDelete(\Owl\DataMapper\Data $data, Service $service = null, $collection = null) { $service = $service ?: $this->getService(); $collection = $collection ?: $this->getCollection(); return $service->delete($collection, $data->id()); }
/** * delete cache before refresh data * * @param \Owl\DataMapper\Data $data * @return \Owl\DataMapper\Data */ public function refresh(\Owl\DataMapper\Data $data) { $this->deleteCache($data->id()); return parent::refresh($data); }
/** * 删除Data * * @param Data $data * @return boolean */ public function destroy(Data $data) { if ($this->isReadonly()) { throw new \RuntimeException($this->class . ' is readonly'); } if ($data->isFresh()) { return true; } $this->__before('delete', $data); if (!$this->doDelete($data)) { throw new \Exception($this->class . ' destroy failed'); } $this->__after('delete', $data); Registry::getInstance()->remove($this->class, $data->id()); return true; }
/** * Data属性值有效性检查 * * @param Data $data * @return boolean * @throws \UnexpectedValueException 不允许为空的属性没有被赋值 */ protected function validateData(Data $data) { $is_fresh = $data->isFresh(); $attributes = $this->getAttributes(); if ($is_fresh) { $record = $this->unpack($data); $keys = array_keys($attributes); } else { $record = $this->unpack($data, ['dirty' => true]); $keys = array_keys($record); } foreach ($keys as $key) { $attribute = $attributes[$key]; do { if ($attribute['allow_null']) { break; } if ($attribute['auto_generate'] && $is_fresh) { break; } if (isset($record[$key])) { break; } throw new \UnexpectedValueException($this->class . ' property ' . $key . ' not allow null'); } while (false); } return true; }