<commit_before><?php

namespace Gaufrette\Adapter;

use CF_Container;

/**
 * Rackspace cloudfiles adapter
 *
 * @package Gaufrette
 * @author  <NAME> <<EMAIL>>
 */
class RackspaceCloudfiles extends Base
{
    protected $container;

    /**
     * Contructor
     *
     * @param  CF_Container $container A CF_Container instance
     */
    public function __construct(CF_Container $container)
    {
        $this->container = $container;
    }

    /**
     * {@inheritDoc}
     */
    public function read($key)
    {
        $object = $this->container->get_object($key);

        try {
            return $object->read();
        } catch (\Exception $e) {
            throw new \RuntimeException(sprintf('Could not read the \'%s\' file.', $key));
        }
    }

    /**
     * {@inheritDoc}
     */
    public function rename($key, $new)
    {
        try {
            $this->write($new, $this->read($key));
            $this->delete($key);
        } catch (\Exception $e) {
            throw new \RuntimeException(sprintf('Could not rename the \'%s\' file to \'%s\'.', $key, $new));
       }
    }

    /**
     * {@inheritDoc}
     */
    public function write($key, $content, array $metadata = null)
    {
        $object = $this->tryGetObject($key);
        if (false === $object) {
            // the object does not exist, so we create it
            $object = $this->container->create_object($key);
        }

        if (!$object->write($content)) {
            throw new \RuntimeException(sprintf('Could not write the \'%s\' file.', $key));
        }

        return Util\Size::fromString($content);
    }

    /**
     * {@inheritDoc}
     */
    public function exists($key)
    {
        return false === $this->tryGetObject($key);
    }

    /**
     * {@inheritDoc}
     */
    public function keys()
    {
        return $this->container->list_objects(0, null, null);
    }

    /**
     * {@inheritDoc}
     */
    public function mtime($key)
    {
        // as far as I know, there is no such information available through the
        // API provided by rackspace
        return null;
    }

    /**
     * {@inheritDoc}<commit_msg>RS adapter: renaming fromString to fromContent<commit_after><?php

namespace Gaufrette\Adapter;

use CF_Container;

/**
 * Rackspace cloudfiles adapter
 *
 * @package Gaufrette
 * @author  <NAME> <<EMAIL>>
 */
class RackspaceCloudfiles extends Base
{
    protected $container;

    /**
     * Contructor
     *
     * @param  CF_Container $container A CF_Container instance
     */
    public function __construct(CF_Container $container)
    {
        $this->container = $container;
    }

    /**
     * {@inheritDoc}
     */
    public function read($key)
    {
        $object = $this->container->get_object($key);

        try {
            return $object->read();
        } catch (\Exception $e) {
            throw new \RuntimeException(sprintf('Could not read the \'%s\' file.', $key));
        }
    }

    /**
     * {@inheritDoc}
     */
    public function rename($key, $new)
    {
        try {
            $this->write($new, $this->read($key));
            $this->delete($key);
        } catch (\Exception $e) {
            throw new \RuntimeException(sprintf('Could not rename the \'%s\' file to \'%s\'.', $key, $new));
       }
    }

    /**
     * {@inheritDoc}
     */
    public function write($key, $content, array $metadata = null)
    {
        $object = $this->tryGetObject($key);
        if (false === $object) {
            // the object does not exist, so we create it
            $object = $this->container->create_object($key);
        }

        if (!$object->write($content)) {
            throw new \RuntimeException(sprintf('Could not write the \'%s\' file.', $key));
        }

        return Util\Size::fromContent($content);
    }

    /**
     * {@inheritDoc}
     */
    public function exists($key)
    {
        return false === $this->tryGetObject($key);
    }

    /**
     * {@inheritDoc}
     */
    public function keys()
    {
        return $this->container->list_objects(0, null, null);
    }

    /**
     * {@inheritDoc}
     */
    public function mtime($key)
    {
        // as far as I know, there is no such information available through the
        // API provided by rackspace
        return null;
    }

    /**
     * {@inheritDoc}
{'fraction_non_alphanumeric': 0.15209387942936034, 'fraction_numerical': 0.0004601932811780948, 'mean_word_length': 1.8941411451398136, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3008761', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1264, 'n_words': 310}