public function setEntity(Entity $entity) { $this->entity = $entity; if ($this->entity) { $this->setModel(app($entity->updateClass())); $this->model->underlyingQuery()->where('entity_id', $this->entity->id); } }
public function check(Entity $entity) { $link = $entity->absoluteLink(); $fetch = app(Fetch::class); $data = $fetch->pull($link); if (!$fetch->isOk()) { return null; } $data = $this->fixHTML($data); $class = ucfirst(class_basename($entity)); $parser = new Parser(); if (method_exists($parser, $method = "parse{$class}")) { $data = $parser->{$method}($data); if (method_exists($this, $method = 'check' . $class)) { return $this->{$method}($entity, $data); } else { return $data; } } throw new CheckError($entity, 'Doesn\'t know, how to parse supplied html'); }
public function __call($method, $args) { if (Str::startsWith($method, 'related')) { $property = lcfirst(substr($method, 7)); if (!isset($this->cached_related[$property])) { $type = null; $related = null; $id = 0; $cached = null; $entity = null; if (($type = StaticCache::map($property)) != null) { $entity = $this->entity(); if ($entity && array_search($property, get_object_vars($entity)) !== false) { $id = intval($entity->{"{$property}_id"}); if (!$id) { if ($entity->updateType() == $type) { $related = $cached = $entity; $id = $entity->id; } } if (!$related) { $related = $cached = StaticCache::cached($type, $id); } } } if (!$related) { if (method_exists($this, $property)) { $related = $this->{$property}($args); } } if (!$related) { if ($entity ?: ($entity = $this->entity())) { $related = $entity->{$property}; } } if ($related && !$cached) { $type = $type !== null ? $type : $related->getModel()->updateType(); StaticCache::map($property, $type); $id = $id ?: ($related ? $related->id : 0); StaticCache::cached($type, $id, $related); } $this->cached_related[$property] = $related; } return $this->cached_related[$property]; } return parent::__call($method, $args); }
protected function deleteEntity(Entity $entity) { return !$entity->trashed() && $entity->delete(); }
/** * Update the specified entity entry in storage. * * @param EntityRequest $request * @return Response */ public function _update(EntityRequest $request, Entity $entity) { if (($deleted = !!$request->deleted()) != !!$entity->trashed()) { if ($deleted) { $entity->delete(); } else { $entity->restore(); } } if ($this->m->updateEvenTrashed($entity, $request->data())) { return $this->innerRedirect('show', $entity)->withMessage('Updated'); } throw new Exception('Update failed'); }
protected static function boot() { parent::boot(); static::attachEventListeners(); }