本文整理汇总了PHP中SimpleXMLIterator::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLIterator::addChild方法的具体用法?PHP SimpleXMLIterator::addChild怎么用?PHP SimpleXMLIterator::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLIterator
的用法示例。
在下文中一共展示了SimpleXMLIterator::addChild方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseFile
/**
* Parse csv file for getting its metadata
* @param \SimpleXMLIterator $data data
* @return multitype:Ambigous <>
*/
public function parseFile($data)
{
try {
$temp = (array) $data;
$fileName = $temp['fileName'];
$dataType = $temp['dataType'];
$duplicateHandle = $data['duplicateHandle'];
$fileStorageId = (string) $temp['fileStorageId'];
$fullPath = (string) $temp['fullPath'];
// count file
$fp = file($fullPath);
$count = count($fp) - 1;
// Get headers
$header = array();
if (($handle = fopen($fullPath, "r")) !== false) {
// no row length limit plus csv escape with '
while (($csvRow = fgetcsv($handle, 0, ",", "'")) !== false) {
for ($columnNo = 0, $columnCount = count($csvRow); $columnNo < $columnCount; $columnNo++) {
$header[] = $csvRow[$columnNo];
$data->headers->addChild($columnNo, (string) $csvRow[$columnNo]);
}
break;
}
fclose($handle);
}
$data->records = $count;
$file = $data->addChild('file');
$file->addChild('fileName', (string) $temp['fileName']);
$file->addChild('fileStorageId', $fileStorageId);
unset($data->fileStorageId);
unset($data->fileName);
unset($data->fullPath);
$response = $this->edit($data);
// Make response
$response['fileName'] = $fileName;
$response['headers'] = $header;
return $response;
} catch (\Exception $e) {
echo $e->getMessage();
}
}
示例2: edit
/**
* save and edit system template document
* @param unknown $data data
* @return Ambigous <multitype:, multitype:Ambigous <boolean, \Base\Model\Service\Ambigous, multitype:, string, unknown, object> NULL >
*/
public function edit($data)
{
if (isset($data->id) && !empty($data->id) && isset($data->generatedOn)) {
unset($data->recipient);
}
$result = parent::edit($data);
$response = new \SimpleXMLIterator('<?xml version="1.0" encoding="UTF-8"?><template/>');
$response->addChild('id', (string) $result['id']);
$response->addChild('fields', 'recipient');
$recipients = $this->getOne($response);
$result['recipients'] = $recipients['fields'];
return $result;
}
示例3: updateAPP
protected function updateAPP()
{
if (is_file($this->applist) && is_writable($this->applist)) {
try {
$doc = new SimpleXMLIterator($this->applist, null, true);
} catch (Exception $e) {
$this->error[] = "发生异常:" . $e->getMessage() . " 文件:" . $e->getFile() . " 行号:" . $e->getLine();
return false;
}
if ($doc->getName() != "apps") {
$this->error[] = "applist.xml的根元素必须是apps";
return false;
}
$i = $doc->count();
if ($i !== 0) {
$apps = $doc->app;
foreach ($apps as $app) {
if ($app['name'] == $this->app_name) {
$this->error[] = "项目列表存在重名项目,请修改项目名称";
return false;
}
}
}
$doc->addChild("app");
$doc->app[$i]->addAttribute("name", $this->app_name);
$doc->app[$i]->addAttribute("path", $this->app_path);
$doc->app[$i]->addAttribute("index", $this->app_index);
if ($doc->asXML($this->applist)) {
return true;
} else {
$this->error[] = "TinkPHP助手/data/applist.xml 写入失败";
return false;
}
} else {
$this->error[] = "TinkPHP助手/data/applist.xml不存在";
return false;
}
}
示例4: edit
/**
* edit function
* @param SimpleXMLIterator $data array
* @return array
*/
public function edit($data)
{
// get the users instance referece
$query = $this->_dm->createQueryBuilder('MoveIn4Instance\\Document\\InstanceDocument');
$inst = $query->field('shortName')->equals((string) $data->auth->inst)->getQuery()->getSingleResult();
if ($inst) {
$data->addChild('instance', $inst->getId());
}
return parent::edit($data);
}
示例5: _setQuickEditData
/**
* replace _id with id in message for saving form data
* @param \SimpleXMLIterator $data - passed from message queue
* @return void
*/
private function _setQuickEditData($data)
{
if (isset($data->_id)) {
$data->addChild('id', $data->_id);
unset($data->_id);
} elseif (isset($data['_id'])) {
$data['id'] = $data['_id'];
unset($data['_id']);
}
foreach ($data as $key => $value) {
if (is_object($value) || is_array($value)) {
$this->_setQuickEditData($value);
}
}
}