public function syncFile($file)
 {
     $extension = pathinfo($file, PATHINFO_EXTENSION);
     if ('php' === $extension) {
         return;
     }
     // local hash
     $md5Local = md5_file($file);
     // remote hash
     $relativePath = $this->getRelativePath($file);
     try {
         $obj = $this->container->get_object($relativePath);
         if ($obj->getETag() != $md5Local) {
             $this->log('~ ' . $relativePath);
             $obj->content_type = $this->getMimeTypeFromExtension($extension);
             $obj->load_from_filename($file);
         }
     } catch (NoSuchObjectException $e) {
         $this->log('+ ' . $relativePath);
         $obj = $this->container->create_object($relativePath);
         $obj->content_type = $this->getMimeTypeFromExtension($extension);
         $obj->load_from_filename($file);
     }
 }
Ejemplo n.º 2
0
 /**
  * Test CDN connection
  *
  * @param string $error
  * @return boolean
  */
 function test(&$error)
 {
     if (!parent::test($error)) {
         return false;
     }
     if (!$this->_init($error) || !$this->_init_container($error)) {
         return false;
     }
     $string = 'test_rscf_' . md5(time());
     try {
         $object = $this->_container->create_object($string);
         $object->content_type = 'text/plain';
         $object->write($string, strlen($string));
     } catch (Exception $exception) {
         $error = sprintf('Unable to write object (%s).', $exception->getMessage());
         return false;
     }
     try {
         $object = $this->_container->get_object($string);
         $data = $object->read();
     } catch (Exception $exception) {
         $error = sprintf('Unable to read object (%s).', $exception->getMessage());
         try {
             $this->_container->delete_object($string);
         } catch (Exception $exception) {
         }
         return false;
     }
     if ($data != $string) {
         $error = 'Objects are not equal.';
         try {
             $this->_container->delete_object($string);
         } catch (Exception $exception) {
         }
         return false;
     }
     try {
         $this->_container->delete_object($string);
     } catch (Exception $exception) {
         $error = sprintf('Unable to delete object (%s).', $exception->getMessage());
         return false;
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * ensure a subcontainer file exists and return it's object
  * @param \CF_Container $container
  * @return \CF_Object
  */
 private function getSubContainerFile($container)
 {
     try {
         return $container->get_object(self::SUBCONTAINER_FILE);
     } catch (\NoSuchObjectException $e) {
         return $container->create_object(self::SUBCONTAINER_FILE);
     }
 }
 /**
  * @param \CF_Container $container
  */
 function it_should_not_mask_exception_when_calculate_checksum($container)
 {
     $container->get_object('filename')->willThrow(new \RuntimeException('checksum'));
     $this->shouldThrow(new \RuntimeException('checksum'))->duringChecksum('filename');
 }
Ejemplo n.º 5
0
 /**
  * Return an Object instance for the remote storage Object
  *
  * Given a name, return a Object instance representing the
  * remote storage object.
  *
  * Example:
  * <code>
  * # ... authentication code excluded (see previous examples) ...
  * #
  * $conn = new CF_Connection($auth);
  *
  * $public_container = $conn->get_container("public");
  *
  * # This call only fetches header information and not the content of
  * # the storage object.  Use the Object's read() or stream() methods
  * # to obtain the object's data.
  * #
  * $pic = $public_container->get_object("baby.jpg");
  * </code>
  *
  * @param string $obj_name name of storage Object
  * @return obj CF_Object instance
  */
 function get_object($obj_name = NULL)
 {
     $this->initContainer();
     return parent::get_object($obj_name);
 }