本文整理汇总了PHP中Thin\File::append方法的典型用法代码示例。如果您正苦于以下问题:PHP File::append方法的具体用法?PHP File::append怎么用?PHP File::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thin\File
的用法示例。
在下文中一共展示了File::append方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: csvByZone
public function csvByZone($address)
{
ini_set('memory_limit', '1024M');
set_time_limit(0);
$file = '/home/gerald/Bureau/' . Inflector::urlize($address) . '_' . date('dmYHis') . '.csv';
touch($file);
$zone = rdb('geo', 'zone')->where(['address', '=i', $address])->first(true);
if ($zone) {
File::append($file, implode(';', ['category', 'name', 'address', 'lat', 'lng', 'altitude', 'zip', 'city', 'phone', 'mail', 'url']) . "\n");
$pivots = $zone->pivots(rdb('geo', 'etablissement')->model())->exec(true);
foreach ($pivots as $pivot) {
$etab = $pivot->etablissement(true);
if ($zone) {
$relations = $etab->pivots(rdb('geo', 'service'))->exec(true);
foreach ($relations as $relation) {
$sp = $relation->service(true);
if ($sp) {
$item = [];
$item['category'] = str_replace([', ', ','], '-', $sp->label);
$item['name'] = str_replace([', ', ','], '-', $etab->name);
$item['address'] = str_replace([', ', ','], '-', $etab->address);
$item['lat'] = str_replace([', ', ','], '.', $etab->lat);
$item['lng'] = str_replace([', ', ','], '.', $etab->lng);
$item['altitude'] = str_replace([', ', ','], '.', $etab->altitude);
$item['zip'] = str_replace([', ', ','], '-', $etab->zip);
$item['city'] = str_replace([', ', ','], '-', $etab->city);
$item['phone'] = str_replace([', ', ','], '-', $etab->phone);
$item['mail'] = str_replace([', ', ','], '-', $etab->mail);
$item['url'] = str_replace([', ', ','], '-', $etab->url);
File::append($file, implode(';', $item) . "\n");
}
}
}
}
}
}
示例2: ThinLog
function ThinLog($message, $logFile = null, $type = 'info')
{
if (null === $logFile) {
$logFile = LOGS_PATH . DS . date('Y-m-d') . '.log';
} else {
if (false === File::exists($logFile)) {
File::create($logFile);
}
}
File::append($logFile, date('Y-m-d H:i:s') . "\t" . Inflector::upper($type) . "\t{$message}\n");
}
示例3: seeds
public function seeds($database = null)
{
set_time_limit(0);
$database = is_null($database) ? SITE_NAME : $database;
$path = STORAGE_PATH . DS . 'seeds';
if (!is_dir($path)) {
File::mkdir($path);
}
$now = time();
$db = $this->getOdm();
$backup = self::instance('core', 'backup');
$collections = $db->getCollectionNames();
$key = array_search('zelift.ages', $collections);
if (strlen($key)) {
unset($collections[$key]);
}
$key = array_search('zelift.counters', $collections);
if (strlen($key)) {
unset($collections[$key]);
}
$key = array_search('zelift.tuples', $collections);
if (strlen($key)) {
unset($collections[$key]);
}
$key = array_search('zelift.caching', $collections);
if (strlen($key)) {
unset($collections[$key]);
}
$key = array_search('zelift.ages', $collections);
if (strlen($key)) {
unset($collections[$key]);
}
foreach ($collections as $coll) {
list($collDb, $collTable) = explode('.', $coll, 2);
if ($collDb != $database) {
continue;
}
$row = $backup->where(['collection', '=', $coll])->first(true);
if (!$row) {
$row = $backup->firstOrCreate(['collection' => $coll])->setWhen($now)->save();
}
$file = STORAGE_PATH . DS . 'seeds' . DS . str_replace('.', '_', $coll) . '.php';
$model = self::instance($collDb, $collTable);
$last = $model->where(['id', '>', 0])->select('updated_at')->order('updated_at', 'DESC')->first(true);
if ($last) {
if ($last->updated_at > $row->when || !File::exists($file)) {
if (!File::exists($file)) {
$datas = $model->select('id')->get();
} else {
$datas = $model->where(['updated_at', '>=', (int) $now])->select('id')->get();
File::delete($file);
}
if (!empty($datas)) {
File::put($file, '<?php' . "\nnamespace Thin;\n\n");
$code = '';
$code .= '$db = rdb("' . $collDb . '", "' . $collTable . '");' . "\n\n\n";
File::append($file, $code);
foreach ($datas as $rowData) {
$data = $model->find((int) $rowData['id'], false);
$codeRow = '// *** ligne ' . $data['id'] . ' ***' . "\n";
$codeRow .= '$row = $db->find(' . $data['id'] . ');' . "\n\n";
$codeRow .= 'if (!$row) {' . "\n";
$codeRow .= "\t" . '$row = $db->addWithId(["id" => ' . $data['id'] . ']);' . "\n";
$codeRow .= '}' . "\n\n";
unset($data['id']);
$codeRow .= '$data = ' . var_export($data, 1) . ';' . "\n";
$codeRow .= '$row->hydrate($data)->save();' . "\n";
$codeRow .= '// *** fin ligne ' . $data['id'] . ' ***' . "\n\n";
File::append($file, $codeRow);
}
$row->setWhen($now)->save();
}
}
}
}
dd(Timer::get());
}