本文整理汇总了PHP中util::var_dump方法的典型用法代码示例。如果您正苦于以下问题:PHP util::var_dump方法的具体用法?PHP util::var_dump怎么用?PHP util::var_dump使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util
的用法示例。
在下文中一共展示了util::var_dump方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importPost
public function importPost($post, $dryrun = true)
{
// If the mapping is not defined, ignore it.
if (empty($this->config['mapping'][$post['post_type']])) {
return "<p>No mapping defined for posttype '" . $post['post_type'] . "'.</p>";
}
// Find out which mapping we should use.
$mapping = $this->config['mapping'][$post['post_type']];
// If the mapped contenttype doesn't exist in Bolt.
if (!$this->app['storage']->getContentType($mapping['targetcontenttype'])) {
return "<p>Bolt contenttype '" . $mapping['targetcontenttype'] . "' for posttype '" . $post['post_type'] . "' does not exist.</p>";
}
// Create the new Bolt Record.
$record = new \Bolt\Content($this->app, $mapping['targetcontenttype']);
// 'expand' the postmeta fields to regular fields.
if (!empty($post['postmeta']) && is_array($post['postmeta'])) {
foreach ($post['postmeta'] as $id => $keyvalue) {
$post[$keyvalue['key']] = $keyvalue['value'];
}
}
// Iterate through the mappings, see if we can find it.
foreach ($mapping['fields'] as $from => $to) {
if (isset($post[$from])) {
// It's present in the fields.
$value = $post[$from];
switch ($from) {
case "post_parent":
if (!empty($value)) {
$value = $mapping['fields']['post_parent_contenttype'] . "/" . $value;
}
break;
case "post_date":
if (!empty($value)) {
// WXR seems to use only one date value.
$record->setValue('datechanged', $value);
$record->setValue('datecreated', $value);
$record->setValue('datepublish', $value);
}
break;
}
switch ($to) {
case "username":
$value = makeSlug($value);
break;
case "status":
if ($value == "publish") {
$value = "published";
}
if ($value == "future") {
$value = "timed";
}
break;
}
$record->setValue($to, $value);
}
}
// Perhaps import the categories as well..
if (!empty($mapping['category']) && !empty($post['terms'])) {
foreach ($post['terms'] as $term) {
if ($term['domain'] == 'category') {
$record->setTaxonomy($mapping['category'], $term['slug']);
if (!in_array($term['slug'], $this->foundcategories)) {
$this->foundcategories[] = $term['slug'];
}
}
}
}
if ($dryrun) {
$output = "<p>Original WXR Post <b>\"" . $post['post_title'] . "\"</b> -> Converted Bolt Record :</p>";
$output .= \util::var_dump($post, true);
$output .= \util::var_dump($record, true);
$output .= "\n<hr>\n";
} else {
$this->app['storage']->saveContent($record);
$output = "Import: " . $record->get('id') . " - " . $record->get('title') . " <small><em>";
$output .= $this->memUsage() . "mb.</em></small><br>";
}
return $output;
}
示例2: processForm
private function processForm($formconfig, $form, $formname)
{
$data = $form->getData();
if ($formconfig['debugmode'] == true) {
\util::var_dump($formconfig);
\util::var_dump($form);
\util::var_dump($formname);
\util::var_dump($data);
\util::var_dump($this->app['request']->files);
}
// $data contains the posted data. For legibility, change boolean fields to "yes" or "no".
foreach ($data as $key => $value) {
if (gettype($value) == "boolean") {
$data[$key] = $value ? "yes" : "no";
}
}
// Some fieldtypes (like 'date' and 'file') require post-processing.
foreach ($formconfig['fields'] as $fieldname => $fieldvalues) {
// Check if we have fields of type 'file'. If so, fetch them, and move them
// to the designated folder.
if ($fieldvalues['type'] == "file") {
if (empty($formconfig['storage_location']) && $formconfig['attach_files'] === false) {
die("You must set the storage_location in the field {$fieldname} if you do not use attachments.");
} elseif (empty($formconfig['storage_location']) && $formconfig['attach_files'] == false) {
// temporary files location will be a subdirectory of the cache
$path = $this->app['paths']['apppath'] . '/cache';
$linkpath = $this->app['paths']['app'] . 'cache';
} else {
// files location will be a subdirectory of the files
$path = $this->app['paths']['filespath'] . "/" . $fieldvalues['storage_location'];
$linkpath = $this->app['paths']['files'] . $fieldvalues['storage_location'];
}
if (!is_writable($path)) {
die("The path {$path} is not writable.");
}
$files = $this->app['request']->files->get($form->getName());
$originalname = strtolower($files[$fieldname]->getClientOriginalName());
$filename = sprintf("%s-%s-%s.%s", $fieldname, date('Y-m-d'), $this->app['randomgenerator']->generateString(8, 'abcdefghijklmnopqrstuvwxyz01234567890'), getExtension($originalname));
$link = sprintf("%s%s/%s", $this->app['paths']['rooturl'], $linkpath, $filename);
// Make sure the file is in the allowed extensions.
if (in_array(getExtension($originalname), $fieldvalues['filetype'])) {
// If so, replace the file to designated folder.
$files[$fieldname]->move($path, $filename);
// by default we send a link
$data[$fieldname] = $link;
if ($formconfig['attach_files'] == 'true') {
// if there is an attachment and no saved file on the server
// only send the original name and the attachment
if (empty($formconfig['storage_location'])) {
$data[$fieldname] = $originalname . " ({$link})";
}
$attachments[] = \Swift_Attachment::fromPath($link)->setFilename($originalname);
}
} else {
$data[$fieldname] = "Invalid upload, ignored ({$originalname})";
}
}
// Fields of type 'date' are \DateTime objects. Convert them to string, for sending in emails, etc.
if ($fieldvalues['type'] == "date" && $data[$fieldname] instanceof \DateTime) {
$format = isset($fieldvalues['format']) ? $fieldvalues['format'] : "Y-m-d";
$data[$fieldname] = $data[$fieldname]->format($format);
}
if ($fieldvalues['type'] == "ip") {
$data[$fieldname] = $this->getRemoteAddress();
}
if ($fieldvalues['type'] == "timestamp") {
$format = "%F %T";
$data[$fieldname] = strftime($format);
}
}
// Attempt to insert the data into a table, if specified..
if (!empty($formconfig['insert_into_table'])) {
try {
$this->app['db']->insert($formconfig['insert_into_table'], $data);
} catch (\Doctrine\DBAL\DBALException $e) {
// Oops. User will get a warning on the dashboard about tables that need to be repaired.
$keys = array_keys($data);
$this->app['log']->add("SimpleForms could not insert data into table" . $formconfig['insert_into_table'] . ' (' . join(', ', $keys) . ') - check if the table exists.', 3);
echo "Couldn't insert data into table " . $formconfig['insert_into_table'] . ".";
}
}
$mailhtml = $this->app['render']->render($formconfig['mail_template'], array('form' => $data));
if ($formconfig['debugmode'] == true) {
\util::var_dump($mailhtml);
}
if (!empty($formconfig['mail_subject'])) {
$subject = $formconfig['mail_subject'];
} else {
$subject = '[SimpleForms] ' . $formname;
}
// Compile the message..
$message = \Swift_Message::newInstance()->setSubject($subject)->setFrom(array($formconfig['recipient_email'] => $formconfig['recipient_name']))->setTo(array($formconfig['recipient_email'] => $formconfig['recipient_name']))->setBody(strip_tags($mailhtml))->addPart($mailhtml, 'text/html');
if ($formconfig['attach_files'] == 'true' && is_array($attachments)) {
foreach ($attachments as $attachment) {
$message->attach($attachment);
}
}
// check for testmode
if ($formconfig['testmode'] == true) {
// override recipient with debug recipient
//.........这里部分代码省略.........
示例3: print_dump
/**
* Output pretty-printed arrays.
*
* @see util::php
* @see http://brandonwamboldt.github.com/utilphp/
*
* @param mixed $var
* return string
*/
public function print_dump($var)
{
$output = util::var_dump($var, true);
return $output;
}
示例4: test_var_dump
public function test_var_dump()
{
$input = 'var';
$expect = '<pre style="margin-bottom: 18px;background: #f7f7f9;border: 1px solid #e1e1e8;padding: 8px;border-radius: 4px;-moz-border-radius: 4px;-webkit-border radius: 4px;display: block;font-size: 12.05px;white-space: pre-wrap;word-wrap: break-word;color: #333;font-family: Menlo,Monaco,Consolas,\'Courier New\',monospace;"><span style="color:#588bff;">string</span><span style="color:#999;">(</span>3<span style="color:#999;">)</span> <strong>"var"</strong></pre>';
// Ensure the proper output is returned
$this->assertEquals($expect, Util::var_dump($input, true));
// Ensure the proper output is actually outputted
$this->expectOutputString($expect);
util::var_dump($input);
// Ensure we avoid infinite recursion on recursive arrays
$a = array('a' => 'value a', 'b' => 'value b');
$b = array('test' => &$a);
$c = array('a' => &$a, 'b' => &$b);
$a['c'] =& $c;
$b['c'] =& $c;
$this->assertContains('*RECURSION DETECTED*', Util::var_dump($c, true));
// Ensure we avoid infinite recursion on recursive objects
$a = (object) array('a' => 'value a', 'b' => 'value b');
$b = (object) array('test' => &$a);
$c = (object) array('a' => &$a, 'b' => &$b);
$a->c =& $c;
$b->c =& $c;
$this->assertContains('*RECURSION DETECTED*', Util::var_dump($c, true));
// Test class scoping.
$experiment = new VarDumpExperiment();
$actual = util::var_dump($experiment, true);
$snippet = substr($actual, strrpos($actual, 'display:inline'));
$this->assertContains('"public"', $snippet);
$this->assertContains('"protected:protected"', $snippet);
$this->assertContains('"private:VarDumpExperiment:private"', $actual);
}