本文整理汇总了PHP中Piwik\Filesystem类的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem类的具体用法?PHP Filesystem怎么用?PHP Filesystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteIfLastModifiedBefore14August2014
private static function deleteIfLastModifiedBefore14August2014($path)
{
$modifiedTime = filemtime($path);
if ($modifiedTime && $modifiedTime < 1408000000) {
Filesystem::deleteFileIfExists($path);
}
}
示例2: removeGoneFiles
public function removeGoneFiles($source, $target)
{
Filesystem::unlinkTargetFilesNotPresentInSource($source . '/core', $target . '/core');
foreach ($this->getPluginsFromDirectoy($source) as $pluginDir) {
Filesystem::unlinkTargetFilesNotPresentInSource($source . $pluginDir, $target . $pluginDir);
}
}
示例3: getPluginName
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return array
* @throws \RunTimeException
*/
protected function getPluginName(InputInterface $input, OutputInterface $output)
{
$self = $this;
$validate = function ($pluginName) use($self) {
if (empty($pluginName)) {
throw new \RunTimeException('You have to enter a plugin name');
}
if (!Filesystem::isValidFilename($pluginName)) {
throw new \RunTimeException(sprintf('The plugin name %s is not valid', $pluginName));
}
$pluginPath = $self->getPluginPath($pluginName);
if (file_exists($pluginPath)) {
throw new \RunTimeException('A plugin with this name already exists');
}
return $pluginName;
};
$pluginName = $input->getOption('name');
if (empty($pluginName)) {
$dialog = $this->getHelperSet()->get('dialog');
$pluginName = $dialog->askAndValidate($output, 'Enter a plugin name: ', $validate);
} else {
$validate($pluginName);
}
$pluginName = ucfirst($pluginName);
return $pluginName;
}
示例4: dispatch
public function dispatch()
{
$module = Common::getRequestVar('module', '', 'string');
$action = Common::getRequestVar('action', '', 'string');
if ($module == 'CoreUpdater' || $module == 'Proxy' || $module == 'Installation' || $module == 'LanguagesManager' && $action == 'saveLanguage') {
return;
}
$updater = new PiwikCoreUpdater();
$updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION));
if (!empty($updates)) {
Filesystem::deleteAllCacheOnUpdate();
}
if ($updater->getComponentUpdates() !== null) {
if (FrontController::shouldRethrowException()) {
throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n");
} elseif ($module === 'API') {
$outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST));
$response = new ResponseBuilder($outputFormat);
$e = new Exception('Database Upgrade Required. Your Piwik database is out-of-date, and must be upgraded before you can continue.');
echo $response->getResponseException($e);
Common::sendResponseCode(503);
exit;
} else {
Piwik::redirectToModule('CoreUpdater');
}
}
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$piwikLanguages = \Piwik\Plugins\LanguagesManager\API::getInstance()->getAvailableLanguages();
$aliasesUrl = 'https://raw.githubusercontent.com/unicode-cldr/cldr-core/master/supplemental/aliases.json';
$aliasesData = Http::fetchRemoteFile($aliasesUrl);
$aliasesData = json_decode($aliasesData, true);
$aliasesData = $aliasesData['supplemental']['metadata']['alias']['languageAlias'];
$writePath = Filesystem::getPathToPiwikRoot() . '/plugins/Intl/lang/%s.json';
foreach ($piwikLanguages as $langCode) {
if ($langCode == 'dev') {
continue;
}
$requestLangCode = $transformedLangCode = $this->transformLangCode($langCode);
if (array_key_exists($requestLangCode, $aliasesData)) {
$requestLangCode = $aliasesData[$requestLangCode]['_replacement'];
}
// fix some locales
$localFixes = array('pt' => 'pt-PT', 'pt-br' => 'pt', 'zh-cn' => 'zh-Hans', 'zh-tw' => 'zh-Hant');
if (array_key_exists($langCode, $localFixes)) {
$requestLangCode = $localFixes[$langCode];
}
setlocale(LC_ALL, $langCode);
$translations = array();
$this->fetchLanguageData($output, $transformedLangCode, $requestLangCode, $translations);
$this->fetchTerritoryData($output, $transformedLangCode, $requestLangCode, $translations);
$this->fetchCalendarData($output, $transformedLangCode, $requestLangCode, $translations);
$this->fetchLayoutDirection($output, $transformedLangCode, $requestLangCode, $translations);
$this->fetchUnitData($output, $transformedLangCode, $requestLangCode, $translations);
$this->fetchNumberFormattingData($output, $transformedLangCode, $requestLangCode, $translations);
ksort($translations['Intl']);
file_put_contents(sprintf($writePath, $langCode), json_encode($translations, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$commandName = $input->getFirstArgument();
$enable = false !== strpos($commandName, 'enable');
$full = $input->getOption('full');
$config = Config::getInstance();
$development = $config->Development;
if ($enable) {
$development['enabled'] = 1;
if ($full) {
$development['disable_merged_assets'] = 1;
}
$message = 'Development mode enabled';
} else {
$development['enabled'] = 0;
if ($full) {
$development['disable_merged_assets'] = 0;
}
$message = 'Development mode disabled';
}
$config->Development = $development;
$config->forceSave();
Filesystem::deleteAllCacheOnUpdate();
$this->writeSuccessMessage($output, array($message));
}
示例7: update
static function update()
{
$errors = array();
try {
$checker = new DoNotTrackHeaderChecker();
// enable DoNotTrack check in PrivacyManager if DoNotTrack plugin was enabled
if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated('DoNotTrack')) {
$checker->activate();
}
// enable IP anonymization if AnonymizeIP plugin was enabled
if (\Piwik\Plugin\Manager::getInstance()->isPluginActivated('AnonymizeIP')) {
IPAnonymizer::activate();
}
} catch (\Exception $ex) {
// pass
}
// disable & delete old plugins
$oldPlugins = array('DoNotTrack', 'AnonymizeIP');
foreach ($oldPlugins as $plugin) {
try {
\Piwik\Plugin\Manager::getInstance()->deactivatePlugin($plugin);
} catch (\Exception $e) {
}
$dir = PIWIK_INCLUDE_PATH . "/plugins/{$plugin}";
if (file_exists($dir)) {
Filesystem::unlinkRecursive($dir, true);
}
if (file_exists($dir)) {
$errors[] = "Please delete this directory manually (eg. using your FTP software): {$dir} \n";
}
}
if (!empty($errors)) {
throw new \Exception("Warnings during the update: <br>" . implode("<br>", $errors));
}
}
示例8: update
static function update()
{
Updater::updateDatabase(__FILE__, self::getSql());
$obsoleteDirectories = array('/plugins/AdminHome', '/plugins/Home', '/plugins/PluginsAdmin');
foreach ($obsoleteDirectories as $dir) {
if (file_exists(PIWIK_INCLUDE_PATH . $dir)) {
Filesystem::unlinkRecursive(PIWIK_INCLUDE_PATH . $dir, true);
}
}
}
示例9: doUpdate
public function doUpdate(Updater $updater)
{
$updater->executeMigrationQueries(__FILE__, $this->getMigrationQueries($updater));
$obsoleteDirectories = array('/plugins/AdminHome', '/plugins/Home', '/plugins/PluginsAdmin');
foreach ($obsoleteDirectories as $dir) {
if (file_exists(PIWIK_INCLUDE_PATH . $dir)) {
Filesystem::unlinkRecursive(PIWIK_INCLUDE_PATH . $dir, true);
}
}
}
示例10: loadCoreTranslationFile
private static function loadCoreTranslationFile($language)
{
$path = PIWIK_INCLUDE_PATH . '/lang/' . $language . '.json';
if (!Filesystem::isValidFilename($language) || !is_readable($path)) {
throw new Exception(Piwik::translate('General_ExceptionLanguageFileNotFound', array($language)));
}
$data = file_get_contents($path);
$translations = json_decode($data, true);
self::mergeTranslationArray($translations);
self::setLocale();
self::$loadedLanguage = $language;
}
示例11: delete
public function delete()
{
if ($this->exists()) {
try {
Filesystem::remove($this->getAbsoluteLocation());
} catch (Exception $e) {
throw new Exception("Unable to delete merged file : " . $this->getAbsoluteLocation() . ". Please delete the file and refresh");
}
// try to remove compressed version of the merged file.
Filesystem::remove($this->getAbsoluteLocation() . ".deflate", true);
Filesystem::remove($this->getAbsoluteLocation() . ".gz", true);
}
}
示例12: sendHttpRequest
/**
* Sends an HTTP request using best available transport method.
*
* @param string $aUrl The target URL.
* @param int $timeout The number of seconds to wait before aborting the HTTP request.
* @param string|null $userAgent The user agent to use.
* @param string|null $destinationPath If supplied, the HTTP response will be saved to the file specified by
* this path.
* @param int|null $followDepth Internal redirect count. Should always pass `null` for this parameter.
* @param bool $acceptLanguage The value to use for the `'Accept-Language'` HTTP request header.
* @param array|bool $byteRange For `Range:` header. Should be two element array of bytes, eg, `array(0, 1024)`
* Doesn't work w/ `fopen` transport method.
* @param bool $getExtendedInfo If true returns the status code, headers & response, if false just the response.
* @param string $httpMethod The HTTP method to use. Defaults to `'GET'`.
* @throws Exception if the response cannot be saved to `$destinationPath`, if the HTTP response cannot be sent,
* if there are more than 5 redirects or if the request times out.
* @return bool|string If `$destinationPath` is not specified the HTTP response is returned on success. `false`
* is returned on failure.
* If `$getExtendedInfo` is `true` and `$destinationPath` is not specified an array with
* the following information is returned on success:
*
* - **status**: the HTTP status code
* - **headers**: the HTTP headers
* - **data**: the HTTP response data
*
* `false` is still returned on failure.
* @api
*/
public static function sendHttpRequest($aUrl, $timeout, $userAgent = null, $destinationPath = null, $followDepth = 0, $acceptLanguage = false, $byteRange = false, $getExtendedInfo = false, $httpMethod = 'GET')
{
// create output file
$file = null;
if ($destinationPath) {
// Ensure destination directory exists
Filesystem::mkdir(dirname($destinationPath));
if (($file = @fopen($destinationPath, 'wb')) === false || !is_resource($file)) {
throw new Exception('Error while creating the file: ' . $destinationPath);
}
}
$acceptLanguage = $acceptLanguage ? 'Accept-Language: ' . $acceptLanguage : '';
return self::sendHttpRequestBy(self::getTransportMethod(), $aUrl, $timeout, $userAgent, $destinationPath, $file, $followDepth, $acceptLanguage, $acceptInvalidSslCertificate = false, $byteRange, $getExtendedInfo, $httpMethod);
}
示例13: execute
public function execute()
{
$label = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsWritable');
$file = new File(PIWIK_DOCUMENT_ROOT . '/piwik.js');
if ($file->hasWriteAccess()) {
return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK, ''));
}
$comment = $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsNotWritable');
if (!SettingsServer::isWindows()) {
$realpath = Filesystem::realpath(PIWIK_INCLUDE_PATH . '/piwik.js');
$command = "<br/><code> chmod +w {$realpath}<br/> chown " . Filechecks::getUserAndGroup() . " " . $realpath . "</code><br />";
$comment .= $this->translator->translate('CustomPiwikJs_DiagnosticPiwikJsMakeWritable', $command);
}
return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
}
示例14: execute
public function execute()
{
$label = $this->translator->translate('Installation_Filesystem');
if (!Filesystem::checkIfFileSystemIsNFS()) {
return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK));
}
$isPiwikInstalling = !Config::getInstance()->existsLocalConfig();
if ($isPiwikInstalling) {
$help = 'Installation_NfsFilesystemWarningSuffixInstall';
} else {
$help = 'Installation_NfsFilesystemWarningSuffixAdmin';
}
$comment = sprintf('%s<br />%s', $this->translator->translate('Installation_NfsFilesystemWarning'), $this->translator->translate($help));
return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
}
示例15: dispatch
public function dispatch()
{
$module = Common::getRequestVar('module', '', 'string');
$action = Common::getRequestVar('action', '', 'string');
$updater = new PiwikCoreUpdater();
$updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION));
if (!empty($updates)) {
Filesystem::deleteAllCacheOnUpdate();
}
if ($updater->getComponentUpdates() !== null && $module != 'CoreUpdater' && $module != 'Proxy' && $module != 'Installation' && !($module == 'LanguagesManager' && $action == 'saveLanguage')) {
if (FrontController::shouldRethrowException()) {
throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n");
} else {
Piwik::redirectToModule('CoreUpdater');
}
}
}