Exemplo n.º 1
0
 /**
  * Creates a new JSON based file store.
  *
  * @param string $cassettePath Path to the cassette directory.
  * @param string $cassetteName Path to a file, will be created if not existing.
  */
 public function __construct($cassettePath, $cassetteName)
 {
     $file = $cassettePath . DIRECTORY_SEPARATOR . $cassetteName;
     if (!file_exists($file)) {
         file_put_contents($file, '[]');
     }
     Assertion::file($file, "Specified path '{$file}' is not a file.");
     Assertion::readable($file, "Specified file '{$file}' must be readable.");
     Assertion::writeable($file, "Specified path '{$file}' must be writeable.");
     $this->handle = fopen($file, 'r+');
     $this->filePath = $file;
 }
Exemplo n.º 2
0
 /**
  * Creates a new YAML based file store.
  *
  * @param string $cassettePath Path to the cassette directory.
  * @param string $cassetteName Path to a file, will be created if not existing.
  * @param Parser $parser Parser used to decode yaml.
  * @param Dumper $dumper Dumper used to encode yaml.
  */
 public function __construct($cassettePath, $cassetteName, Parser $parser = null, Dumper $dumper = null)
 {
     $file = $cassettePath . DIRECTORY_SEPARATOR . $cassetteName;
     if (!file_exists($file)) {
         file_put_contents($file, '');
     }
     Assertion::file($file, "Specified path '{$file}' is not a file.");
     Assertion::readable($file, "Specified file '{$file}' must be readable.");
     Assertion::writeable($file, "Specified path '{$file}' must be writable.");
     $this->handle = fopen($file, 'r+');
     $this->yamlParser = $parser ?: new Parser();
     $this->yamlDumper = $dumper ?: new Dumper();
 }
Exemplo n.º 3
0
 /**
  * Creates a new file store.
  *
  * If the cassetteName contains PATH_SEPARATORs, subfolders of the
  * cassettePath are autocreated when not existing.
  *
  * @param string  $cassettePath   Path to the cassette directory.
  * @param string  $cassetteName   Path to the cassette file, relative to the path.
  * @param string  $defaultContent Default data for this cassette if its not existing
  */
 public function __construct($cassettePath, $cassetteName, $defaultContent = '[]')
 {
     Assertion::directory($cassettePath, "Cassette path '{$cassettePath}' is not existing or not a directory");
     $this->filePath = rtrim($cassettePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $cassetteName;
     if (!is_dir(dirname($this->filePath))) {
         mkdir(dirname($this->filePath), 0777, true);
     }
     if (!file_exists($this->filePath) || 0 === filesize($this->filePath)) {
         file_put_contents($this->filePath, $defaultContent);
         $this->isNew = true;
     }
     Assertion::file($this->filePath, "Specified path '{$this->filePath}' is not a file.");
     Assertion::readable($this->filePath, "Specified file '{$this->filePath}' must be readable.");
     $this->handle = fopen($this->filePath, 'r+');
 }