本文整理汇总了PHP中stream_is_local函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_is_local函数的具体用法?PHP stream_is_local怎么用?PHP stream_is_local使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_is_local函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: loadClassMetadata
/**
* {@inheritdoc}
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
if (null === $this->classes) {
if (!stream_is_local($this->file)) {
throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
}
if (null === $this->yamlParser) {
$this->yamlParser = new Parser();
}
$classes = $this->yamlParser->parse(file_get_contents($this->file));
if (empty($classes)) {
return false;
}
// not an array
if (!is_array($classes)) {
throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file));
}
$this->classes = $classes;
}
if (isset($this->classes[$metadata->getClassName()])) {
$yaml = $this->classes[$metadata->getClassName()];
if (isset($yaml['attributes']) && is_array($yaml['attributes'])) {
foreach ($yaml['attributes'] as $attribute => $data) {
if (isset($data['groups'])) {
foreach ($data['groups'] as $group) {
$metadata->addAttributeGroup($attribute, $group);
}
}
}
}
return true;
}
return false;
}
开发者ID:vadim2404,项目名称:symfony,代码行数:37,代码来源:YamlFileLoader.php
示例2: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
$messages = array();
if (!stream_is_local($resource)) {
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $resource));
}
try {
$file = new \SplFileObject($resource, 'rb');
} catch (\RuntimeException $e) {
throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
}
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
$file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
foreach ($file as $data) {
if (substr($data[0], 0, 1) === '#') {
continue;
}
if (!isset($data[1])) {
continue;
}
if (count($data) == 2) {
$messages[$data[0]] = $data[1];
} else {
continue;
}
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
开发者ID:kingsj,项目名称:core,代码行数:35,代码来源:CsvFileLoader.php
示例3: copy
/**
* Copies and transforms a file.
*
* This method only copies the file if the origin file is newer than the target file.
*
* By default, if the target already exists, it is not overridden.
*
* @param string $originFile The original filename
* @param string $targetFile The target filename
* @param boolean $override Whether to override an existing file or not
*
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $override = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
throw new IOException(sprintf('Failed to copy %s because file does not exist', $originFile));
}
$this->mkdir(dirname($targetFile));
if (!$override && is_file($targetFile)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
} else {
$doCopy = true;
}
if (!$doCopy) {
return;
}
$event = new FileCopyEvent($originFile, $targetFile);
$event = $this->event_dispatcher->dispatch(FilesystemEvents::COPY, $event);
$originFile = $event->getSource();
$targetFile = $event->getTarget();
if ($event->isModified()) {
file_put_contents($targetFile, $event->getContent());
return;
}
// No listeners modified the file, so just copy it (original behaviour & code)
// https://bugs.php.net/bug.php?id=64634
$source = fopen($originFile, 'r');
$target = fopen($targetFile, 'w+');
stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy %s to %s', $originFile, $targetFile));
}
}
开发者ID:shauncjones,项目名称:site-builder,代码行数:47,代码来源:TransformingFilesystem.php
示例4: load
/**
*
* {@inheritdoc}
*
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!is_dir($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
try {
$rb = new \ResourceBundle($locale, $resource);
} catch (\Exception $e) {
// HHVM compatibility: constructor throws on invalid resource
$rb = null;
}
if (!$rb) {
throw new InvalidResourceException(sprintf('Cannot load resource "%s"', $resource));
} elseif (intl_is_failure($rb->getErrorCode())) {
throw new InvalidResourceException($rb->getErrorMessage(), $rb->getErrorCode());
}
$messages = $this->flatten($rb);
$catalogue = new MessageCatalogue($locale);
$catalogue->add($messages, $domain);
if (class_exists('Symfony\\Component\\Config\\Resource\\DirectoryResource')) {
$catalogue->addResource(new DirectoryResource($resource));
}
return $catalogue;
}
开发者ID:ngitimfoyo,项目名称:Nyari-AppPHP,代码行数:32,代码来源:IcuResFileLoader.php
示例5: load
/**
* Loads a Yaml file.
*
* @param string $file A Yaml file path
* @param string|null $type The resource type
*
* @return RouteCollection A RouteCollection instance
*
* @throws \InvalidArgumentException When a route can't be parsed because YAML is invalid
*
* @api
*/
public function load($file, $type = null)
{
$path = $this->locator->locate($file);
if (!stream_is_local($path)) {
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path));
}
if (!file_exists($path)) {
throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path));
}
if (null === $this->yamlParser) {
$this->yamlParser = new YamlParser();
}
$config = $this->yamlParser->parse(file_get_contents($path));
$collection = new RouteCollection();
$collection->addResource(new FileResource($path));
// empty file
if (null === $config) {
return $collection;
}
// not an array
if (!is_array($config)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path));
}
foreach ($config as $name => $config) {
$this->validate($config, $name, $path);
if (isset($config['resource'])) {
$this->parseImport($collection, $config, $path, $file);
} else {
$this->parseRoute($collection, $name, $config, $path);
}
}
return $collection;
}
开发者ID:nuwe1,项目名称:symfony,代码行数:45,代码来源:YamlFileLoader.php
示例6: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
try {
$messages = Neon\Neon::decode(file_get_contents($resource));
} catch (Nette\Utils\NeonException $e) {
throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
} catch (Nette\Neon\Exception $e) {
throw new InvalidResourceException(sprintf("Error parsing Neon: %s", $e->getMessage()), 0, $e);
}
if (empty($messages)) {
$messages = array();
}
if (!is_array($messages)) {
throw new InvalidResourceException(sprintf('The file "%s" must contain a Neon array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
开发者ID:tomasstrejcek,项目名称:Translation,代码行数:28,代码来源:NeonFileLoader.php
示例7: sync
/**
* (non-PHPDoc)
*
* @see \phpbu\App\Backup\Sync::sync()
* @param \phpbu\App\Backup\Target $target
* @param \phpbu\App\Result $result
* @throws \phpbu\App\Backup\Sync\Exception
*/
public function sync(Target $target, Result $result)
{
$sourcePath = $target->getPathname();
$dropboxPath = $this->path . $target->getFilename();
$client = new DropboxApi\Client($this->token, "phpbu/1.1.0");
$pathError = DropboxApi\Path::findErrorNonRoot($dropboxPath);
if (substr(__FILE__, 0, 7) == 'phar://') {
DropboxApi\RootCertificates::useExternalPaths();
}
if ($pathError !== null) {
throw new Exception(sprintf('Invalid \'dropbox-path\': %s', $pathError));
}
$size = null;
if (stream_is_local($sourcePath)) {
$size = filesize($sourcePath);
}
try {
$fp = fopen($sourcePath, 'rb');
$res = $client->uploadFile($dropboxPath, DropboxApi\WriteMode::add(), $fp, $size);
fclose($fp);
} catch (\Exception $e) {
throw new Exception($e->getMessage(), null, $e);
}
$result->debug('upload: done (' . $res['size'] . ')');
}
开发者ID:todiadiyatmo,项目名称:phpbu,代码行数:33,代码来源:Dropbox.php
示例8: load
/**
* Loads a JSON file
*
* @param string $file A JSON file path
* @param string|null $type The resource type
*
* @return RouteCollection
*
* @throws InvalidArgumentException When the JSON is invalid
*/
public function load($file, $type = null)
{
$path = $this->locator->locate($file);
if (!stream_is_local($path)) {
$message = sprintf('This is not a local file "%s"', $path);
throw new InvalidArgumentException($message);
}
if (!file_exists($path)) {
$message = sprintf('File "%s" not found', $path);
throw new InvalidArgumentException($message);
}
$parsedConfig = json_decode(file_get_contents($path), true);
$collection = new RouteCollection();
$collection->addResource(new FileResource($path));
// empty file
if ($parsedConfig === null) {
return $collection;
}
// not an array
if (!is_array($parsedConfig)) {
$message = sprintf('The file "%s" must contain a JSON object', $path);
throw new InvalidArgumentException($message);
}
foreach ($parsedConfig as $name => $config) {
$this->validate($config, $name, $path);
if (isset($config['resource'])) {
$this->parseImport($collection, $config, $path, $file);
} else {
$this->parseRoute($collection, $name, $config, $path);
}
}
return $collection;
}
开发者ID:novuso,项目名称:common-bundle,代码行数:43,代码来源:JsonFileLoader.php
示例9: loadFile
/**
* @param string $file
* @return array
*/
protected function loadFile($file)
{
if (!class_exists('Symfony\\Component\\Yaml\\Parser')) {
throw new \RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.');
}
if (!stream_is_local($file)) {
throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
}
if (!file_exists($file)) {
throw new \InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
}
if (null === $this->yamlParser) {
$this->yamlParser = new Parser();
}
try {
$config = $this->yamlParser->parse(file_get_contents($file));
if (!is_array($config)) {
throw new \InvalidArgumentException(sprintf('The contents of the file "%s" is not an array.', $file));
}
} catch (ParseException $e) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
}
$this->app->parseParameters($config);
return $config;
}
开发者ID:vudaltsov,项目名称:silex-project,代码行数:29,代码来源:YamlConfigLoader.php
示例10: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
$messages = array();
try {
$file = new \SplFileObject($resource, 'rb');
} catch (\RuntimeException $e) {
throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
}
$file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
$file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
foreach ($file as $data) {
if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === count($data)) {
$messages[$data[0]] = $data[1];
}
}
$catalogue = parent::load($messages, $locale, $domain);
if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$catalogue->addResource(new FileResource($resource));
}
return $catalogue;
}
开发者ID:Dren-x,项目名称:mobit,代码行数:30,代码来源:CsvFileLoader.php
示例11: copy
/**
* Copies a file.
*
* This method only copies the file if the origin file is newer than the target file.
*
* By default, if the target already exists, it is not overridden.
*
* @param string $originFile The original filename
* @param string $targetFile The target filename
* @param bool $override Whether to override an existing file or not
*
* @throws FileNotFoundException When originFile doesn't exist
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $override = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
}
$this->mkdir(dirname($targetFile));
if (!$override && is_file($targetFile) && null === parse_url($originFile, PHP_URL_HOST)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
} else {
$doCopy = true;
}
if ($doCopy) {
// https://bugs.php.net/bug.php?id=64634
if (false === ($source = @fopen($originFile, 'r'))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
}
if (false === ($target = @fopen($targetFile, 'w'))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
}
stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
}
}
}
开发者ID:ymnl007,项目名称:92five,代码行数:42,代码来源:Filesystem.php
示例12: copy
/**
* Copies a file or directory.
* @return void
* @throws Nette\IOException
*/
public static function copy($source, $dest, $overwrite = TRUE)
{
if (stream_is_local($source) && !file_exists($source)) {
throw new Nette\IOException("File or directory '{$source}' not found.");
} elseif (!$overwrite && file_exists($dest)) {
throw new Nette\InvalidStateException("File or directory '{$dest}' already exists.");
} elseif (is_dir($source)) {
static::createDir($dest);
foreach (new \FilesystemIterator($dest) as $item) {
static::delete($item);
}
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir()) {
static::createDir($dest . '/' . $iterator->getSubPathName());
} else {
static::copy($item, $dest . '/' . $iterator->getSubPathName());
}
}
} else {
static::createDir(dirname($dest));
if (@stream_copy_to_stream(fopen($source, 'r'), fopen($dest, 'w')) === FALSE) {
// @ is escalated to exception
throw new Nette\IOException("Unable to copy file '{$source}' to '{$dest}'.");
}
}
}
开发者ID:Richmond77,项目名称:learning-nette,代码行数:31,代码来源:FileSystem.php
示例13: __construct
/**
* Disk constructor.
* @param string $path
* @throws DiskException
*/
public function __construct(string $path = ".")
{
// Check if provided path is local stream
if (!stream_is_local($path)) {
throw DiskException::diskInit("Path to disk must be a local directory");
}
// Check if path is a symbolic link
if (@is_link($path) === true) {
throw DiskException::diskInit("Path to disk cannot be a symbolic link");
}
// Resolve path
$realPath = @realpath($path);
// Check if path couldn't be resolved
if (!$realPath) {
// Create directory
$this->createDir($path, 0777);
$realPath = @realpath($path);
}
// Set resolved path
$path = $realPath;
// Confirm if path leads to a directory
if (!$path || !@is_dir($path)) {
throw DiskException::diskInit("Disk must be provided with path to a directory");
}
// Set path variable for this instance
// Disk path must have a trailing DIRECTORY_SEPARATOR
$this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
// Check and set privileges
$this->privilegeRead = @is_readable($this->path) ? true : false;
$this->privilegeWrite = @is_writable($this->path) ? true : false;
if (!$this->privilegeRead && !$this->privilegeWrite) {
// Doesn't have both read/write privileges
throw DiskException::diskInit("Disk doesn't have read and write privileges");
}
}
开发者ID:comelyio,项目名称:comely,代码行数:40,代码来源:Disk.php
示例14: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
list($xml, $encoding) = $this->parseFile($resource);
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
$catalogue = new MessageCatalogue($locale);
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
$attributes = $translation->attributes();
if (!(isset($attributes['resname']) || isset($translation->source))) {
continue;
}
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values
$target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding);
$catalogue->set((string) $source, $target, $domain);
$metadata = array();
if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) {
$metadata['notes'] = $notes;
}
if ($translation->target->attributes()) {
$metadata['target-attributes'] = $translation->target->attributes();
}
$catalogue->setMetadata((string) $source, $metadata, $domain);
}
if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$catalogue->addResource(new FileResource($resource));
}
return $catalogue;
}
开发者ID:symstriker,项目名称:symfony,代码行数:40,代码来源:XliffFileLoader.php
示例15: copy
public function copy($originFile, $targetFile, $override = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
}
$this->mkdir(dirname($targetFile));
$doCopy = true;
if (!$override && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
}
if ($doCopy) {
if (false === ($source = @fopen($originFile, 'r'))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
}
if (false === ($target = @fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true)))))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
}
$bytesCopied = stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
}
@chmod($targetFile, fileperms($targetFile) | fileperms($originFile) & 0111);
if (stream_is_local($originFile) && $bytesCopied !== ($bytesOrigin = filesize($originFile))) {
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
}
}
}
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:30,代码来源:Filesystem.php
示例16: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
list($xml, $encoding) = $this->parseFile($resource);
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
$catalogue = new MessageCatalogue($locale);
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
$attributes = $translation->attributes();
if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
continue;
}
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
$target = (string) $translation->target;
// If the xlf file has another encoding specified, try to convert it because
// simple_xml will always return utf-8 encoded values
if ('UTF-8' !== $encoding && !empty($encoding)) {
if (function_exists('mb_convert_encoding')) {
$target = mb_convert_encoding($target, $encoding, 'UTF-8');
} elseif (function_exists('iconv')) {
$target = iconv('UTF-8', $encoding, $target);
} else {
throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
}
}
$catalogue->set((string) $source, $target, $domain);
}
$catalogue->addResource(new FileResource($resource));
return $catalogue;
}
开发者ID:peintune,项目名称:Ternado,代码行数:39,代码来源:XliffFileLoader.php
示例17: load
/**
* {@inheritdoc}
*
* @api
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
try {
$dom = XmlUtils::loadFile($resource);
} catch (\InvalidArgumentException $e) {
throw new InvalidResourceException(sprintf('Unable to load "%s".', $resource), $e->getCode(), $e);
}
$internalErrors = libxml_use_internal_errors(true);
libxml_clear_errors();
$xpath = new \DOMXPath($dom);
$nodes = $xpath->evaluate('//TS/context/name[text()="' . $domain . '"]');
$catalogue = new MessageCatalogue($locale);
if ($nodes->length == 1) {
$translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message');
foreach ($translations as $translation) {
$translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue;
if (!empty($translationValue)) {
$catalogue->set((string) $translation->getElementsByTagName('source')->item(0)->nodeValue, $translationValue, $domain);
}
$translation = $translation->nextSibling;
}
$catalogue->addResource(new FileResource($resource));
}
libxml_use_internal_errors($internalErrors);
return $catalogue;
}
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:37,代码来源:QtFileLoader.php
示例18: copy
/**
* Copies a file.
*
* This method only copies the file if the origin file is newer than the target file.
*
* By default, if the target already exists, it is not overridden.
*
* @param string $originFile The original filename
* @param string $targetFile The target filename
* @param bool $override Whether to override an existing file or not
*
* @throws FileNotFoundException When originFile doesn't exist
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $override = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
}
$this->mkdir(dirname($targetFile));
if (!$override && is_file($targetFile) && null === parse_url($originFile, PHP_URL_HOST)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
} else {
$doCopy = true;
}
if ($doCopy) {
// https://bugs.php.net/bug.php?id=64634
if (false === ($source = @fopen($originFile, 'r'))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
}
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
if (false === ($target = @fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true)))))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
}
$bytesCopied = stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
}
if (stream_is_local($originFile) && $bytesCopied !== filesize($originFile)) {
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s %g bytes copied".', $originFile, $targetFile, $bytesCopied), 0, null, $originFile);
}
}
}
开发者ID:tccLaravel,项目名称:test4,代码行数:46,代码来源:Filesystem.php
示例19: generate
public function generate()
{
if (PHP_SAPI != 'cli') {
throw new \Exception("This script only can be used in CLI");
}
$config = $this->config->database;
system('/usr/bin/mysqldump -u ' . $config->username . ' -p' . $config->password . ' -r /tmp/phosphorum.sql ' . $config->dbname);
system('bzip2 /tmp/phosphorum.sql');
$sourcePath = '/tmp/phosphorum.sql.bz2';
if (!file_exists($sourcePath)) {
throw new \Exception("Backup could not be created");
}
list($accessToken, $host) = AuthInfo::loadFromJsonFile(APP_PATH . '/app/config/backup.auth');
$client = new Client($accessToken, "phosphorum", null, $host);
$dropboxPath = '/phosphorum.sql.bz2';
$pathError = Path::findErrorNonRoot($dropboxPath);
if ($pathError !== null) {
throw new \Exception("Invalid <dropbox-path>: {$pathError}");
}
try {
$client->delete($dropboxPath);
} catch (\Exception $e) {
// ...
}
$size = null;
if (\stream_is_local($sourcePath)) {
$size = \filesize($sourcePath);
}
$fp = fopen($sourcePath, "rb");
$client->uploadFile($dropboxPath, WriteMode::add(), $fp, $size);
fclose($fp);
@unlink($sourcePath);
}
开发者ID:sysatom,项目名称:workflow,代码行数:33,代码来源:Backup.php
示例20: load
/**
* {@inheritdoc}
*/
public function load($resource, $locale, $domain = 'messages')
{
if (!stream_is_local($resource)) {
throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
}
if (!file_exists($resource)) {
throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
}
if (!class_exists('Symfony\\Component\\Yaml\\Parser')) {
throw new \LogicException('Loading translations from the YAML format requires the Symfony Yaml component.');
}
if (null === $this->yamlParser) {
$this->yamlParser = new YamlParser();
}
try {
$messages = $this->yamlParser->parse(file_get_contents($resource));
} catch (ParseException $e) {
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
}
// empty file
if (null === $messages) {
$messages = array();
}
// not an array
if (!is_array($messages)) {
throw new InvalidResourceException(sprintf('The file "%s" must contain a YAML array.', $resource));
}
$catalogue = parent::load($messages, $locale, $domain);
if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
$catalogue->addResource(new FileResource($resource));
}
return $catalogue;
}
开发者ID:Dren-x,项目名称:mobit,代码行数:36,代码来源:YamlFileLoader.php
注:本文中的stream_is_local函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论