public static function request() { $class = new static(); !Input::has('updateBillStatus') ?: $class->setId(Input::get('updateBillStatus'))->status(Input::get('billUpdate.' . Input::get('updateBillStatus') . '.status_id'))->comment(Input::get('billUpdate.' . Input::get('updateBillStatus'))); !Input::has('updateBillSend') ?: $class->setId(head(Input::get('updateBillSend', [])))->markAsSent(); !Input::has('updateBillPaid') ?: $class->setId(head(Input::get('updateBillPaid', [])))->markAsPaid(key(Input::get('updateBillPaid', []))); !Input::has('updateBillCancel') ?: $class->setId(head(Input::get('updateBillCancel', [])))->markAsCancel(key(Input::get('updateBillCancel', []))); !Input::has('deleteBill') ?: $class->setId(Input::get('deleteBill'))->delete(); if (Input::has('addNewBill') && Input::has('billCreate.fill.orders_id')) { $class->add(Input::get('billCreate.fill'), Input::get('billCreate.template')); } }
/** * @param $data * * @return static */ public static function createExisting($data) { $newRequest = new static($data); $newRequest->setId($data['id']); $newRequest->setExists(true); return $newRequest; }
public static function create($id, $title) { $post = new static(); $post->setId($id); $post->setTitle($title); return $post; }
/** * @param string $id * @param string[] $options * * @return static */ public static function make($id, array $options = []) { $tag = new static(); $tag->setId($id); $tag->addOptions($options); return $tag; }
/** * Create unique service name from string. * * @param string $uniqueServiceName * * @return self */ public static function fromString($uniqueServiceName) { $instance = new static(); $uniqueServiceName = strtolower(trim($uniqueServiceName)); $parts = explode('::', $uniqueServiceName, 2); if (!substr($parts[0], 0, 4) === 'uuid') { throw new \InvalidArgumentException('Invalid string.'); } $instance->setId(Uuid::fromString(substr($parts[0], 5))); if (count($parts) < 2) { return $instance; } if ($parts[1] === 'upnp:rootdevice') { return $instance->setRootDevice(true); } $parts = explode(':', $parts[1], 5); if (5 !== count($parts) || 'urn' !== array_shift($parts)) { throw new \InvalidArgumentException('Invalid string.'); } $instance->setDomainName(array_shift($parts)); $name = array_shift($parts); if ('device' === $name) { return $instance->setDevice(true)->setType(array_shift($parts))->setVersion((int) array_shift($parts)); } if ('service' === $name) { return $instance->setService(true)->setType(array_shift($parts))->setVersion((int) array_shift($parts)); } throw new \InvalidArgumentException('Invalid string.'); }
public static function create($id, $firstName = null, $lastName = null) { $user = new static(); $user->setId($id); $user->setFirstName($firstName); $user->setLastName($lastName); return $user; }
/** * Unserialize an alert type from an array created using toArray(). * * @param array $serialized The serialized alert type. * * @return MybbStuff_MyAlerts_Entity_AlertType The unserialized alert type. */ public static function unserialize(array $serialized) { $serialized = array_merge(array('id' => 0, 'code' => '', 'enabled' => false, 'can_be_user_disabled' => false), $serialized); $alertType = new static(); $alertType->setEnabled($serialized['enabled']); $alertType->setId($serialized['id']); $alertType->setCode($serialized['code']); $alertType->setCanBeUserDisabled($serialized['can_be_user_disabled']); return $alertType; }
public static function createFromObject(\stdClass $data) : Photo { $photo = new static(); $photo->setId((int) $data->id); $photo->setSpecificPath($data->specificPath); $photo->setRelativePath($data->relativePath); $photo->setName($data->name); $photo->addTag(implode('/', [$data->tag1, $data->tag2, $data->tag3])); return $photo; }
/** * @param File $file * @return static */ public static function fromFile(File $file) { $note = new static(); $note->setId($file->getId()); $note->setContent($file->getContent()); $note->setModified($file->getMTime()); $note->setTitle(pathinfo($file->getName(), PATHINFO_FILENAME)); // remove extension $note->resetUpdatedFields(); return $note; }
public static function fromString($headerLine) { list($name, $value) = Header\GenericHeader::splitHeaderLine($headerLine); $value = Header\HeaderWrap::mimeDecodeValue($value); if (strtolower($name) !== 'x-queue-item-id') { throw new Header\Exception\InvalidArgumentException('Invalid header line for Message-ID string'); } $header = new static(); $header->setId($value); return $header; }
public static function fromString($headerLine) { list($name, $value) = GenericHeader::splitHeaderLine($headerLine); // check to ensure proper header type for this factory if (strtolower($name) !== 'message-id') { throw new Exception\InvalidArgumentException('Invalid header line for Message-ID string'); } $header = new static(); $header->setId($value); return $header; }
/** * @param File $file * @return static */ public static function fromFile(File $file) { $note = new static(); $note->setId($file->getId()); $note->setContent($file->getContent()); $note->setModified($file->getMTime()); $note->setTitle(substr($file->getName(), 0, -4)); // remove trailing .txt $note->resetUpdatedFields(); return $note; }
/** * @param $content * @param string $title * @param string $id * * @return static */ public static function make($content, $title = null, $id = null) { $tag = new static(); $tag->setContents($content); if ($title) { $tag->setTitle($title); } if ($id) { $tag->setId($id); } return $tag; }
/** * @param HttpRequest $httpRequest * @param Serializer $serializer * @param array $context * * @return Request */ public static function factory(HttpRequest $httpRequest, Serializer $serializer, array $context = []) { $attributes = $httpRequest->attributes; $content = $httpRequest->getContent(); $method = $attributes->get('method'); $params = $serializer->deserialize($content, ParamsDenormalizer::TYPE, 'rest', $context); $id = $attributes->get('id'); $request = new static(); $request->setMethod($method); $request->setParams($params); $request->setId($id); }
public static function fromEventMessage(EventMessage $message) { $event = new static(); $event->setId($message->getId()); $event->setEvent($message->getEvent()); $event->setEventType(get_class($message->getEvent())); $event->setEntityType($message->getEntity()->getType()); $event->setEntityId($message->getEntity()->getPlainId()); $event->setVersion($message->getEntity()->getVersion()); $event->setMetadata($message->getEnvelope()->getMetadata()); $event->setTime($message->getEnvelope()->getTime()); return $event; }
/** * Configure the request based on a JSON * * @param string $json * @return boolean */ public static function fromJSON($json) { $request = new static(); print_r($json); $data = json_decode($json, true); print_r($data); if (!$data) { throw new UnexpectedValueException(sprintf('Unexpected message, invalid JSON from nginx: "%s"', $json)); } if (isset($data['id'])) { $request->setId($data['id']); } if (isset($data['method'])) { $request->setMethod($data['method']); } if (isset($data['params'])) { $request->setPrams($data['params']); } return $request; }
public function saveAsNew($newKey = null) { $new = new static(); $new->hydrate(call_user_func('get_object_vars', $this)); $new->setId($newKey); $new->save(); return $new; }
/** * Create new item in database. * * @param $fields * * @throws Exception * * @return static */ public static function create($fields) { $model = new static(null, $fields); if ($model->onBeforeSave() === false || $model->onBeforeCreate() === false) { return false; } $bxObject = static::instantiateObject(); $id = $bxObject->add($fields); $model->setId($id); $result = $id ? true : false; $model->onAfterCreate($result); $model->onAfterSave($result); if (!$result) { throw new Exception($bxObject->LAST_ERROR); } return $model; }
/** * Create table * @return $this */ public static function table() { $table = new static(); //set random name $table->setId(str_random(8)); return $table; }
/** * @param array $array * @return Metadata */ public static function __set_state(array $array) { $metadata = new static(); $metadata->setId($array['id']); $metadata->setPrefix($array['prefix']); $metadata->setIndexes($array['indexes']); $metadata->setSortedIndexes($array['sortedIndexes']); $metadata->setPropertyMappings($array['propertyMappings']); return $metadata; }
/** * @param $newKey * * @return static */ public function saveAsNew($newKey = null) { $new = new static(); // hydrate new mapper with existing values $new->hydrate(call_user_func('get_object_vars', $this)); // hydrate new mapper with specified keys $new->setId($newKey); // unset autoTimestamps if (static::useAutoTimestamp()) { $new->updatedAt = null; $new->createdAt = null; } $new->save(); return $new; }
/** * Return a worker from it's ID * * @param string $id Worker id * @param Logger $logger Logger for the worker to use * @return Worker */ public static function fromId($id, Logger $logger = null) { if (!$id or !count($packet = Redis::instance()->hgetall(self::redisKey($id)))) { return false; } $worker = new static(explode(',', $packet['queues']), $packet['blocking']); $worker->setId($id); $worker->setPid($packet['pid']); $worker->setInterval($packet['interval']); $worker->setTimeout($packet['timeout']); $worker->setMemoryLimit($packet['memory_limit']); $worker->setHost(new Host($packet['hostname'])); $worker->setLogger($logger); return $worker; }
public static function fromSelector($selector, Node $parent = null, array $children = null) { $selector = $selector instanceof Selector ? $selector : Selector::fromString($selector); $tag = $selector->getTag(); $el = new static($tag ? $tag : 'div', $selector->getAttributes(), $parent, $children); if ($id = $selector->getId()) { $el->setId($id); } if ($classes = $selector->getClasses()) { foreach ($classes as $class) { $el->appendClass($class); } } return $el; }
/** * Deletes the Order with the given ID * * @param integer $order_id The Order ID * @param boolean $stockUpdate True to update stock of the product * * @return boolean True on success, false otherwise */ static function deleteById($order_id, $stockUpdate = false) { global $objDatabase, $_ARRAYLANG; $order_id = contrexx_input2int($order_id); if (empty($order_id)) { return false; } // Deactivate accounts autocreated for downloads $objOrder = self::getById($order_id); if ($objOrder && ($objCustomer = Customer::getById($objOrder->customer_id()))) { $customer_email = Orders::usernamePrefix . "_{$order_id}_%-" . $objCustomer->email(); $objUser = \FWUser::getFWUserObject()->objUser->getUsers(array('email' => $customer_email)); if ($objUser) { while (!$objUser->EOF) { $objUser->setActiveStatus(false); if (!$objUser->store()) { return false; } $objUser->next(); } } } $objUser = \FWUser::getFWUserObject()->objUser; $query = ' UPDATE `' . DBPREFIX . 'module_shop' . MODULE_INDEX . '_orders` SET `status` = ' . Order::STATUS_DELETED . ', `modified_by` = "' . contrexx_raw2db($objUser->getUsername()) . '", `modified_on` = "' . date('Y-m-d H:i:s') . '" WHERE `id`=' . $order_id; if (!$objDatabase->Execute($query)) { return \Message::error($_ARRAYLANG['TXT_SHOP_ERROR_DELETING_ORDER']); } if ($stockUpdate) { $order = new static(); $order->setId($order_id); $order->updateStock(); } return true; }
/** * {@inheritDoc} */ public static function decode($payload) { $decoded = json_decode($payload, true); // @todo check for json_decode error, if error throw an exception. if (null === $decoded) { throw new InvalidArgumentException('Invalid JSON'); } $job = new static(); $job->setJobClass($decoded['class']); $job->setArguments($decoded['args'][0]); $job->setId($decoded['id']); return $job; }
/** * @param $id * * @return static */ public static function loadOrNew($id) { try { $mapper = static::load($id); } catch (\Exception $e) { $mapper = new static(); $mapper->setId($id); } return $mapper; }