本文整理汇总了PHP中FileHelper::writeFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHelper::writeFile方法的具体用法?PHP FileHelper::writeFile怎么用?PHP FileHelper::writeFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHelper
的用法示例。
在下文中一共展示了FileHelper::writeFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateTagRelationCache
public static function updateTagRelationCache($manualLock = false)
{
if (!$manualLock) {
self::checkTagRelationCache('lock');
}
try {
$tagRelationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/tagsRelations.php";
$c = new Criteria();
$allTags = TagPeer::doSelect($c);
$content = "<?php \n";
foreach ($allTags as $singleTag) {
$c = new Criteria();
$c->add(TagrelationPeer::TAG_ID, $singleTag->getId());
$tagRelations = TagrelationPeer::doSelect($c);
if ($tagRelations) {
$elementsArr = "array(";
foreach ($tagRelations as $tagRelation) {
$elementsArr .= $tagRelation->getId() . ",";
}
$content .= "\$_TagRel['" . $singleTag->getTagId() . "'] = " . substr($elementsArr, 0, -1) . ");\n";
}
}
$content .= "\n?>";
if (FileHelper::writeFile($tagRelationsFile, $content)) {
BackendService::loadTagsRelations();
} else {
echo FileHelper::Log("Unable to write tag cache in: " . $tagRelationsFile, UtilsHelper::MSG_ERROR);
}
} catch (Exception $e) {
echo FileHelper::Log("Unable to refresh tag cache: " . $e->getMessage(), UtilsHelper::MSG_ERROR);
}
if (!$manualLock) {
self::checkTagRelationCache('unlock');
}
}
示例2: function
<?php
require_once 'vendor/autoload.php';
require_once 'FileHelper.php';
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$app->post('/upload', function (Request $request) use($app) {
// get file from requests
$file = $request->files->get('image');
// if null return error
if ($file == null) {
$obj = new stdClass();
$obj->success = false;
$obj->error = "No image provided";
return json_encode($obj);
}
// upload the file and return the json with the data
return json_encode(FileHelper::writeFile($file));
});
$app->run();
示例3: run_generate_cache
function run_generate_cache($task, $args)
{
ini_set("memory_limit", "2048M");
ini_set("display_errors", 1);
define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
define('SF_APP', 'frontend');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG', false);
sfConfig::set("sf_use_relations_cache", false);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
run_url_relations($task, $args);
run_tags_relations($task, $args);
echo_cms_title("GENERATING CACHE...");
if (!class_exists("XMLParser")) {
include sfConfig::get('sf_root_dir') . "/lib/tools/XMLParser.class.php";
}
if (!class_exists("FileHelper")) {
include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php";
}
//echo_cms_sep();
echo_cms("sf_cache_objects = " . sfConfig::get('sf_cache_objects'));
echo_cms("sf_cache_relations = " . sfConfig::get('sf_cache_relations'));
echo_cms("sf_cache_trees = " . sfConfig::get('sf_cache_trees'));
//echo_cms_sep();
if (count($args) > 0) {
$relationsFlag = substr($args[0], 0, 3) == "rel";
$listsFlag = substr($args[0], 0, 4) == "list";
$cacheModel = $args[0];
if (is_numeric($cacheModel)) {
$obj = Document::getDocumentInstance($cacheModel);
if ($obj) {
$phpName = get_class($obj);
} else {
echo_cms_error("Object with ID=" . $cacheModel . " not found!");
exit;
}
}
}
// parse schema file to make Schema.class.php
$objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/schema.xml");
$schemaFile = sfConfig::get('sf_root_dir') . "/config/Schema.class.php";
$content = $content = "<?php\n class Schema\n{\n\n";
echo_cms("Building " . $schemaFile . "... ");
foreach ($objects as $obj) {
if ($obj['tag'] == 'TABLE' && $obj['type'] == 'open') {
$table = $obj['attributes']['PHPNAME'];
if ($phpName && $phpName == $table) {
$tableName = $obj['attributes']['NAME'];
}
$trees = explode(",", $obj['attributes']['TREE']);
$content .= "\tpublic static function get" . $table . "Trees()\n\t{\n";
$content .= "\t\treturn array(";
foreach ($trees as $tree) {
$content .= "'" . strtolower($tree) . "', ";
}
$content = substr($content, 0, -2);
$content .= ");\n\t}\n\n";
$content .= "\tpublic static function get" . $table . "Properties()\n\t{\n";
$content .= "\t\treturn array(";
}
if ($obj['tag'] == 'COLUMN' && $obj['type'] == 'complete') {
$property = $obj['attributes']['NAME'];
$getProperty = UtilsHelper::convertFieldName($property);
$content .= "'" . $getProperty . "', ";
}
if ($obj['tag'] == 'TABLE' && $obj['type'] == 'close') {
$content = substr($content, 0, -2);
$content .= ");\n\t}\n\n";
}
}
$content .= "\n}";
//echo_cms_sep();
if (FileHelper::writeFile($schemaFile, $content)) {
echo_cms($schemaFile . " writen successfully!");
} else {
echo_cms_error("Error writing " . $schemaFile . "!");
}
echo "\n";
//echo_cms_sep();
if (substr($args[0], 0, 5) == "schema") {
echo_cms(" Done!");
exit;
}
if (!$relationsFlag && !$listsFlag) {
try {
if (is_numeric($cacheModel)) {
$obj = array();
$obj['tag'] = 'OBJECT';
$obj['type'] = 'complete';
$obj['id'] = $cacheModel;
$objects = array($obj);
$exit = true;
} elseif ($cacheModel) {
$obj = array();
$obj['tag'] = 'OBJECT';
$obj['type'] = 'complete';
$obj['value'] = $cacheModel;
$objects = array($obj);
//.........这里部分代码省略.........
示例4: updateRelationCache
public static function updateRelationCache($parentId = null, $manualLock = false)
{
//$m = memory_get_usage();
if (!$manualLock) {
self::checkRelationCache('wait');
self::checkRelationCache('lock');
}
try {
$relationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/childrenRelations.php";
$found = false;
if ($parentId && is_readable($relationsFile)) {
$handle = fopen($relationsFile, "r+");
if ($handle) {
$content = fread($handle, filesize($relationsFile));
$rels = explode("\$_Rel[" . $parentId . "]", $content);
$cnt = count($rels);
if ($cnt > 1) {
$prevContent = $rels[0];
$p = strpos($rels[$cnt - 1], ";");
$nextContent = substr($rels[$cnt - 1], $p + 2);
$found = true;
}
}
}
if (!$found) {
// if not found - create relations for ALL documents
$prevContent = "<?php \n";
$nextContent = "\n?>";
$parentId = null;
}
$c = new Criteria();
if ($parentId) {
$c->add(RelationPeer::ID1, $parentId);
}
$c->addAscendingOrderByColumn('id1');
$c->addAscendingOrderByColumn('document_model2');
$c->addAscendingOrderByColumn('sort_order');
$rs = RelationPeer::doSelectRs($c);
$i = 0;
$content = $prevContent;
// "<?php \n";
$oldIDModel = '';
$currIDModel = '';
$idStr = '';
while ($rs->next()) {
$id1 = $rs->getInt(1);
$id2 = $rs->getInt(2);
$model1 = $rs->getString(3);
$model2 = $rs->getString(4);
$sort = $rs->getString(5);
$currIDModel = $id1 . ':' . $model2;
if ($i == 0) {
$oldIDModel = $currIDModel;
}
$i++;
if ($currIDModel == $oldIDModel) {
$idStr .= "," . $id2;
} else {
$idStr = substr($idStr, 1);
$content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n";
$idStr = "," . $id2;
}
$oldIDModel = $currIDModel;
$oldId1 = $id1;
$oldModel2 = $model2;
}
if ($idStr) {
$idStr = substr($idStr, 1);
$content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n";
}
$content .= $nextContent;
/* "\n?>"; */
FileHelper::writeFile($relationsFile, $content);
$_SESSION['childrenRelations'] = null;
BackendService::loadChildrenRelations();
} catch (Exception $e) {
}
if (!$manualLock) {
self::checkRelationCache('unlock');
}
//$m2 = memory_get_usage();
//FileHelper::Log(round(($m2-$m)/1024/1024,2)." Mo");
}
示例5: cacheObj
public static function cacheObj($document, $documentModel = null, $refreshTree = true, $parentId = null)
{
if (sfConfig::get('sf_cache_objects')) {
// parse cachedObjects and cache objects
$objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/cachedObjects.xml");
// check if documentModel is Cached
$foundModel = false;
if (is_null($documentModel)) {
$documentModel = get_class($document);
}
foreach ($objects as $obj) {
if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') {
if ($documentModel == $obj['value']) {
$foundModel = true;
}
}
}
// Caching Object if it's model is in "cachedObjects.xml" file
if ($foundModel) {
$docId = $document->getId();
$path = self::getCachePath($docId, true);
include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php";
$m = "get" . $documentModel . "Properties";
$properties = Schema::$m();
$content = "<?php\nclass CachedObj" . $docId . "\n{\n";
$content .= "\tpublic function __getDocumentModel(){\n\t\treturn \"" . $documentModel . "\";\n\t}\n";
foreach ($properties as $getProperty) {
$getter = "get" . ucfirst($getProperty);
$v = $document->{$getter}();
if (is_null($v)) {
$content .= "\tpublic function " . $getter . "(){\n\t\treturn NULL;\n\t}\n";
} else {
if ($documentModel == "Page" && $getProperty == "Content") {
$content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n";
} else {
// delete <script> tags !!!
$v = preg_replace('@(<[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v);
$v = preg_replace('@(<[ \\n\\r\\t]*/[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v);
$content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n";
}
}
/* else
{
$content .= "\tpublic function ".$getter."(){\n\t\treturn ".$v.";\n\t}\n";
}*/
}
if (!$parentId) {
$parentId = intval(self::getParentOf($docId, null, false, false));
}
$content .= "\tpublic function getParent(){\n\t\treturn {$parentId};\n\t}\n";
$content .= "}";
$cachefile = $path . "doc" . $docId . ".php";
if (file_exists($cachefile)) {
unlink($cachefile);
}
FileHelper::writeFile($cachefile, $content);
chmod($cachefile, 0777);
}
}
// Refreshing Tree - not related to CacheObject !!!
if (sfConfig::get('sf_cache_trees') && $refreshTree) {
/*
$modules = FileHelper::getSubElements(sfConfig::get('sf_root_dir')."/apps/backend/modules", "folder");
foreach ($modules as $module => $path)
*/
include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php";
$documentModel = get_class($document);
$getTree = "get" . $documentModel . "Trees";
$trees = Schema::$getTree();
foreach ($trees as $module) {
$module = strtolower($module);
// Caching Left, Right and MCE tree
BackendService::updateTree($module, $document, "UPDATE");
//BackendService::updateTree($module, $document, "UPDATE", "right");
BackendService::updateTree($module, $document, "UPDATE", "mce");
}
}
}
示例6: makePhpCache
public static function makePhpCache($contentArr, $moduleName, $tree, $saveToFile = true)
{
$content = "<?php\n\n" . "\$contentArray = array(\n";
foreach ($contentArr as $contentItem) {
$content .= "\t" . $contentItem['id'] . "\t\t=> array(";
foreach ($contentItem as $k => $v) {
if (is_int($v)) {
$content .= " '" . $k . "' => " . $v . ",";
} else {
$content .= " '" . $k . "' => '" . addslashes($v) . "',";
}
}
$content = substr($content, 0, -1) . "),\n";
}
$content = substr($content, 0, -2) . "\n);\n\n?>";
if ($saveToFile) {
$moduleName = ucfirst($moduleName);
/*if($tree == "right")
{
$writeResult = FileHelper::writeFile(sfConfig::get('sf_root_dir')."/cache/backend/".$moduleName."_rightTree.php", $content);
}
else*/
if ($tree == "mce") {
$writeResult = FileHelper::writeFile(sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.php", $content);
} else {
$writeResult = FileHelper::writeFile(sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_Tree.php", $content);
}
if ($writeResult) {
return self::makeHtmlCache($moduleName, $tree);
} else {
return "Error caching tree";
}
}
return $content;
}
示例7: updateListCache
public static function updateListCache($listId = null)
{
if ($listId) {
$list = Lists::getListByListId($listId);
$lists = array($list);
} else {
if ($listsRootFolder = Rootfolder::getRootfolderByModule("lists")) {
$lists = Document::getChildrenOf($listsRootFolder->getId(), "Lists");
}
}
foreach ($lists as $list) {
$listId = $list->getListId();
$listPath = sfConfig::get('sf_root_dir') . "/cache/listscache/" . $listId . ".php";
@unlink($listPath);
$content = "<?php \n";
$content .= "\$listItemsForSelect = array(\n";
$items = Lists::getListitemsForSelect($listId, array(), false);
foreach ($items as $key => $item) {
$content .= "\"" . str_replace("\"", "\\\"", $key) . "\" => \"" . str_replace("\"", "\\\"", $item) . "\",\n";
}
$content .= ");\n?>";
FileHelper::writeFile($listPath, $content);
}
}