/** * It should be instantiated with the title of * the workshop and the path to the DI configuration file. * * @param string $workshopTitle The workshop title - this is used throughout the application * @param string $diConfigFile The absolute path to the DI configuration file */ public function __construct($workshopTitle, $diConfigFile) { Assertion::string($workshopTitle); Assertion::file($diConfigFile); $this->workshopTitle = $workshopTitle; $this->diConfigFile = $diConfigFile; }
/** * @Given /^I have some generated config at "([^"]*)"$/ */ public function iHaveSomeGeneratedConfigAt($arg1) { $this->configFilePath = getcwd() . "/{$arg1}/"; Assertion::file($this->configFilePath . 'configured.json'); $this->config = json_decode(file_get_contents($this->configFilePath . 'configured.json')); Assertion::isInstanceOf($this->config, 'stdClass'); }
public function read($filename) { Assertion::file($filename); $this->filename = $filename; $config = (include $this->filename); $this->assertConfigIsValid($config); return $config; }
/** * @param string $filename * * @throws InvalidArgumentException * * @return FileReader */ public function create($filename) { Assertion::file($filename); $readerClass = $this->getReaderClass($filename); if (!isset($this->readers[$readerClass])) { $this->readers[$readerClass] = new $readerClass(); } return $this->readers[$readerClass]; }
public function read($filename) { Assertion::file($filename); $this->filename = $filename; $config = json_decode(file_get_contents($filename), true); if (json_last_error() !== JSON_ERROR_NONE) { throw InvalidConfigException::fromJSONFileError($filename, $this->getJsonError()); } return $config; }
protected function marshallInput(InputInterface $input) : string { $inputFile = $input->getArgument('file'); if ($inputFile) { Assertion::file($inputFile); $inputBuffer = file_get_contents($inputFile); } else { $inputBuffer = ''; $stdin = fopen('php://stdin', 'r'); stream_set_blocking($stdin, false); while ($line = fgets($stdin)) { $inputBuffer .= $line; } } Assertion::notEmpty($inputBuffer, 'Input must not be empty'); return $inputBuffer; }
public function testFileDoesNotExists() { $this->setExpectedException('Assert\\AssertionFailedException', null, Assertion::INVALID_FILE); Assertion::file(__DIR__ . '/does-not-exists'); }
/** * Creates a new Doc with the DocStream set to the content of * the specified file path. * * @param $DocType * @param $DocMimeType * @param $FilePath * @return Doc * * @throws \InvalidArgumentException If the file does not exist or is not readable. */ public static function fromFile($DocType, $DocMimeType, $FilePath) { Assertion::file($FilePath, "{$FilePath} does not exist."); Assertion::readable($FilePath, "{$FilePath} is not readable."); return new self($DocType, $DocMimeType, file_get_contents($FilePath)); }
/** * Parses config file and returns array. * * @param string $file * * @return array */ private function parseConfigFile($file) { Assertion::file($file, 'Can\'t parse config file. File does not exist: ' . $file); $config = Yaml::parse(file_get_contents($file)); if (is_null($config)) { $config = array(); } return $config; }
public function create($key, $description) { $ret = false; try { $prefix = Carbon::now()->format('YmdHis'); $keys = $this->getSlugKeyName($key); $classname = $keys . "Migration"; $filename = MIGRATIONPATH . DS . $classname . ".php"; $classtxt = Stringy::create($this->migration_model)->replace("##description##", $description)->replace("##date##", $prefix)->replace('##classname##', $classname)->replace('##key##', $keys)->__toString(); file_put_contents($filename, $classtxt); Assertion::file($filename); $ret = true; } catch (\Exception $e) { $ret = false; } catch (AssertionFailedException $ex) { $ret = false; } return $ret; }
/** * Put large blob (> 64 MB) * * @param string $containerName Container name * @param string $blobName Blob name * @param string $localFileName Local file name to be uploaded * @param array $metadata Key/value pairs of meta data * @param string $leaseId Lease identifier * @param array $additionalHeaders Additional headers. See http://msdn.microsoft.com/en-us/library/dd179371.aspx for more information. * @return object Partial blob properties * @throws BlobException */ public function putLargeBlob($containerName = '', $blobName = '', $localFileName = '', $metadata = array(), $leaseId = null, $additionalHeaders = array()) { Assertion::notEmpty($containerName, 'Container name is not specified'); self::assertValidContainerName($containerName); Assertion::notEmpty($blobName, 'Blob name is not specified.'); Assertion::notEmpty($localFileName, 'Local file name is not specified.'); Assertion::file($localFileName, 'Local file name is not specified.'); self::assertValidRootContainerBlobName($containerName, $blobName); if (filesize($localFileName) < self::MAX_BLOB_SIZE) { return $this->putBlob($containerName, $blobName, $localFileName, $metadata, $leaseId, $additionalHeaders); } $numberOfParts = ceil(filesize($localFileName) / self::MAX_BLOB_TRANSFER_SIZE); $blockIdentifiers = array(); for ($i = 0; $i < $numberOfParts; $i++) { $blockIdentifiers[] = $this->generateBlockId($i); } $fp = fopen($localFileName, 'r'); if ($fp === false) { throw new BlobException('Could not open local file.'); } for ($i = 0; $i < $numberOfParts; $i++) { fseek($fp, $i * self::MAX_BLOB_TRANSFER_SIZE); $fileContents = fread($fp, self::MAX_BLOB_TRANSFER_SIZE); $this->putBlock($containerName, $blobName, $blockIdentifiers[$i], $fileContents, $leaseId); $fileContents = null; unset($fileContents); } fclose($fp); $this->putBlockList($containerName, $blobName, $blockIdentifiers, $metadata, $leaseId, $additionalHeaders); return $this->getBlobInstance($containerName, $blobName, null, $leaseId); }
/** * Returns a config file path. * * @param0 string $project Project name * * @return string */ private function getConfigFilePath($project) { $path = $this->path . '/' . $project . '.yml'; Assertion::file($path); return realpath($path); }
/** * Sets a certificate file path and optional passphrase to use. * * @param string $certificateFilePath Path to a certificate file. * @return Config * * @throws \InvalidArgumentException If certificate path is invalid. */ public function setCertificateFilePath($certificateFilePath, $passphrase = null) { Assertion::file($certificateFilePath); Assertion::readable($certificateFilePath); $this->certificateFilePath = $certificateFilePath; $this->soapClientOptions['local_cert'] = $certificateFilePath; if (!empty($passphrase)) { $this->soapClientOptions['passphrase'] = $passphrase; } return $this; }
/** * @param string $filename * * @throws InvalidArgumentException * * @return $this */ public function configFromFile($filename) { Assertion::file($filename); $this->readFileAndMergeConfig($filename); return $this; }
/** * @Given /^I have a config file at "([^"]*)"$/ */ public function iHaveAConfigFileAt($arg1) { $this->configFilePath = getcwd() . "/{$arg1}/"; Assertion::file($this->configFilePath . 'quick-configure.json'); }
/** * @Given /^it should be in JSON format$/ */ public function itShouldBeInJsonFormat() { $file = $this->path . '/' . $this->fileName . '.' . $this->format; Assertion::file($file); Assertion::notNull(json_decode(file_get_contents($file))); }