<commit_before><?php
/**
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Google\Cloud\Storage;

use Google\Cloud\Storage\Acl;
use Google\Cloud\Storage\Connection\ConnectionInterface;
use Google\Cloud\Storage\Object;

class Bucket
{
    /**
     * @var ConnectionInterface
     */
    private $connection;

    /**
     * @var array
     */
    private $identity;

    /**
     * @var array
     */
    private $data;

    /**
     * @var Acl
     */
    private $acl;

    /**
     * @var Acl
     */
    private $defaultAcl;

    /**
     * @param ConnectionInterface $connection
     * @param string $name
     * @param array $data
     */
    public function __construct(ConnectionInterface $connection, $name, array $data = null)
    {
        $this->connection = $connection;
        $this->identity = ['bucket' => $name];
        $this->data = $data;
        $this->acl = new Acl($this->connection, 'bucketAccessControls', $this->identity);
        $this->defaultAcl = new Acl($this->connection, 'defaultObjectAccessControls', $this->identity);
    }

    /**
     * Configure ACL for this bucket.
     *
     * @return Acl
     */
    public function acl()
    {
        return $this->acl;
    }

    /**
     * Configure default object ACL for this bucket.
     *
     * @return Acl
     */
    public function defaultAcl()
    {
        return $this->defaultAcl;
    }

    /**
     * Check whether or not the bucket exists.
     *
     * Example:
     * ```
     * $bucket->exists();
     * ```
     *
     * @return bool
     */
    public function exists()
    {
        try {
            $resp = $this->connection->getBucket($this->identity + ['fields' => 'name']);
        } catch (\Exception $ex) {
            return false;
        }

        return true;
    }

    /**
     * Upload data from a stream.
     *
     * Example:
     * ```
     * $bucket->uploadFromStream(
     *     fopen('image.jpg', 'r'),
     *     'image.jpg',
     *     ['contentType' => 'image/jpeg']
     * );
     * ```
     *
     * @param resource|StreamInterface $data
     * @param string $destination Name of where the file will be stored.
     * @param array $options Configuration options.
     * @return Object
     */
    public function uploadFromStream($data, $destination, array $options = [])
    {
        $response = $this->connection->uploadObject($options + [
            'bucket' => $this->identity['bucket'],
            'data' => $data,
            'name' => $destination
        ]);

        return new Object($this->connection, $destination, $this->identity['bucket'], null, $response);
    }

    /**
     * Upload
     *
     * Example:
     * ```
     * ```
     *
     * @param string $path Path to the file to be uploaded.
     * @param array $options Configuration options.
     * @return Object
     */
    public function uploadFromPath($path, array $options = [])
    {

    }

    /**
     * Lazily instantiates an object.
     *
     * Example:
     * ```
     * $object = $bucket->object('file.txt');
     * ```
     *
     * @param string $objectName The name of the object to request.
     * @param array $options Configuration options. {
     *     @type string $generation Request a specific revision of the object.
     * }
     * @return Object
     */
    public function object($objectName, array $options = [])
    {
        $generation = isset($options['generation']) ? $options['generation'] : null;

        return new Object($this->connection, $objectName, $this->identity['bucket'], $generation);
    }

    /**
     * @todo investigate abstracting the generator logic<commit_msg>remove todo<commit_after><?php
/**
 * Copyright 2015 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace Google\Cloud\Storage;

use Google\Cloud\Storage\Acl;
use Google\Cloud\Storage\Connection\ConnectionInterface;
use Google\Cloud\Storage\Object;

class Bucket
{
    /**
     * @var ConnectionInterface
     */
    private $connection;

    /**
     * @var array
     */
    private $identity;

    /**
     * @var array
     */
    private $data;

    /**
     * @var Acl
     */
    private $acl;

    /**
     * @var Acl
     */
    private $defaultAcl;

    /**
     * @param ConnectionInterface $connection
     * @param string $name
     * @param array $data
     */
    public function __construct(ConnectionInterface $connection, $name, array $data = null)
    {
        $this->connection = $connection;
        $this->identity = ['bucket' => $name];
        $this->data = $data;
        $this->acl = new Acl($this->connection, 'bucketAccessControls', $this->identity);
        $this->defaultAcl = new Acl($this->connection, 'defaultObjectAccessControls', $this->identity);
    }

    /**
     * Configure ACL for this bucket.
     *
     * @return Acl
     */
    public function acl()
    {
        return $this->acl;
    }

    /**
     * Configure default object ACL for this bucket.
     *
     * @return Acl
     */
    public function defaultAcl()
    {
        return $this->defaultAcl;
    }

    /**
     * Check whether or not the bucket exists.
     *
     * Example:
     * ```
     * $bucket->exists();
     * ```
     *
     * @return bool
     */
    public function exists()
    {
        try {
            $resp = $this->connection->getBucket($this->identity + ['fields' => 'name']);
        } catch (\Exception $ex) {
            return false;
        }

        return true;
    }

    /**
     * Upload data from a stream.
     *
     * Example:
     * ```
     * $bucket->uploadFromStream(
     *     fopen('image.jpg', 'r'),
     *     'image.jpg',
     *     ['contentType' => 'image/jpeg']
     * );
     * ```
     *
     * @param resource|StreamInterface $data
     * @param string $destination Name of where the file will be stored.
     * @param array $options Configuration options.
     * @return Object
     */
    public function uploadFromStream($data, $destination, array $options = [])
    {
        $response = $this->connection->uploadObject($options + [
            'bucket' => $this->identity['bucket'],
            'data' => $data,
            'name' => $destination
        ]);

        return new Object($this->connection, $destination, $this->identity['bucket'], null, $response);
    }

    /**
     * Upload
     *
     * Example:
     * ```
     * ```
     *
     * @param string $path Path to the file to be uploaded.
     * @param array $options Configuration options.
     * @return Object
     */
    public function uploadFromPath($path, array $options = [])
    {

    }

    /**
     * Lazily instantiates an object.
     *
     * Example:
     * ```
     * $object = $bucket->object('file.txt');
     * ```
     *
     * @param string $objectName The name of the object to request.
     * @param array $options Configuration options. {
     *     @type string $generation Request a specific revision of the object.
     * }
     * @return Object
     */
    public function object($objectName, array $options = [])
    {
        $generation = isset($options['generation']) ? $options['generation'] : null;

        return new Object($this->connection, $objectName, $this->identity['bucket'], $generation);
    }

    /**
{'fraction_non_alphanumeric': 0.13482067890128344, 'fraction_numerical': 0.0019191555715485187, 'mean_word_length': 2.1275318829707426, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1167590', 'n_tokens_mistral': 2372, 'n_tokens_neox': 2329, 'n_words': 664}