PHP ConnectionInterface Code Examples

This page contains top rated real world PHP examples of ConnectionInterface extracted from open source projects. You can rate examples to help us improve the quality of examples
Example #1
Show file File: Sender.php Project: romeugodoi/palestra-async
0
 /**
  * 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);
 }
Example #2
Show file File: RemovePersister.php Project: innmind/neo4j-onm
0
 /**
  * {@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));
     });
 }
Example #3
Show file File: InsertPersister.php Project: innmind/neo4j-onm
0
 /**
  * {@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));
     });
 }
Example #4
Show file File: PubSubClient.php Project: Radiergummi/anacronism
0
 /**
  * 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']);
 }
Example #5
Show file File: UpdatePersister.php Project: innmind/neo4j-onm
0
 /**
  * {@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));
     });
 }
Example #6
Show file File: VisionClient.php Project: Radiergummi/anacronism
0
 /**
  * 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;
 }
Example #7
Show file File: AbstractDriver.php Project: ajbdev/contain-reverse-mapper
0
 /**
  * @return ConnectionInterface
  */
 public function getConnection()
 {
     return $this->connection->getConnection();
 }
Example #8
Show file File: FTPWrapper.php Project: ringfreejohn/pbxframework
0
 /**
  * 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());
 }
Example #9
Show file File: ConnectionSpeedyApi.php Project: fire1/speedy
0
 /**
  * @return string
  */
 public function getPass()
 {
     return $this->connInfo->getPassword();
 }
Example #10
Show file File: Database.php Project: titounnes/CodeIgniter4
0
 /**
  * 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;
 }
Example #11
Show file File: ConnectionDecorator.php Project: koolkode/database
0
 /**
  * {@inheritdoc}
  */
 public function applyPrefix($value)
 {
     return $this->conn->applyPrefix($value);
 }
Example #12
Show file File: DatastoreClient.php Project: GoogleCloudPlatform/gcloud-php
0
 /**
  * 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']);
 }
Example #13
Show file File: TestCase.php Project: kalaspuffar/php-orm-benchmark
0
 /**
  * @return string[]
  */
 protected function getDriver()
 {
     return $this->adapterClass ? $this->adapterClass : ($this->con ? $this->con->getAttribute(\PDO::ATTR_DRIVER_NAME) : 'sqlite');
 }
Example #14
Show file File: Query.php Project: titounnes/CodeIgniter4
0
 /**
  * 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;
 }
Example #15
Show file File: CategoryRepository.php Project: mint-soft-com/xpressengine
0
 /**
  * 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);
 }
Frequently Used Methods