本文整理汇总了PHP中Pimcore\File::put方法的典型用法代码示例。如果您正苦于以下问题:PHP File::put方法的具体用法?PHP File::put怎么用?PHP File::put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\File
的用法示例。
在下文中一共展示了File::put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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));
}
示例4: load
/**
* @param $imagePath
* @param array $options
* @return $this|bool|self
*/
public function load($imagePath, $options = [])
{
// support image URLs
if (preg_match("@^https?://@", $imagePath)) {
$tmpFilename = "imagick_auto_download_" . md5($imagePath) . "." . File::getFileExtension($imagePath);
$tmpFilePath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $tmpFilename;
$this->tmpFiles[] = $tmpFilePath;
File::put($tmpFilePath, \Pimcore\Tool::getHttpData($imagePath));
$imagePath = $tmpFilePath;
}
if ($this->resource) {
unset($this->resource);
$this->resource = null;
}
try {
$i = new \Imagick();
$this->imagePath = $imagePath;
if (method_exists($i, "setcolorspace")) {
$i->setcolorspace(\Imagick::COLORSPACE_SRGB);
}
$i->setBackgroundColor(new \ImagickPixel('transparent'));
//set .png transparent (print)
if (isset($options["resolution"])) {
// set the resolution to 2000x2000 for known vector formats
// otherwise this will cause problems with eg. cropPercent in the image editable (select specific area)
// maybe there's a better solution but for now this fixes the problem
$i->setResolution($options["resolution"]["x"], $options["resolution"]["y"]);
}
$imagePathLoad = $imagePath;
if (!defined("HHVM_VERSION")) {
$imagePathLoad .= "[0]";
// not supported by HHVM implementation - selects the first layer/page in layered/pages file formats
}
if (!$i->readImage($imagePathLoad) || !filesize($imagePath)) {
return false;
}
$this->resource = $i;
// this is because of HHVM which has problems with $this->resource->readImage();
// set dimensions
$dimensions = $this->getDimensions();
$this->setWidth($dimensions["width"]);
$this->setHeight($dimensions["height"]);
// check if image can have alpha channel
if (!$this->reinitializing) {
$alphaChannel = $i->getImageAlphaChannel();
if ($alphaChannel) {
$this->setIsAlphaPossible(true);
}
}
$this->setColorspaceToRGB();
} catch (\Exception $e) {
\Logger::error("Unable to load image: " . $imagePath);
\Logger::error($e);
return false;
}
$this->setModified(false);
return $this;
}
示例5: getMinimizedScriptPath
/**
* @static
* @param $scriptContent
* @return mixed
*/
public static function getMinimizedScriptPath($scriptContent)
{
$scriptPath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/minified_javascript_core_" . md5($scriptContent) . ".js";
if (!is_file($scriptPath)) {
File::put($scriptPath, $scriptContent);
}
$params = ["scriptPath" => "/website/var/system/", "scripts" => basename($scriptPath), "_dc" => \Pimcore\Version::getRevision()];
return "/admin/misc/script-proxy?" . array_toquerystring($params);
}
示例6: _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);
}
示例7: 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);
}
示例8: 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));
}
示例9: 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);
}
}
}
示例10: __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);
}
示例11: log
/**
* @param $name
* @param $message
*/
public static function log($name, $message)
{
$log = PIMCORE_LOG_DIRECTORY . "/{$name}.log";
if (!is_file($log)) {
if (is_writable(dirname($log))) {
File::put($log, "AUTOCREATE\n");
}
}
if (is_writable($log)) {
// check for big logfile, empty it if it's bigger than about 200M
if (filesize($log) > 200000000) {
File::put($log, "");
}
$f = fopen($log, "a+");
fwrite($f, \Zend_Date::now()->getIso() . " : " . $message . "\n");
fclose($f);
}
}
示例12: log
/**
* @param $name
* @param $message
*/
public static function log($name, $message)
{
$log = PIMCORE_LOG_DIRECTORY . "/{$name}.log";
if (!is_file($log)) {
if (is_writable(dirname($log))) {
File::put($log, "AUTOCREATE\n");
}
}
if (is_writable($log)) {
// check for big logfile, empty it if it's bigger than about 200M
if (filesize($log) > 200000000) {
File::put($log, "");
}
$date = new \DateTime("now");
$f = fopen($log, "a+");
fwrite($f, $date->format(\DateTime::ISO8601) . " : " . $message . "\n");
fclose($f);
}
}
示例13: load
/**
* loads the image by the specified path
*
* @param $imagePath
* @param array $options
* @return ImageMagick
*/
public function load($imagePath, $options = [])
{
// support image URLs
if (preg_match("@^https?://@", $imagePath)) {
$tmpFilename = "imagick_auto_download_" . md5($imagePath) . "." . File::getFileExtension($imagePath);
$tmpFilePath = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/" . $tmpFilename;
$this->tmpFiles[] = $tmpFilePath;
File::put($tmpFilePath, \Pimcore\Tool::getHttpData($imagePath));
$imagePath = $tmpFilePath;
}
if (!stream_is_local($imagePath)) {
// imagick 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($imagePath);
copy($imagePath, $tmpFilePath);
$imagePath = $tmpFilePath;
$this->tmpFiles[] = $imagePath;
}
$this->imagePath = $imagePath;
$this->initResource();
$this->setModified(false);
return $this;
}
示例14: config
/**
* @param array $config
*/
public function config($config = array())
{
$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 = array("general" => array("timezone" => "Europe/Berlin", "language" => "en", "validLanguages" => "en", "debug" => "1", "debugloglevel" => "debug", "custom_php_logfile" => "1", "extjs6" => "1"), "database" => array("adapter" => "Mysqli", "params" => array("username" => "root", "password" => "", "dbname" => "")), "documents" => array("versions" => array("steps" => "10"), "default_controller" => "default", "default_action" => "default", "error_pages" => array("default" => "/"), "createredirectwhenmoved" => "", "allowtrailingslash" => "no", "allowcapitals" => "no", "generatepreview" => "1"), "objects" => array("versions" => array("steps" => "10")), "assets" => array("versions" => array("steps" => "10")), "services" => array(), "cache" => array("excludeCookie" => ""), "httpclient" => array("adapter" => "Zend_Http_Client_Adapter_Socket"));
}
$settings = array_replace_recursive($settings, $config);
// convert all special characters to their entities so the xml writer can put it into the file
$settings = array_htmlspecialchars($settings);
// create initial /website/var folder structure
// @TODO: should use values out of startup.php (Constants)
$varFolders = array("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::put($configFile, to_php_data_file_format($settings));
}
示例15: save
/**
* @throws \Exception
*/
public function save()
{
if (!$this->getKey()) {
throw new \Exception("A field-collection needs a key to be saved!");
}
$fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/fieldcollections";
// create folder if not exist
if (!is_dir($fieldCollectionFolder)) {
File::mkdir($fieldCollectionFolder);
}
$serialized = Serialize::serialize($this);
$definitionFile = $fieldCollectionFolder . "/" . $this->getKey() . ".psf";
if (!is_writable(dirname($definitionFile)) || is_file($definitionFile) && !is_writable($definitionFile)) {
throw new \Exception("Cannot write definition file in: " . $definitionFile . " please check write permission on this directory.");
}
File::put($definitionFile, $serialized);
$extendClass = "Object\\Fieldcollection\\Data\\AbstractData";
if ($this->getParentClass()) {
$extendClass = $this->getParentClass();
$extendClass = "\\" . ltrim($extendClass, "\\");
}
// create class file
$cd = '<?php ';
$cd .= "\n\n";
$cd .= "/** Generated at " . date('c') . " */";
$cd .= "\n\n";
$cd .= "/**\n";
if ($_SERVER["REMOTE_ADDR"]) {
$cd .= "* IP: " . $_SERVER["REMOTE_ADDR"] . "\n";
}
$cd .= "*/\n";
$cd .= "\n\n";
$cd .= "namespace Pimcore\\Model\\Object\\Fieldcollection\\Data;";
$cd .= "\n\n";
$cd .= "use Pimcore\\Model\\Object;";
$cd .= "\n\n";
$cd .= "class " . ucfirst($this->getKey()) . " extends " . $extendClass . " {";
$cd .= "\n\n";
$cd .= 'public $type = "' . $this->getKey() . "\";\n";
if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) {
foreach ($this->getFieldDefinitions() as $key => $def) {
$cd .= "public \$" . $key . ";\n";
}
}
$cd .= "\n\n";
if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) {
$relationTypes = array();
foreach ($this->getFieldDefinitions() as $key => $def) {
/**
* @var $def Object\ClassDefinition\Data
*/
$cd .= $def->getGetterCodeFieldcollection($this);
$cd .= $def->getSetterCodeFieldcollection($this);
}
}
$cd .= "}\n";
$cd .= "\n";
$fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Fieldcollection/Data";
if (!is_dir($fieldClassFolder)) {
File::mkdir($fieldClassFolder);
}
$classFile = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php";
if (!is_writable(dirname($classFile)) || is_file($classFile) && !is_writable($classFile)) {
throw new \Exception("Cannot write definition file in: " . $classFile . " please check write permission on this directory.");
}
File::put($classFile, $cd);
// update classes
$classList = new Object\ClassDefinition\Listing();
$classes = $classList->load();
if (is_array($classes)) {
foreach ($classes as $class) {
foreach ($class->getFieldDefinitions() as $fieldDef) {
if ($fieldDef instanceof Object\ClassDefinition\Data\Fieldcollections) {
if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) {
$this->getResource()->createUpdateTable($class);
break;
}
}
}
}
}
}