本文整理汇总了PHP中Pimcore\File类的典型用法代码示例。如果您正苦于以下问题:PHP File类的具体用法?PHP File怎么用?PHP File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: locateConfigFile
/**
* @param $name
* @return mixed
*/
public static function locateConfigFile($name)
{
if (!isset(self::$configFileCache[$name])) {
$pathsToCheck = [PIMCORE_WEBSITE_PATH . "/config", PIMCORE_CONFIGURATION_DIRECTORY];
$file = PIMCORE_CONFIGURATION_DIRECTORY . "/" . $name;
// check for environment configuration
$env = getenv("PIMCORE_ENVIRONMENT");
if ($env) {
$fileExt = File::getFileExtension($name);
$pureName = str_replace("." . $fileExt, "", $name);
foreach ($pathsToCheck as $path) {
$tmpFile = $path . "/" . $pureName . "." . $env . "." . $fileExt;
if (file_exists($tmpFile)) {
$file = $tmpFile;
break;
}
}
}
foreach ($pathsToCheck as $path) {
$tmpFile = $path . "/" . $name;
if (file_exists($tmpFile)) {
$file = $tmpFile;
break;
}
}
self::$configFileCache[$name] = $file;
}
return self::$configFileCache[$name];
}
示例2: send
/**
* @param null $options
* @return bool|void
* @throws \Exception
* @throws \Zend_Http_Client_Exception
*/
public function send($options = null)
{
$sourceFile = $this->getSourceFile();
$destinationFile = $this->getDestinationFile();
if (!$sourceFile) {
throw new \Exception("No sourceFile provided.");
}
if (!$destinationFile) {
throw new \Exception("No destinationFile provided.");
}
if (is_array($options)) {
if ($options['overwrite'] == false && file_exists($destinationFile)) {
throw new \Exception("Destination file : '" . $destinationFile . "' already exists.");
}
}
if (!$this->getHttpClient()) {
$httpClient = \Pimcore\Tool::getHttpClient(null, ['timeout' => 3600 * 60]);
} else {
$httpClient = $this->getHttpClient();
}
$httpClient->setUri($this->getSourceFile());
$response = $httpClient->request();
if ($response->isSuccessful()) {
$data = $response->getBody();
File::mkdir(dirname($destinationFile));
$result = File::put($destinationFile, $data);
if ($result === false) {
throw new \Exception("Couldn't write destination file:" . $destinationFile);
}
} else {
throw new \Exception("Couldn't download file:" . $sourceFile);
}
return true;
}
示例3: installConfigFile
public function installConfigFile()
{
if (!is_file($this->configFile)) {
$settings = array("accordion" => ["configElements" => [["type" => "select", "name" => "type", "title" => "Type", "values" => ["panel-default" => "Default", "panel-danger" => "Dangers"], "default" => "panel-default"], ["type" => "additionalClasses", "values" => []]]], "columns" => ["configElements" => [["type" => "select", "name" => "type", "title" => "Columns", "values" => ["column_12" => "1 Column", "column_4_8" => "2 Columns (33:66)", "column_8_4" => "2 Columns (66:33)", "column_3_9" => "2 Columns (25:75)", "column_9_3" => "2 Columns (75:25)", "column_6_6" => "2 Columns (50:50)", "column_4_4_4" => "3 Columns (33:33:33)"], "default" => "column_12"], ["type" => "checkbox", "name" => "equalHeight", "title" => "Equal heights?", "reload" => FALSE]]], "slideColumns" => ["configElements" => [["type" => "select", "name" => "slidesPerView", "title" => "Slides per View", "values" => ["2" => "2 Columns", "3" => "3 Columns", "4" => "4 Columns", "6" => "6 Columns"], "default" => "4"], ["type" => "checkbox", "name" => "equalHeight", "title" => "Equal heights?", "reload" => FALSE]], "columnClasses" => ["2" => "col-xs-12 col-sm-6"], "breakpoints" => []], "content" => ["configElements" => [["type" => "additionalClasses", "values" => []]]], "download" => ["configElements" => [["type" => "additionalClasses", "values" => []]]], "gallery" => ["configElements" => [["type" => "additionalClasses", "values" => []]]], "headline" => ["configElements" => [["type" => "select", "name" => "headlineType", "title" => "Headline Size", "values" => ["h1" => "Headline 1", "h2" => "Headline 2", "h3" => "Headline 3", "h4" => "Headline 4", "h5" => "Headline 5", "h6" => "Headline 6"], "default" => "h3"], ["type" => "additionalClasses", "values" => []]]], "image" => ["configElements" => [["type" => "additionalClasses", "values" => []]]], "linklist" => ["configElements" => [["type" => "additionalClasses", "values" => []]]], "parallaxContainer" => ["configElements" => [["type" => "select", "name" => "type", "title" => "Type", "values" => ["image" => "Image", "snippet" => "Snippet"], "default" => "image"], ["type" => "additionalClasses", "values" => ["window-full-height" => "min. window height"]]]], "separator" => ["configElements" => [["type" => "select", "name" => "space", "title" => "Space before & after separator", "values" => ["default" => "Default", "medium" => "Medium", "large" => "Large"], "default" => "default"], ["type" => "additionalClasses", "values" => []]]], "teaser" => ["configElements" => [["type" => "select", "name" => "type", "title" => "Type", "values" => ["direct" => "Direct", "snippet" => "Snippet"], "default" => "direct"], ["type" => "select", "name" => "layout", "title" => "Layout", "values" => ["default" => "Default"], "default" => "default", "conditions" => [["type" => "direct"]]], ["type" => "checkbox", "name" => "useLightBox", "title" => "use Lightbox?"], ["type" => "additionalClasses", "values" => []]]], "video" => ["configElements" => [["type" => "additionalClasses", "values" => []], ["type" => "checkbox", "name" => "autoplay", "title" => "Autoplay?"]]], "googleMap" => ["configElements" => [], "mapOptions" => ["streetViewControl" => TRUE, "mapTypeControl" => FALSE, "panControl" => FALSE, "scrollwheel" => FALSE], "mapStyleUrl" => FALSE, "markerIcon" => FALSE], "ckeditor" => ["styles" => [['name' => 'test', 'element' => 'p', 'attributes' => ['class' => 'h5']]]], "disallowedSubAreas" => ["accordion" => ["accordion", "container", "slideColumns"], "columns" => ["container"], "slideColumns" => ["slideColumns", "accordion", "container", "columns", "anchor"], "container" => ["container"], "image" => ["parallaxContainer"], "snippet" => ["parallaxContainer"]], "disallowedContentSnippetAreas" => ["parallaxContainer", "teaser", "container", "snippet"], "areaBlockConfiguration" => ["toolbar" => ["title" => "Inhaltsbausteine", "width" => 200, "x" => 10, "y" => 125, "buttonWidth" => 200], "groups" => FALSE]);
\Pimcore\File::putPhpFile($this->configFile, to_php_data_file_format($settings));
}
}
示例4: config
/**
* @param array $config
*/
public function config($config = [])
{
$settings = null;
// check for an initial configuration template
// used eg. by the demo installer
$configTemplatePath = PIMCORE_CONFIGURATION_DIRECTORY . "/system.template.php";
if (file_exists($configTemplatePath)) {
try {
$configTemplate = new \Zend_Config(include $configTemplatePath);
if ($configTemplate->general) {
// check if the template contains a valid configuration
$settings = $configTemplate->toArray();
// unset database configuration
unset($settings["database"]["params"]["host"]);
unset($settings["database"]["params"]["port"]);
}
} catch (\Exception $e) {
}
}
// set default configuration if no template is present
if (!$settings) {
// write configuration file
$settings = ["general" => ["timezone" => "Europe/Berlin", "language" => "en", "validLanguages" => "en", "debug" => "1", "debugloglevel" => "debug", "custom_php_logfile" => "1", "extjs6" => "1"], "database" => ["adapter" => "Mysqli", "params" => ["username" => "root", "password" => "", "dbname" => ""]], "documents" => ["versions" => ["steps" => "10"], "default_controller" => "default", "default_action" => "default", "error_pages" => ["default" => "/"], "createredirectwhenmoved" => "", "allowtrailingslash" => "no", "generatepreview" => "1"], "objects" => ["versions" => ["steps" => "10"]], "assets" => ["versions" => ["steps" => "10"]], "services" => [], "cache" => ["excludeCookie" => ""], "httpclient" => ["adapter" => "Zend_Http_Client_Adapter_Socket"]];
}
$settings = array_replace_recursive($settings, $config);
// create initial /website/var folder structure
// @TODO: should use values out of startup.php (Constants)
$varFolders = ["areas", "assets", "backup", "cache", "classes", "config", "email", "log", "plugins", "recyclebin", "search", "system", "tmp", "versions", "webdav"];
foreach ($varFolders as $folder) {
\Pimcore\File::mkdir(PIMCORE_WEBSITE_VAR . "/" . $folder);
}
$configFile = \Pimcore\Config::locateConfigFile("system.php");
File::putPhpFile($configFile, to_php_data_file_format($settings));
}
示例5: detect
/**
* @param $file
* @param null $filename
* @return mixed|string
* @throws \Exception
*/
public static function detect($file, $filename = null)
{
if (!file_exists($file)) {
throw new \Exception("File " . $file . " doesn't exist");
}
if (!$filename) {
$filename = basename($file);
}
// check for an extension mapping first
if ($filename) {
$extension = \Pimcore\File::getFileExtension($filename);
if (array_key_exists($extension, self::$extensionMapping)) {
return self::$extensionMapping[$extension];
}
}
// check with fileinfo, if there's no extension mapping
$finfo = finfo_open(FILEINFO_MIME);
$type = finfo_file($finfo, $file);
finfo_close($finfo);
if ($type !== false && !empty($type)) {
if (strstr($type, ';')) {
$type = substr($type, 0, strpos($type, ';'));
}
return $type;
}
// return default mime-type if we're unable to detect it
return "application/octet-stream";
}
示例6: processHtml
/**
* @param $body
* @return mixed
*/
public static function processHtml($body)
{
$processedPaths = array();
preg_match_all("@\\<link[^>]*(rel=\"stylesheet/less\")[^>]*\\>@msUi", $body, $matches);
if (is_array($matches)) {
foreach ($matches[0] as $tag) {
preg_match("/href=\"([^\"]+)*\"/", $tag, $href);
if (array_key_exists(1, $href) && !empty($href[1])) {
$source = $href[1];
$source = preg_replace("/\\?_dc=[\\d]+/", "", $source);
if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) {
$path = PIMCORE_ASSET_DIRECTORY . $source;
} else {
if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) {
$path = PIMCORE_DOCUMENT_ROOT . $source;
}
}
// add the same file only one time
if (in_array($path, $processedPaths)) {
continue;
}
$newFile = PIMCORE_TEMPORARY_DIRECTORY . "/less___" . File::getValidFilename(str_replace(".less", "", $source)) . "-" . filemtime($path) . ".css";
if (!is_file($newFile)) {
$compiledContent = self::compile($path, $source);
File::put($newFile, $compiledContent);
}
$body = str_replace($tag, str_replace("stylesheet/less", "stylesheet", str_replace($source, str_replace(PIMCORE_DOCUMENT_ROOT, "", $newFile), $tag)), $body);
}
}
}
return $body;
}
示例7: getWorkingDir
/**
* @static
* @return string
*/
public static function getWorkingDir()
{
$dir = PIMCORE_CONFIGURATION_DIRECTORY . "/videopipelines";
if (!is_dir($dir)) {
\Pimcore\File::mkdir($dir);
}
return $dir;
}
示例8: saveAction
public function saveAction()
{
$this->checkPermission("system_settings");
$values = \Zend_Json::decode($this->getParam("data"));
$configFile = \Pimcore\Config::locateConfigFile("reports.php");
File::put($configFile, to_php_data_file_format($values));
$this->_helper->json(array("success" => true));
}
示例9: _write
/**
* calls prent _write and and writes temp log file
*
* @param array $event Event data
* @return void
*/
protected function _write($event)
{
if (!is_file($this->_tempfile)) {
@\Pimcore\File::put($this->_tempfile, "... continued ...\r\n");
$writerFile = new \Zend_Log_Writer_Stream($this->_tempfile);
$this->_tempLogger = new \Zend_Log($writerFile);
}
$this->_tempLogger->log($event['message'], $event['priority']);
parent::_write($event);
}
示例10: getMinimizedStylesheetPath
/**
* @param $stylesheetContent
* @return mixed
*/
public static function getMinimizedStylesheetPath($stylesheetContent)
{
$stylesheetPath = PIMCORE_TEMPORARY_DIRECTORY . "/minified_css_core_" . md5($stylesheetContent) . ".css";
if (!is_file($stylesheetPath)) {
//$stylesheetContent = Minify_CSS::minify($stylesheetContent); // temp. disabled until we have a better library - just combine for now
// put minified contents into one single file
File::put($stylesheetPath, $stylesheetContent);
}
return preg_replace("@^" . preg_quote(PIMCORE_DOCUMENT_ROOT, "@") . "@", "", $stylesheetPath);
}
示例11: setName
/**
* @param string $name
* @return $this|void
* @throws DAV\Exception\Forbidden
* @throws \Exception
*/
function setName($name)
{
if ($this->asset->isAllowed("rename")) {
$user = AdminTool::getCurrentUser();
$this->asset->setUserModification($user->getId());
$this->asset->setFilename(\Pimcore\File::getValidFilename($name));
$this->asset->save();
} else {
throw new DAV\Exception\Forbidden();
}
return $this;
}
示例12: preparePath
/**
* @param $path
* @return string
*/
protected function preparePath($path)
{
if (!stream_is_local($path)) {
// gs is only able to deal with local files
// if your're using custom stream wrappers this wouldn't work, so we create a temp. local copy
$tmpFilePath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/imagick-tmp-" . uniqid() . "." . File::getFileExtension($path);
copy($path, $tmpFilePath);
$path = $tmpFilePath;
$this->tmpFiles[] = $path;
}
return $path;
}
示例13: saveDeleteLog
/**
* @param $log
*/
public static function saveDeleteLog($log)
{
// cleanup old entries
$tmpLog = array();
foreach ($log as $path => $data) {
if ($data["timestamp"] > time() - 30) {
// remove 30 seconds old entries
$tmpLog[$path] = $data;
}
}
\Pimcore\File::put(Asset\WebDAV\Service::getDeleteLogFile(), serialize($tmpLog));
}
示例14: dispatchLoopShutdown
/**
*
*/
public function dispatchLoopShutdown()
{
if (!Tool::isHtmlResponse($this->getResponse())) {
return;
}
if ($this->enabled) {
include_once "simple_html_dom.php";
$body = $this->getResponse()->getBody();
$html = str_get_html($body);
if ($html) {
$styles = $html->find("link[rel=stylesheet], style[type=text/css]");
$stylesheetContent = "";
foreach ($styles as $style) {
if ($style->tag == "style") {
$stylesheetContent .= $style->innertext;
} else {
$source = $style->href;
$path = "";
if (is_file(PIMCORE_ASSET_DIRECTORY . $source)) {
$path = PIMCORE_ASSET_DIRECTORY . $source;
} else {
if (is_file(PIMCORE_DOCUMENT_ROOT . $source)) {
$path = PIMCORE_DOCUMENT_ROOT . $source;
}
}
if (!empty($path) && is_file("file://" . $path)) {
$content = file_get_contents($path);
$content = $this->correctReferences($source, $content);
if ($style->media) {
$content = "@media " . $style->media . " {" . $content . "}";
}
$stylesheetContent .= $content;
$style->outertext = "";
}
}
}
if (strlen($stylesheetContent) > 1) {
$stylesheetPath = PIMCORE_TEMPORARY_DIRECTORY . "/minified_css_" . md5($stylesheetContent) . ".css";
if (!is_file($stylesheetPath)) {
// put minified contents into one single file
File::put($stylesheetPath, $stylesheetContent);
}
$head = $html->find("head", 0);
$head->innertext = $head->innertext . "\n" . '<link rel="stylesheet" type="text/css" href="' . str_replace(PIMCORE_DOCUMENT_ROOT, "", $stylesheetPath) . '" />' . "\n";
}
$body = $html->save();
$html->clear();
unset($html);
$this->getResponse()->setBody($body);
}
}
}
示例15: __construct
/**
* @param string $data
* @param string $filename
*/
public function __construct($data, $filename = null)
{
if (!is_dir(PIMCORE_LOG_FILEOBJECT_DIRECTORY)) {
File::mkdir(PIMCORE_LOG_FILEOBJECT_DIRECTORY);
}
$this->data = $data;
$this->filename = $filename;
if (empty($this->filename)) {
$folderpath = PIMCORE_LOG_FILEOBJECT_DIRECTORY . strftime('/%Y/%m/%d');
if (!is_dir($folderpath)) {
mkdir($folderpath, 0775, true);
}
$this->filename = $folderpath . "/" . uniqid("fileobject_", true);
}
File::put($this->filename, $this->data);
}