Storage/src/Bucket.php
public function createNotification($topic, array $options = [])
    {
        $res = $this->connection->insertNotification($options + $this->identity + [
            'topic' => $this->getFormattedTopic($topic),
            'payload_format' => 'JSON_API_V1'
        ]);

        return new Notification(
            $this->connection,
            $res['id'],
            $this->identity['bucket'],
            $res + [
                'requesterProjectId' => $this->identity['userProject']
            ]
        );
    }
public function createNotification($topic, array $options = [])
    {
        $res = $this->connection->insertNotification($options + $this->identity + [
            'topic' => $this->getFormattedTopic($topic),
            'payload_format' => 'JSON_API_V1'
        ]);

        return new Notification(
            $this->connection,
            $res['id'],
            $this->identity['bucket'],
            $res + [
                'requesterProjectId' => $this->identity['userProject']
            ]
        );
    }
public function createNotification ( $ topic , array $ options = [ ] ) { $ res = $ this -> connection -> insertNotification ( $ options + $ this -> identity + [ 'topic' => $ this -> getFormattedTopic ( $ topic ) , 'payload_format' => 'JSON_API_V1' ] ) ; return new Notification ( $ this -> connection , $ res [ 'id' ] , $ this -> identity [ 'bucket' ] , $ res + [ 'requesterProjectId' => $ this -> identity [ 'userProject' ] ] ) ; }
Create a Cloud PubSub notification.

Please note, the desired topic must be given the IAM role of
"pubsub.publisher" from the service account associated with the project
which contains the bucket you would like to receive notifications from.
Please see the example below for a programmatic example of achieving
this.

Example:
```
// Update the permissions on the desired topic prior to creating the
// notification.
use Google\Cloud\Core\Iam\PolicyBuilder;
use Google\Cloud\PubSub\PubSubClient;

$pubSub = new PubSubClient();
$topicName = 'my-topic';
$serviceAccountEmail = $storage->getServiceAccount();
$topic = $pubSub->topic($topicName);
$iam = $topic->iam();
$updatedPolicy = (new PolicyBuilder($iam->policy()))
->addBinding('roles/pubsub.publisher', [
"serviceAccount:$serviceAccountEmail"
])
->result();
$iam->setPolicy($updatedPolicy);

$notification = $bucket->createNotification($topicName);
```

```
// Use a fully qualified topic name.
$notification = $bucket->createNotification('projects/my-project/topics/my-topic');
```

```
// Provide a Topic object from the Cloud PubSub component.
use Google\Cloud\PubSub\PubSubClient;

$pubSub = new PubSubClient();
$topic = $pubSub->topic('my-topic');
$notification = $bucket->createNotification($topic);
```

```
// Supplying event types to trigger the notifications.
$notification = $bucket->createNotification('my-topic', [
'event_types' => [
'OBJECT_DELETE',
'OBJECT_METADATA_UPDATE'
]
]);
```

@codingStandardsIgnoreStart
@see https://cloud.google.com/storage/docs/pubsub-notifications Cloud PubSub Notifications.
@see https://cloud.google.com/storage/docs/json_api/v1/notifications/insert Notifications insert API documentation.
@see https://cloud.google.com/storage/docs/reporting-changes Registering Object Changes.
@codingStandardsIgnoreEnd

@param string|Topic $topic The topic used to publish notifications.
@param array $options [optional] {
Configuration options.

@type array $custom_attributes An optional list of additional
attributes to attach to each Cloud PubSub message published for
this notification subscription.
@type array $event_types If present, only send notifications about
listed event types. If empty, sent notifications for all event
types. Acceptablue values include `"OBJECT_FINALIZE"`,
`"OBJECT_METADATA_UPDATE"`, `"OBJECT_DELETE"`
, `"OBJECT_ARCHIVE"`.
@type string $object_name_prefix If present, only apply this
notification configuration to object names that begin with this
prefix.
@type string $payload_format The desired content of the Payload.
Acceptable values include `"JSON_API_V1"`, `"NONE"`.
**Defaults to** `"JSON_API_V1"`.
}
@return Notification
@throws \InvalidArgumentException When providing a type other than string
or {@see Google\Cloud\PubSub\Topic} as $topic.
@throws GoogleException When a project ID has not been detected.
@experimental The experimental flag means that while we believe this
method or class is ready for use, it may change before release in
backwards-incompatible ways. Please use with caution, and test
thoroughly when upgrading.
Create a Cloud PubSub notification .