本文整理汇总了PHP中Cake\Filesystem\File::close方法的典型用法代码示例。如果您正苦于以下问题:PHP File::close方法的具体用法?PHP File::close怎么用?PHP File::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Filesystem\File
的用法示例。
在下文中一共展示了File::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Cria um plugin de teste e o carrega para conseguir rodar os testes.
*/
public function setUp()
{
parent::setUp();
$testData = ['full_path' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS, 'config_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'config' . DS, 'css_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'css' . DS, 'js_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'js' . DS, 'img_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'img' . DS, 'packages_folder' => ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest' . DS . 'webroot' . DS . '_assets' . DS . 'packages' . DS];
$pluginFolder = new Folder($testData['full_path'], self::CREATE_FOLDER_IF_NOT_EXISTS, self::PLUGIN_FOLDER_PERMISSIONS);
$pluginFolder->create($testData['config_folder']);
$pluginFolder->create($testData['css_folder']);
$pluginFolder->create($testData['js_folder']);
$pluginFolder->create($testData['img_folder']);
$pluginFolder->create($testData['packages_folder'] . 'sample_package');
$defaultSettingsFile = new File($testData['config_folder'] . 'default_settings.php', true);
$defaultSettingsFile->write("<?php \n\t\t\treturn [\n\t\t\t\t'MyApplication.Modules.ThemeInstallerTest.Settings' => \n\t\t\t\t\t['Default' => true]\n\t\t\t\t]; \n\t\t?>");
$defaultSettingsFile->close();
$file = new File($testData['css_folder'] . 'sample.css', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['js_folder'] . 'sample.js', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.css', true);
$file->write('#id { }');
$file->close();
$file = new File($testData['packages_folder'] . 'sample_package' . DS . 'sample.js', true);
$file->write('#id { }');
$file->close();
$bootstrapFile = new File($testData['config_folder'] . 'bootstrap.php', true);
$bootstrapFile->close();
}
示例2: afterDelete
public function afterDelete(Event $event, Banner $banner, \ArrayObject $options)
{
$bannerFile = new File(WWW_ROOT . 'img' . DS . $banner->image);
$bannerFile->delete();
$bannerFile->close();
Cache::clear(false, 'banners_manager_cache');
}
示例3: afterDelete
public function afterDelete(Event $event, PhotoThumbnail $photo, \ArrayObject $config)
{
if (!empty($photo->path)) {
$file = new File(WWW_ROOT . 'img' . DS . $photo->path);
$file->delete();
$file->close();
}
}
示例4: main
public function main()
{
$tick_names_and_values = array();
$this->authentication();
$http = new Client();
$this->loadModel('Stocks');
$this->loadModel('Devices');
$token_file = new File("/home/demo/token/token.txt");
$token = $token_file->read();
$token_file->close();
$MyAuthObject = new OAuthObject(array("token_type" => "Bearer", "access_token" => $token));
$OptionsToast = new WNSNotificationOptions();
$OptionsToast->SetAuthorization($MyAuthObject);
$OptionsToast->SetX_WNS_REQUESTFORSTATUS(X_WNS_RequestForStatus::Request);
$NotifierToast = new WindowsNotificationClass($OptionsToast);
$OptionsTile = new WNSNotificationOptions();
$OptionsTile->SetAuthorization($MyAuthObject);
$OptionsTile->SetX_WNS_REQUESTFORSTATUS(X_WNS_RequestForStatus::Request);
//NOTE: Set the Tile type
$OptionsTile->SetX_WNS_TYPE(X_WNS_Type::Tile);
$NotifierTile = new WindowsNotificationClass($OptionsTile);
$allStocks = $this->Stocks->find('all')->toArray();
//$allStocks = $this->Stocks->find('all')->group(['Stocks.device_id'])->toArray();
//$allStocks = $this->Stocks->Devices->find()->group(['Devices.id'])->toArray();
Debugger::dump('allStocks: ');
Debugger::dump($allStocks);
$allStocksByDeviceId = array();
for ($i = 0; $i < sizeof($allStocks); $i++) {
$actualDeviceId = $allStocks[$i]['device_id'];
$added = false;
for ($a = 0; $a < sizeof($allStocksByDeviceId); $a++) {
if ($allStocksByDeviceId[$a]['device_id'] == $actualDeviceId) {
$allStocksByDeviceId[$a]['stocks'][] = $allStocks[$i];
$added = true;
}
}
if (!$added) {
$allStocksByDeviceId[] = ['device_id' => $actualDeviceId, 'stocks' => [$allStocks[$i]]];
}
}
Debugger::dump('allStocksByDeviceId: ');
Debugger::dump($allStocksByDeviceId);
$someStocks = $this->Stocks->find()->distinct(['tick_name'])->toArray();
for ($i = 0; $i < sizeof($someStocks); $i++) {
$response = $http->get('http://download.finance.yahoo.com/d/quotes?f=sl1d1t1v&s=' . $someStocks[$i]['tick_name']);
$tick_name = explode(",", $response->body())[0];
$tick_names_and_values[] = [str_replace("\"", "", $tick_name), explode(",", $response->body())[1]];
}
Debugger::dump('tick_names_and_values: ');
Debugger::dump($tick_names_and_values);
$this->sendAllStocksNotificationsInTileNotifications($NotifierTile, $tick_names_and_values, $allStocksByDeviceId);
$this->checkMinMaxValuesAndSendToastNotifications($NotifierToast, $tick_names_and_values);
//$stuff = implode(",", $stuff);
//$now = Time::now();
//$this->createFile('/home/demo/files_created_each_minute/'.$now->i18nFormat('yyyy-MM-dd HH:mm:ss').'.txt', $stuff);
}
示例5: uploadToControllerFolderAndIdFolder
public function uploadToControllerFolderAndIdFolder($file, $controller, $model, $id)
{
$filefolder = '../webroot' . DS . 'files';
$tmppath = AMUploadBehavior::checkIfSubfolderExistsAndCreateIfFalseAndReturnPath($filefolder, $controller);
$path = AMUploadBehavior::checkIfSubfolderExistsAndCreateIfFalseAndReturnPath($tmppath, $id);
$filename = $file['name'];
$tmpfile = new File($file['tmp_name']);
$fullpath = $path . DS . $filename;
$tmpfile->copy($fullpath);
$tmpfile->close();
return $fullpath;
}
示例6: testInstalledPluginSettingsFileWillNotBeOverrridenOnLoad
public function testInstalledPluginSettingsFileWillNotBeOverrridenOnLoad()
{
$starter = new PluginStarter();
$starter->load('PluginInstallerTest');
$installedSettingsFile = new File(ROOT . DS . 'config' . DS . 'Plugins' . DS . 'PluginInstallerTest' . DS . 'settings.php');
$defaultSettingsFile = new File(ROOT . DS . 'plugins' . DS . 'PluginInstallerTest' . DS . 'config' . DS . 'default_settings.php');
$installedSettingsFile->write("<?php \n\t\t\treturn [\n\t\t\t\t'MyApplication.Modules.PluginInstallerTest.Settings' => \n\t\t\t\t\t['Default' => false]\n\t\t\t\t]; \n\t\t?>");
$installedSettingsFile->close();
$starter->load('PluginInstallerTest');
$installedSettingsFile = new File(ROOT . DS . 'config' . DS . 'Plugins' . DS . 'PluginInstallerTest' . DS . 'settings.php');
$this->assertEquals(strcmp($installedSettingsFile->md5(), $defaultSettingsFile->md5()) === 0, false);
$installedSettingsFile->close();
$defaultSettingsFile->close();
}
示例7: install
/**
* Faz uma instalação básica do plugin.
* A instalação consiste em criar o arquivo de configurações do plugin no diretório apropriado.
* Este método é chamado pelo método PluginStarter::load() quando necessário.
*
* @param string $pluginName O nome do plugin a ser instalado.
* @return void
*/
public function install($pluginName)
{
$settingsFileFolder = $this->pluginInstallationFolder . $pluginName . DS;
if (Plugin::loaded($pluginName)) {
$defaultFile = Plugin::path($pluginName) . 'config' . DS . 'default_settings.php';
$folderHandler = new Folder();
if (!$folderHandler->cd($settingsFileFolder)) {
$folderHandler->create($settingsFileFolder);
}
$fileHandler = new File($defaultFile);
$fileHandler->copy($settingsFileFolder . 'settings.php');
$fileHandler->close();
}
}
示例8: add
public function add()
{
$broch = $this->request->data;
if (!empty($this->request->data)) {
//hacking in blank default values since there is no inputs for the following
$this->request->data['location'] = '';
$this->request->data['restrict_access'] = 0;
$this->request->data['max_restricted_qty'] = 0;
if ($this->request->data['image']['tmp_name'] != '') {
$file = new File($this->request->data['image']['tmp_name']);
$filename = $this->request->data['image']['name'];
$data = $file->read();
$file->close();
$file = new File(WWW_ROOT . '/img/brochures/' . $filename, true);
$file->write($data);
$file->close();
unset($this->request->data['image']);
$image = ['filename' => $filename, 'caption' => $filename];
$image = $this->Brochures->Images->newEntity($image);
if ($image = $this->Brochures->Images->save($image)) {
$this->Flash->set(__('The brochure image could not be saved. Please, try again.'));
}
$this->request->data['image_id'] = '';
} else {
$image = '';
}
try {
$brochure = $this->Brochures->newEntity($this->request->data, ['accessibleFields' => ['sku' => true], 'contain' => 'Images']);
if ($image) {
$brochure->image = $image;
}
if ($brochure = $this->Brochures->save($brochure)) {
$this->Flash->set(__('The brochure has been saved'));
// $this->_notifyWarehouse($broch);
$this->redirect(array('action' => 'index'));
} else {
$this->Flash->set(__('The brochure could not be saved. Please, try again.'));
}
} catch (Exception $e) {
$this->Flash->set(__('The brochure could not be saved. Please, try again.'));
}
}
$images = $this->Brochures->Images->find('list', array('fields' => array('id', 'caption')));
//$images['0'] = "None";
$this->LoadModel('Suppliers');
$suppliers = $this->Suppliers->find('list', ['fields' => array('company', 'id'), 'order' => ['Suppliers.company']]);
//$suppliers['0'] = "None";
$this->set(compact('images', 'suppliers'));
}
示例9: testShrinkJs
/**
* Test that js files are properly processed
*
* @return void
*/
public function testShrinkJs()
{
$ret = $this->Shrink->build(['base.js', 'base.coffee'], 'js');
// verify the result has the proper keys
$this->assertArrayHasKey('path', $ret);
$this->assertArrayHasKey('webPath', $ret);
// verify we were returned a file
$this->assertFileExists($ret['path']);
// verify the contents
$cacheFile = new File($ret['path']);
$result = $cacheFile->read();
$cacheFile->delete();
$cacheFile->close();
$expectedfile = new File(WWW_ROOT . 'js/base.shrink.js');
$expect = $expectedfile->read();
$expectedfile->close();
$this->assertEquals($expect, $result);
}
示例10: testShrinkJs
/**
* test that js files are properly queued and processed
*
* @return void
*/
public function testShrinkJs()
{
$this->Shrink->js(['base.js', 'base.coffee']);
$tag = $this->Shrink->fetch('js');
// did it create a link tag?
$this->assertRegExp('/^\\<script\\s/', $tag);
// grab the url if it has one (it always should)
preg_match('/src="(?P<url>.+?)"/', $tag, $matches);
$this->assertArrayHasKey('url', $matches);
// verify the file exists
$url = $matches['url'];
$file = new File(WWW_ROOT . $url);
$this->assertTrue($file->exists());
// verify the contents
$result = $file->read();
$file->delete();
$file->close();
$expectedfile = new File(WWW_ROOT . 'js/base.shrink.js');
$expect = $expectedfile->read();
$expectedfile->close();
$this->assertEquals($expect, $result);
}
示例11: main
/**
* main method
*
* @param string $tempDir an other directory to clear of all folders and files, if desired
* @return void
*/
public function main($tempDir = null)
{
if (empty($tempDir)) {
$tempDir = Configure::read('Attachments.tmpUploadsPath');
}
if (!Folder::isAbsolute($tempDir)) {
$this->out('The path must be absolute, "' . $tempDir . '" given.');
exit;
}
$Folder = new Folder();
if ($Folder->cd($tempDir) === false) {
$this->out('Path "' . $tempDir . '" doesn\'t seem to exist.');
exit;
}
$dir = new Folder($tempDir);
$folders = $dir->read();
$files = $dir->findRecursive();
$deletedFiles = 0;
$deletedFolders = 0;
$this->out('Found ' . count($folders[0]) . ' folders and ' . count($files) . ' files');
foreach ($files as $filePath) {
$file = new File($filePath);
// only delete if last change is longer than 24 hours ago
if ($file->lastChange() < time() - 24 * 60 * 60 && $file->delete()) {
$deletedFiles++;
}
$file->close();
}
foreach ($folders[0] as $folderName) {
$folder = new Folder($dir->pwd() . $folderName);
// only delete if folder is empty
if ($folder->dirsize() === 0 && $folder->delete()) {
$deletedFolders++;
}
}
$this->out('Deleted ' . $deletedFolders . ' folders and ' . $deletedFiles . ' files.');
}
示例12: cmdInfo
public function cmdInfo()
{
$cmdline_fh = new File('/proc/cmdline');
$cmdline_raw = $cmdline_fh->read();
$cmdline_fh->close();
$lines = explode(" ", $cmdline_raw);
$cmdline = [];
for ($i = 0; $i < sizeof($lines); $i++) {
if (trim($lines[$i]) != "") {
$info = explode("=", $lines[$i]);
if (sizeof($info) < 2) {
continue;
}
if (!strpos($info[0], '.')) {
$key = trim($info[0]);
} else {
$key = substr(strstr(trim($info[0]), '.'), 1);
}
$val = trim($info[1]);
$cmdline[$key] = $val;
}
}
return $cmdline;
}
示例13: testCompilerTypescript
/**
* test that compiler "ts" works
*
* @return void
*/
public function testCompilerTypescript()
{
$compiler = ShrinkType::getCompiler('ts', []);
// verify the instance
$this->assertInstanceOf('\\Shrink\\Lib\\ShrinkCompiler\\ShrinkCompilerInterface', $compiler);
if ($compiler->isAvailable()) {
// get the result
$file = new File(WWW_ROOT . 'js/base.ts');
$result = $compiler->compile($file);
$file->close();
// get the expected result
$jsfile = new File(WWW_ROOT . 'js/base.ts.js');
$expect = $jsfile->read();
$jsfile->close();
$this->assertEquals($expect, $result, 'Compiled Typescript does not match. Ensure Typescript script command line utility is available. npm install -g typescript');
} else {
echo "\nSkipping Typescript tests, no typescript available: npm install -g typescript\n";
}
}
示例14: _getFromUrl
/**
* Prepares install from remote URL.
*
* @return bool True on success
*/
protected function _getFromUrl()
{
try {
$http = new Client(['redirect' => 3]);
// follow up to 3 redirections
$response = $http->get($this->params['source'], [], ['headers' => ['X-Requested-With' => 'XMLHttpRequest']]);
} catch (\Exception $ex) {
$response = false;
$this->err(__d('installer', 'Could not download the package. Details: {0}', $ex->getMessage()));
return false;
}
if ($response && $response->isOk()) {
$this->params['source'] = TMP . substr(md5($this->params['source']), 24) . '.zip';
$file = new File($this->params['source']);
$responseBody = $response->body();
if (is_readable($file->pwd())) {
$file->delete();
}
if (!empty($responseBody) && $file->create() && $file->write($responseBody, 'w+', true)) {
$file->close();
return $this->_getFromFile();
$this->err(__d('installer', 'Unable to extract the package.'));
return false;
}
$this->err(__d('installer', 'Unable to download the file, check write permission on "{0}" directory.', [TMP]));
return false;
}
$this->err(__d('installer', 'Could not download the package, no .ZIP file was found at the given URL.'));
return false;
}
示例15: save
//.........这里部分代码省略.........
$width = $resizedWidth;
$height = $this->thumbHeight;
$src_x = intval(($resizedWidth - $this->thumbWidth) / 2);
} else {
$width = $this->thumbWidth;
$height = $resizedHeight;
$src_y = intval(($resizedHeight - $this->thumbHeight) / 2);
}
$src = imagecreatetruecolor($width, $height);
// save transparent colors
if ($this->imgFormat == 'png') {
imagecolortransparent($src, imagecolorallocate($src, 0, 0, 0));
imagealphablending($src, false);
imagesavealpha($src, true);
}
// get and reallocate transparency-color for gif
if ($this->imgFormat == 'gif') {
imagealphablending($src, false);
$transindex = imagecolortransparent($this->imgSource) <= imagecolorstotal($src) ? imagecolortransparent($this->imgSource) : imagecolorstotal($src);
if ($transindex >= 0) {
$transcol = imagecolorsforindex($this->imgSource, $transindex);
$transindex = imagecolorallocatealpha($src, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
imagefill($src, 0, 0, $transindex);
}
}
if (function_exists('imagecopyresampled')) {
@imagecopyresampled($src, $this->imgSource, 0, 0, 0, 0, $width, $height, $this->imgWidth, $this->imgHeight);
} else {
@imagecopyresized($src, $this->imgSource, 0, 0, 0, 0, $width, $height, $this->imgWidth, $this->imgHeight);
}
// restore transparency for gif
if ($this->imgFormat == 'gif') {
if ($transindex >= 0) {
imagecolortransparent($src, $transindex);
for ($y = 0; $y < imagesy($src); ++$y) {
for ($x = 0; $x < imagesx($src); ++$x) {
if ((imagecolorat($src, $x, $y) >> 24 & 0x7f) >= 100) {
imagesetpixel($src, $x, $y, $transindex);
}
}
}
}
}
}
// create thumbnail image
$thumbnail = imagecreatetruecolor($this->thumbWidth, $this->thumbHeight);
// save transparent colors for png
if ($this->imgFormat == 'png') {
imagecolortransparent($thumbnail, imagecolorallocate($src, 0, 0, 0));
imagealphablending($thumbnail, false);
imagesavealpha($thumbnail, true);
}
// get and reallocate transparency-color for gif
if ($this->imgFormat == 'gif') {
imagealphablending($thumbnail, false);
$transindex = imagecolortransparent($src);
if ($transindex >= 0) {
$transcol = imagecolorsforindex($src, $transindex);
$transindex = imagecolorallocatealpha($thumbnail, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
imagefill($thumbnail, 0, 0, $transindex);
}
}
@imagecopy($thumbnail, $src, 0, 0, $src_x, $src_y, $this->thumbWidth, $this->thumbHeight);
// restore transparency for gif
if ($this->imgFormat == 'gif') {
if ($transindex >= 0) {
imagecolortransparent($thumbnail, $transindex);
for ($y = 0; $y < imagesy($thumbnail); ++$y) {
for ($x = 0; $x < imagesx($thumbnail); ++$x) {
if ((imagecolorat($thumbnail, $x, $y) >> 24 & 0x7f) >= 100) {
imagesetpixel($thumbnail, $x, $y, $transindex);
}
}
}
}
}
// save thumbnail to file
ob_start();
switch ($this->imgFormat) {
case 'gif':
$return = imagegif($thumbnail);
break;
case 'jpeg':
$return = imagejpeg($thumbnail, null, $this->thumbQuality);
break;
case 'png':
$return = imagepng($thumbnail);
break;
}
$output = ob_get_contents();
ob_end_clean();
$File = new File($file);
$File->write($output);
$File->close();
// free memory resources
imagedestroy($thumbnail);
imagedestroy($src);
}
return $return;
}