本文整理汇总了PHP中League\Flysystem\Filesystem类的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem类的具体用法?PHP Filesystem怎么用?PHP Filesystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readModuleMetadata
/**
* read all metadata from module file.
* @param type $module_system_name
* @return type
*/
public function readModuleMetadata($module_system_name)
{
$adapter = new Local(MODULE_PATH);
$filesystem = new Filesystem($adapter);
unset($adapter);
$output = [];
if ($filesystem->has($module_system_name . DS . $module_system_name . '.php')) {
$content = $filesystem->read($module_system_name . DS . $module_system_name . '.php');
preg_match_all('|([a-zA-Z0-9-_ ]+):(.*)$|mi', $content, $matches, PREG_PATTERN_ORDER);
unset($content);
if (isset($matches) && is_array($matches) && array_key_exists(1, $matches) && array_key_exists(2, $matches) && is_array($matches[1]) && is_array($matches[2])) {
foreach ($matches[1] as $key => $item) {
if (!is_array($item) && array_key_exists($key, $matches[2]) && !is_array($matches[2][$key])) {
$output[trim($item)] = trim($matches[2][$key]);
}
}
}
}
// validate available metadata
foreach ($this->available_metadata as $meta_name) {
if (!array_key_exists($meta_name, $output)) {
$output[$meta_name] = '';
}
}
unset($filesystem, $item, $key, $matches, $meta_name);
return $output;
}
示例2:
function it_should_execute_the_transfer_file_command(Filesystem $source, Filesystem $destination)
{
$source->readStream('source')->willReturn('data');
$destination->writeStream('destination', 'data')->shouldBeCalled();
$this->beConstructedWith($source, 'source', $destination, 'destination');
$this->execute();
}
示例3: testHas
public function testHas()
{
$mock = $this->getClient();
$mock->shouldReceive('propFind')->once()->andReturn(array('{DAV:}getcontentlength' => 20));
$adapter = new Filesystem(new Adapter($mock));
$this->assertTrue($adapter->has('something'));
}
示例4: readThemeMetadata
/**
* read all metadata from theme file.
* @param type $theme_system_name
* @return type
*/
public function readThemeMetadata($theme_system_name)
{
// get theme config
$Config = new \System\Libraries\Config();
$Config->load('theme');
$theme_dir = $Config->get('theme_dir', 'theme');
unset($Config);
$adapter = new Local($theme_dir);
$filesystem = new Filesystem($adapter);
unset($adapter, $theme_dir);
$output = [];
if ($filesystem->has($theme_system_name . DS . $theme_system_name . '.php')) {
$content = $filesystem->read($theme_system_name . DS . $theme_system_name . '.php');
preg_match_all('|([a-zA-Z0-9-_ ]+):(.*)$|mi', $content, $matches, PREG_PATTERN_ORDER);
unset($content);
if (isset($matches) && is_array($matches) && array_key_exists(1, $matches) && array_key_exists(2, $matches) && is_array($matches[1]) && is_array($matches[2])) {
foreach ($matches[1] as $key => $item) {
if (!is_array($item) && array_key_exists($key, $matches[2]) && !is_array($matches[2][$key])) {
$output[trim($item)] = trim($matches[2][$key]);
}
}
}
}
// validate available metadata
foreach ($this->available_metadata as $meta_name) {
if (!array_key_exists($meta_name, $output)) {
$output[$meta_name] = '';
}
}
unset($filesystem, $item, $key, $matches, $meta_name);
return $output;
}
示例5: system
public function system()
{
$adapter = new Local(__DIR__ . '/../../storage/');
$filesystem = new Filesystem($adapter);
$filesystem->createDir($this->getZipName());
return $filesystem;
}
示例6: getConfigFile
/**
* get the languages configuration file path.<br>
* the languages are store in db. use this class/method to generate them into a file and get the file path that were generated.
*
* @return string return languages configuration file path.
*/
public function getConfigFile()
{
$adapter = new Local($this->language_config_folder);
$filesystem = new Filesystem($adapter);
unset($adapter);
if ($filesystem->has($this->language_db_file)) {
$lang_file_ts = $filesystem->getTimestamp($this->language_db_file);
$day_old = (time() - $lang_file_ts) / 60 / 60 / 24;
if ($day_old > 30) {
// older than 30 days, rebuild languages.
$build_result = $this->buildConfigFile();
}
unset($day_old, $filesystem, $lang_file_ts);
if (isset($build_result) && $build_result !== true) {
\System\Libraries\Log::write('LanguagesDb', 'notice', 'Could not generate the languages from db from getConfigFile method.');
}
return $this->language_config_folder . DS . $this->language_db_file;
} elseif ($this->buildConfigFile() === true) {
// never build the language configuration file before, build it.
unset($filesystem);
return $this->language_config_folder . DS . $this->language_db_file;
} else {
return null;
}
}
示例7: assets
/**
* Return admin assets
* @param Response $response
* @param $asset
* @return Response|static
* @throws FileNotFoundException
*/
public function assets(Response $response, $asset)
{
$filesystem = new Filesystem(new Adapter(FS2ADMIN));
$expires = 8640000;
try {
// generate cache data
$timestamp_string = gmdate('D, d M Y H:i:s ', $filesystem->getTimestamp($asset)) . 'GMT';
$etag = md5($filesystem->read($asset));
$mime_type = $filesystem->getMimetype($asset);
if (0 !== strpos($mime_type, 'image')) {
$mime_type = 'text/css';
}
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? $_SERVER['HTTP_IF_NONE_MATCH'] : false;
if (($if_none_match && $if_none_match == "\"{$etag}\"" || !$if_none_match) && ($if_modified_since && $if_modified_since == $timestamp_string)) {
return $response->withStatus('304');
} else {
$response = $response->withHeader('Last-Modified', $timestamp_string)->withHeader('ETag', "\"{$etag}\"");
}
// send out content type, expire time and the file
$response->getBody()->write($filesystem->read($asset));
return $response->withHeader('Expires', gmdate('D, d M Y H:i:s ', time() + $expires) . 'GMT')->withHeader('Content-Type', $mime_type)->withHeader('Pragma', 'cache')->withHeader('Cache-Control', 'cache');
} catch (FileNotFoundException $e) {
throw $e;
}
}
示例8: ArrayCollection
function it_returns_flat_data_with_media($channelManager, Filesystem $filesystem, ChannelInterface $channel, LocaleInterface $locale, ProductInterface $product, FileInfoInterface $media1, FileInfoInterface $media2, ProductValueInterface $value1, ProductValueInterface $value2, AttributeInterface $attribute, ProductValueInterface $identifierValue, AttributeInterface $identifierAttribute, $serializer, $productBuilder)
{
$localeCodes = ['en_US'];
$channel->getLocales()->willReturn(new ArrayCollection([$locale]));
$channel->getLocaleCodes()->willReturn($localeCodes);
$productBuilder->addMissingProductValues($product, [$channel], [$locale])->shouldBeCalled();
$media1->getKey()->willReturn('key/to/media1.jpg');
$media2->getKey()->willReturn('key/to/media2.jpg');
$value1->getAttribute()->willReturn($attribute);
$value1->getMedia()->willReturn($media1);
$value2->getAttribute()->willReturn($attribute);
$value2->getMedia()->willReturn($media2);
$attribute->getAttributeType()->willReturn('pim_catalog_image');
$product->getValues()->willReturn([$value1, $value2, $identifierValue]);
$identifierValue->getAttribute()->willReturn($identifierAttribute);
$identifierAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
$product->getIdentifier()->willReturn($identifierValue);
$identifierValue->getData()->willReturn('data');
$filesystem->has('key/to/media1.jpg')->willReturn(true);
$filesystem->has('key/to/media2.jpg')->willReturn(true);
$serializer->normalize($media1, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value1])->willReturn(['normalized_media1']);
$serializer->normalize($media2, 'flat', ['field_name' => 'media', 'prepare_copy' => true, 'value' => $value2])->willReturn(['normalized_media2']);
$serializer->normalize($product, 'flat', ['scopeCode' => 'foobar', 'localeCodes' => $localeCodes, 'decimal_separator' => '.', 'date_format' => 'yyyy-MM-dd'])->willReturn(['normalized_product']);
$channelManager->getChannelByCode('foobar')->willReturn($channel);
$this->setChannel('foobar');
$this->process($product)->shouldReturn(['media' => [['normalized_media1'], ['normalized_media2']], 'product' => ['normalized_product']]);
}
示例9: generate
public function generate()
{
if (PHP_SAPI != 'cli') {
throw new \Exception("This script only can be used in CLI");
}
$config = $this->config->get('database');
system(sprintf('/usr/bin/mysqldump -u %s -h %s -p%s -r /tmp/phosphorum.sql %s', $config->username, $config->host, $config->password, $config->dbname));
system('bzip2 -f /tmp/phosphorum.sql');
$config = $this->config->get('dropbox');
if (!$config instanceof Config) {
throw new \Exception("Unable to retrieve Dropbox credentials. Please check Forum Configuration");
}
if (!$config->get('appSecret') || !$config->get('accessToken')) {
throw new \Exception("Please provide correct 'appSecret' and 'accessToken' config values");
}
$sourcePath = '/tmp/phosphorum.sql.bz2';
if (!file_exists($sourcePath)) {
throw new \Exception("Backup could not be created");
}
$client = new Client($config->get('accessToken'), $config->get('appSecret'));
$adapter = new DropboxAdapter($client, $config->get('prefix', null));
$filesystem = new Filesystem($adapter);
$dropboxPath = '/phosphorum.sql.bz2';
if ($filesystem->has($dropboxPath)) {
$filesystem->delete($dropboxPath);
}
$fp = fopen($sourcePath, "rb");
$filesystem->putStream($dropboxPath, $fp);
fclose($fp);
@unlink($sourcePath);
}
示例10: build
public function build()
{
\yii\base\Event::on(\denoll\filekit\Storage::className(), \denoll\filekit\Storage::EVENT_BEFORE_SAVE, function ($event) {
/** @var \denoll\filekit\Storage $storage */
$storage = $event->sender;
if (!$storage->getFilesystem()->has('.dirindex')) {
$storage->getFilesystem()->write('.dirindex', 1);
$dirindex = 1;
} else {
$dirindex = $storage->getFilesystem()->read('.dirindex');
}
if ($storage->maxDirFiles !== -1) {
if ($storage->getFilesystem()->has($dirindex)) {
$filesCount = count($storage->getFilesystem()->listContents($dirindex));
if ($filesCount > $storage->maxDirFiles) {
$dirindex++;
$storage->getFilesystem()->createDir($dirindex);
}
} else {
$storage->getFilesystem()->createDir($dirindex);
}
}
});
$client = new \Sabre\DAV\Client(['baseUri' => 'https://webdav.yandex.ru']);
$client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false);
$client->addCurlSetting(CURLOPT_HTTPHEADER, ['Authorization: OAuth TOKENTOKENTOKEN', 'Accept: */*', 'Host: webdav.yandex.ru']);
$adapter = new WebDAVAdapter($client, '/');
$flysystem = new Filesystem($adapter);
if (!$flysystem->has($this->pathPrefix)) {
$flysystem->createDir($this->pathPrefix);
}
$adapter->setPathPrefix($this->pathPrefix);
return $flysystem;
}
示例11: run
public function run()
{
$log = new Stream('php://stdout');
/** @var Config $config */
$config = Di::getDefault()->getShared('config');
$expireDate = new DateTime('now', new DateTimeZone('UTC'));
$expireDate->modify('+1 month');
$baseUrl = rtrim($config->get('site')->url, '/');
$content = <<<EOL
User-agent: *
Allow: /
Sitemap: {$baseUrl}/sitemap.xml
EOL;
$adapter = new Local(dirname(dirname(__FILE__)) . '/public');
$filesystem = new Filesystem($adapter);
if ($filesystem->has('robots.txt')) {
$result = $filesystem->update('robots.txt', $content);
} else {
$result = $filesystem->write('robots.txt', $content);
}
if ($result) {
$log->info('The robots.txt was successfully updated');
} else {
$log->error('Failed to update the robots.txt file');
}
}
示例12: handleField
protected function handleField(Request $request, $item, array $fields, $groupName, $fieldName)
{
$modelFolder = $this->slug . DIRECTORY_SEPARATOR;
$basePath = base_path(DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . config('anavel-crud.uploads_path'));
$modelPath = $basePath . $modelFolder;
$skip = null;
$requestValue = null;
if (!empty($fields["{$fieldName}__delete"])) {
//We never want to save this field, it doesn't exist in the DB
$skip = "{$fieldName}__delete";
//If user wants to delete the existing file
if (!empty($request->input("{$groupName}.{$fieldName}__delete"))) {
$adapter = new Local($basePath);
$filesystem = new Filesystem($adapter);
if ($filesystem->has($item->{$fieldName})) {
$filesystem->delete($item->{$fieldName});
}
$item->setAttribute($fieldName, null);
return ['skip' => $skip];
}
}
if ($request->hasFile($groupName . '.' . $fieldName)) {
$fileName = uniqid() . '.' . $request->file($groupName . '.' . $fieldName)->getClientOriginalExtension();
$request->file($groupName . '.' . $fieldName)->move($modelPath, $fileName);
$requestValue = $modelFolder . $fileName;
} elseif (!empty($request->file($groupName . '.' . $fieldName)) && !$request->file($groupName . '.' . $fieldName)->isValid()) {
throw new \Exception($request->file($groupName . '.' . $fieldName)->getErrorMessage());
}
return ['requestValue' => $requestValue, 'skip' => $skip];
}
示例13: getFilesystem
/**
* @return Filesystem
*/
public function getFilesystem()
{
if ($this->filesystem == null) {
$this->filesystem = new Filesystem(new Local($this->path));
$this->filesystem->addPlugin(new ListFiles());
}
return $this->filesystem;
}
示例14: saveFile
/**
* {@inheritdoc}
*/
public function saveFile(UploadedFile $uploadedFile, $fileName)
{
$stream = fopen($uploadedFile->getRealPath(), 'r+');
$result = $this->filesystem->writeStream($this->getMediaBasePath() . '/' . $fileName . '.' . $uploadedFile->guessClientExtension(), $stream);
fclose($stream);
return $result;
}
示例15: testDeleteMockResourceExistsSizes
public function testDeleteMockResourceExistsSizes()
{
$resourceDO = $this->getResourceDOMock();
$this->filesystem->put($resourceDO->getFilePath(), '');
$resourceDOSize10x11 = $this->getResourceDOMock();
$resourceDOSize10x11->setWidth(10);
$resourceDOSize10x11->setHeight(11);
$this->filesystem->put($resourceDOSize10x11->getFilePath(), '');
$resourceDOSize20x21 = $this->getResourceDOMock();
$resourceDOSize20x21->setWidth(20);
$resourceDOSize20x21->setHeight(21);
$this->filesystem->put($resourceDOSize20x21->getFilePath(), '');
$yetAnotherWrongDO = clone $resourceDO;
$yetAnotherWrongDO->setWidth(998);
$yetAnotherWrongDO->setHeight(999);
$this->wrongFiles->create($resourceDO, 'Wrong1');
$this->wrongFiles->create($resourceDOSize10x11, 'Wrong2');
$this->wrongFiles->create($resourceDOSize20x21, 'Wrong3');
$this->wrongFiles->create($yetAnotherWrongDO, 'Wrong4');
$modelFiles = $this->filesystem->listContents('/', true);
// Make the expected model looks like filesystem after the command execution
// With this model we will be sure that other files have not been deleted
unset($modelFiles[56], $modelFiles[57]);
$modelFiles[55] = ['type' => 'dir', 'path' => 'testBase/png/def/def/0/c9f/20x21', 'dirname' => 'testBase/png/def/def/0/c9f', 'basename' => '20x21', 'filename' => '20x21'];
$command = $this->getCommand($resourceDO);
$result = $command();
$this->assertTrue($result);
$this->assertFalse($this->filesystem->has($resourceDOSize10x11->getFilePath()));
$this->assertFalse($this->filesystem->has($resourceDOSize20x21->getFilePath()));
$result = $this->filesystem->listContents('/', true);
$this->assertEquals($modelFiles, $result);
}