/** * Envia a mensagem para uma conexão * * @param Message $message * @param ConnectionInterface $connection */ public static function send($message, $connection) { if (!is_string($message)) { $message = json_encode($message); } $connection->send($message); }
/** * {@inheritdoc} */ public function persist(ConnectionInterface $connection, Container $container) { $entities = $container->state(Container::STATE_TO_BE_REMOVED)->foreach(function (IdentityInterface $identity, $object) { $this->dispatcher->dispatch(Events::PRE_REMOVE, new RemoveEvent($identity, $object)); }); if ($entities->size() === 0) { return; } $connection->execute($this->queryFor($entities)); $entities->foreach(function (IdentityInterface $identity, $object) use($container) { $container->push($identity, $object, Container::STATE_REMOVED); $this->changeset->use($identity, new Collection([])); //in case the identity is reused later on $this->dispatcher->dispatch(Events::POST_REMOVE, new RemoveEvent($identity, $object)); }); }
/** * {@inheritdoc} */ public function persist(ConnectionInterface $connection, Container $container) { $entities = $container->state(Container::STATE_NEW); if ($entities->size() === 0) { return; } $entities->foreach(function (IdentityInterface $identity, $entity) { $this->dispatcher->dispatch(Events::PRE_PERSIST, new PersistEvent($identity, $entity)); }); $connection->execute($this->queryFor($entities)); $entities->foreach(function (IdentityInterface $identity, $entity) use($container) { $container->push($identity, $entity, Container::STATE_MANAGED); $this->changeset->use($identity, $this->extractor->extract($entity)); $this->dispatcher->dispatch(Events::POST_PERSIST, new PersistEvent($identity, $entity)); }); }
/** * Get a list of the subscriptions registered to all of your project's * topics. * * Example: * ``` * $subscriptions = $pubsub->subscriptions(); * foreach ($subscriptions as $subscription) { * $info = $subscription->info(); * echo $info['name']; // `projects/my-awesome-project/subscriptions/<subscription-name>` * } * ``` * * @see https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/list List Subscriptions * * @param array $options [optional] { * Configuration Options * * @type int $pageSize Maximum number of results to return per * request. * } * @return \Generator<Google\Cloud\PubSub\Subscription> */ public function subscriptions(array $options = []) { $options['pageToken'] = null; do { $response = $this->connection->listSubscriptions($options + ['project' => $this->formatName('project', $this->projectId)]); foreach ($response['subscriptions'] as $subscription) { (yield $this->subscriptionFactory($subscription['name'], $subscription['topic'], $subscription)); } // If there's a page token, we'll request the next page. $options['pageToken'] = isset($response['nextPageToken']) ? $response['nextPageToken'] : null; } while ($options['pageToken']); }
/** * {@inheritdoc} */ public function persist(ConnectionInterface $connection, Container $container) { $changesets = new Map(IdentityInterface::class, CollectionInterface::class); $entities = $container->state(Container::STATE_MANAGED)->foreach(function (IdentityInterface $identity, $entity) use(&$changesets) { $data = $this->extractor->extract($entity); $changeset = $this->changeset->compute($identity, $data); if ($changeset->count() > 0) { $changesets = $changesets->put($identity, $changeset); } }); if ($changesets->size() === 0) { return; } $changesets->foreach(function (IdentityInterface $identity, CollectionInterface $changeset) use($entities) { $this->dispatcher->dispatch(Events::PRE_UPDATE, new UpdateEvent($identity, $entities->get($identity), $changeset)); }); $connection->execute($this->queryFor($changesets, $entities)); $changesets->foreach(function (IdentityInterface $identity, CollectionInterface $changeset) use($entities) { $entity = $entities->get($identity); $this->changeset->use($identity, $this->extractor->extract($entity)); $this->dispatcher->dispatch(Events::POST_UPDATE, new UpdateEvent($identity, $entity, $changeset)); }); }
/** * Annotate a set of images. * * Example: * ``` * $images = []; * * $familyPhotoResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); * $images[] = $vision->image($familyPhotoResource, [ * 'FACE_DETECTION' * ]); * * $eiffelTowerResource = fopen(__DIR__ .'/assets/eiffel-tower.jpg', 'r'); * $images[] = $vision->image($eiffelTowerResource, [ * 'LANDMARK_DETECTION' * ]); * * $result = $vision->annotateBatch($images); * ``` * * @param Image[] $images An array consisting of instances of * {@see Google\Cloud\Vision\Image}. * @param array $options Configuration Options * @return Annotation[] */ public function annotateBatch(array $images, array $options = []) { $this->validateBatch($images, Image::class); $requests = []; foreach ($images as $image) { $requests[] = $image->requestObject(); } $res = $this->connection->annotate(['requests' => $requests] + $options); $annotations = []; if (isset($res['responses'])) { foreach ($res['responses'] as $response) { $annotations[] = new Annotation($response); } } return $annotations; }
/** * @return ConnectionInterface */ public function getConnection() { return $this->connection->getConnection(); }
/** * Returns the system type identifier * @link http://php.net/php_systype * * @return string The remote system type, FALSE on error */ public function systype() { return ftp_systype($this->connection->getStream()); }
/** * @return string */ public function getPass() { return $this->connInfo->getPassword(); }
/** * Loads the Database Utilities class. * * @param ConnectionInterface $db * * @return mixed */ public function loadUtils(ConnectionInterface $db) { $className = strpos($db->DBDriver, '\\') === false ? '\\CodeIgniter\\Database\\' . $db->DBDriver . '\\Utils' : $db->DBDriver . '\\Utils'; // Make sure a connection exists if (!$db->connID) { $db->initialize(); } $class = new $className($db); return $class; }
/** * {@inheritdoc} */ public function applyPrefix($value) { return $this->conn->applyPrefix($value); }
/** * Create a Transaction * * Example: * ``` * $transaction = $datastore->transaction(); * ``` * * @see https://cloud.google.com/datastore/docs/concepts/transactions Datastore Transactions * * @param array $options [optional] Configuration options. * @return Transaction */ public function transaction(array $options = []) { $res = $this->connection->beginTransaction($options + ['projectId' => $this->projectId]); return new Transaction(clone $this->operation, $this->projectId, $res['transaction']); }
/** * @return string[] */ protected function getDriver() { return $this->adapterClass ? $this->adapterClass : ($this->con ? $this->con->getAttribute(\PDO::ATTR_DRIVER_NAME) : 'sqlite'); }
/** * Match bindings * @param string $sql * @param array $binds * @param int $bindCount * @param int $ml * @return string */ protected function matchSimpleBinds(string $sql, array $binds, int $bindCount, int $ml) { // Make sure not to replace a chunk inside a string that happens to match the bind marker if ($c = preg_match_all("/'[^']*'/i", $sql, $matches)) { $c = preg_match_all('/' . preg_quote($this->bindMarker, '/') . '/i', str_replace($matches[0], str_replace($this->bindMarker, str_repeat(' ', $ml), $matches[0]), $sql, $c), $matches, PREG_OFFSET_CAPTURE); // Bind values' count must match the count of markers in the query if ($bindCount !== $c) { return $sql; } } else { if (($c = preg_match_all('/' . preg_quote($this->bindMarker, '/') . '/i', $sql, $matches, PREG_OFFSET_CAPTURE)) !== $bindCount) { return $sql; } } do { $c--; $escapedValue = $this->db->escape($binds[$c]); if (is_array($escapedValue)) { $escapedValue = '(' . implode(',', $escapedValue) . ')'; } $sql = substr_replace($sql, $escapedValue, $matches[0][$c][1], $ml); } while ($c !== 0); return $sql; }
/** * Decrement has item count * * @param CategoryEntity $category category object * @param int $amount decrease value * @return int affecting statement */ public function decrement(CategoryEntity $category, $amount = 1) { return $this->conn->table($this->table)->where('id', $category->id)->decrement('count', $amount); }