Dumps values.

@param mixed $value
@param bool  $interpolate

@return string

@throws RuntimeException
508829
private function dumpValue($value, $interpolate = true)
    {
        if (is_array($value)) {
            $code = array();
            foreach ($value as $k => $v) {
                $code[] = sprintf('%s => %s', $this->dumpValue($k, $interpolate), $this->dumpValue($v, $interpolate));
            }

            return sprintf('array(%s)', implode(', ', $code));
        } elseif ($value instanceof Definition) {
            if (null !== $this->definitionVariables && $this->definitionVariables->contains($value)) {
                return $this->dumpValue($this->definitionVariables->offsetGet($value), $interpolate);
            }
            if (count($value->getMethodCalls()) > 0) {
                throw new RuntimeException('Cannot dump definitions which have method calls.');
            }
            if (null !== $value->getConfigurator()) {
                throw new RuntimeException('Cannot dump definitions which have a configurator.');
            }

            $arguments = array();
            foreach ($value->getArguments() as $argument) {
                $arguments[] = $this->dumpValue($argument);
            }

            if (null !== $value->getFactory()) {
                $factory = $value->getFactory();

                if (is_string($factory)) {
                    return sprintf('%s(%s)', $this->dumpLiteralClass($this->dumpValue($factory)), implode(', ', $arguments));
                }

                if (is_array($factory)) {
                    if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $factory[1])) {
                        throw new RuntimeException(sprintf('Cannot dump definition because of invalid factory method (%s)', $factory[1] ?: 'n/a'));
                    }

                    if (is_string($factory[0])) {
                        return sprintf('%s::%s(%s)', $this->dumpLiteralClass($this->dumpValue($factory[0])), $factory[1], implode(', ', $arguments));
                    }

                    if ($factory[0] instanceof Definition) {
                        return sprintf("call_user_func(array(%s, '%s')%s)", $this->dumpValue($factory[0]), $factory[1], count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
                    }

                    if ($factory[0] instanceof Reference) {
                        return sprintf('%s->%s(%s)', $this->dumpValue($factory[0]), $factory[1], implode(', ', $arguments));
                    }
                }

                throw new RuntimeException('Cannot dump definition because of invalid factory');
            }

            $class = $value->getClass();
            if (null === $class) {
                throw new RuntimeException('Cannot dump definitions which have no class nor factory.');
            }

            return sprintf('new %s(%s)', $this->dumpLiteralClass($this->dumpValue($class)), implode(', ', $arguments));
        } elseif ($value instanceof Variable) {
            return '$'.$value;
        } elseif ($value instanceof Reference) {
            if (null !== $this->referenceVariables && isset($this->referenceVariables[$id = (string) $value])) {
                return $this->dumpValue($this->referenceVariables[$id], $interpolate);
            }

            return $this->getServiceCall((string) $value, $value);
        } elseif ($value instanceof Expression) {
            return $this->getExpressionLanguage()->compile((string) $value, array('this' => 'container'));
        } elseif ($value instanceof Parameter) {
            return $this->dumpParameter($value);
        } elseif (true === $interpolate && is_string($value)) {
            if (preg_match('/^%([^%]+)%$/', $value, $match)) {
                // we do this to deal with non string values (Boolean, integer, ...)
                // the preg_replace_callback converts them to strings
                return $this->dumpParameter(strtolower($match[1]));
            } else {
                $replaceParameters = function ($match) {
                    return "'.".$this->dumpParameter(strtolower($match[2])).".'";
                };

                $code = str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', $replaceParameters, $this->export($value)));

                return $code;
            }
        } elseif (is_object($value) || is_resource($value)) {
            throw new RuntimeException('Unable to dump a service container if a parameter is an object or a resource.');
        } else {
            return $this->export($value);
        }
    }
1211905
protected function _interpolate($query)
    {
        $params = array_map(function ($p) {
            if ($p === null) {
                return 'NULL';
            }
            if (is_bool($p)) {
                return $p ? '1' : '0';
            }

            if (is_string($p)) {
                $replacements = [
                    '$' => '\\$',
                    '\\' => '\\\\\\\\',
                    "'" => "''",
                ];

                $p = strtr($p, $replacements);

                return "'$p'";
            }

            return $p;
        }, $query->params);

        $keys = [];
        $limit = is_int(key($params)) ? 1 : -1;
        foreach ($params as $key => $param) {
            $keys[] = is_string($key) ? "/:$key\b/" : '/[?]/';
        }

        return preg_replace($keys, $params, $query->query, $limit);
    }
1325454
public function processValue( $value,
                                  ZipArchive $zip,
                                  array $substitutions,
                                  array $domains,
                                  $dbSchema,
                                  array $paragraphIdMap = null)
    {
        if ( empty( $substitutions ) )
        {
            return $value;
        }

        $base       = static::PUBLIC_DIR . static::UPLOADS_DIR;
        $siteInfo   = $this->getSiteInfo();
        $importDir  = null;

        foreach ( $substitutions as $original => $file )
        {
            $stats = $zip->statName( $file, ZipArchive::FL_NOCASE );

            if ( ! empty( $stats ) && isset( $stats['index'] ) )
            {
                $contents   = null;
                $file       = trim( $stats['name'], '/' );

                if ( $siteInfo->getSchema() == $dbSchema &&
                     substr( $file, 0, strlen( $base ) ) == $base &&
                     is_file( $file ) &&
                     filesize( $file ) == $stats['size']  )
                {
                    $contents = $zip->getFromIndex( $stats['index'] );

                    if ( file_get_contents( $file ) == $contents )
                    {
                        $contents = null;
                        continue;
                    }
                }

                if ( null === $importDir )
                {
                    $importDir = static::UPLOADS_DIR
                               . $siteInfo->getSchema()
                               . '/pages/imports/'
                               . (new DateTime)->toHash() . '/';

                    if ( ! is_dir( static::PUBLIC_DIR . $importDir ) )
                    {
                        @mkdir( static::PUBLIC_DIR . $importDir, 0777, true );
                    }
                }

                $info   = pathinfo( $file );
                $name   = str_replace( '%', '.', rawurlencode( $info['filename'] ) );
                $ext    = '';
                $suffix = '';

                if ( isset( $info['extension'] ) )
                {
                    $ext = '.' . str_replace( '%', '.', rawurlencode( $info['extension'] ) );
                }

                while ( is_file( static::PUBLIC_DIR . $importDir . $name . $suffix . $ext ) )
                {
                    --$suffix;
                }

                $url    = $importDir . $name . $suffix . $ext;
                $path   = static::PUBLIC_DIR . $url;

                if ( $contents )
                {
                    $write = false !== file_put_contents( $path, $contents );
                }
                else if ( is_resource( $source = $zip->getStream( $stats['name'] ) ) )
                {
                    $destination = @fopen( $path, 'w' );

                    if ( is_resource( $destination ) )
                    {
                        $write = stream_copy_to_stream( $source, $destination );
                        fclose( $destination );
                    }
                    else
                    {
                        $write = false;
                    }

                    fclose( $source );
                }
                else
                {
                    $write = false;
                }

                if ( $write )
                {
                    $value = str_replace( $original, '/' . $url, $value );
                }
            }
        }

        foreach ( $domains as $domain )
        {
            if ( $domain === $siteInfo->getDomain() )
            {
                continue;
            }

            $value = preg_replace_callback(
                '((https?://)([^/:]+?\.)?'
                    . preg_quote( $domain )
                    . '(:\d+)?/?)i',
                function ( $matches ) use ( $siteInfo )
                {
                    return $siteInfo->getSubdomainUrl(
                        empty( $matches[2] ) ? '' : $matches[2],
                        true
                    );
                },
                $value
            );
        }

        return $value;
    }
785743
public String interpolate() {
        getValues();
        if (definition == null) {
            return "";
        }

        int variableStart = definition.indexOf("{");
        if (variableStart < 0) {
            return definition;
        }

        int index = 0;
        int variableEnd = 0;
        StringBuilder sb = new StringBuilder();
        while (variableStart >= 0) {
            sb.append(definition.substring(variableEnd,
                                           variableStart));
            variableEnd = getIndexForEndOfVariable(definition,
                                                   variableStart) + 1;
            variableStart = definition.indexOf("{",
                                               variableEnd);
            sb.append(values.get(index++).getValue());
        }
        if (variableEnd < definition.length()) {
            sb.append(definition.substring(variableEnd));
        }
        return sb.toString();
    }
563818
public function debug($value='')
    {
        if($this->sieve->debug) {
            self::$writer->swrite(LOG_DEBUG, sprintf($this->template, 'DEBUG', $value));
        }
    }
345556
public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if (null === $value) {
            return $this->onNullFromPhp();
        }

        return $value->getValue();
    }
52297
private double fillInterpolatedValues(InterpolationType interpolationType) {
		double interpolatedValue = 0;
		if (shouldDoInterpolation(true)) {

			double y1 = values[indexToInterpolate];

			if (current == indexToInterpolate) {
				return y1;
			}

			long x = timestamps[current];
			long x1 = timestamps[indexToInterpolate];
			if (x == x1) {
				return y1;
			}
			int next = indexToInterpolate + iterators.length;
			double y2 = values[next];
			long x2 = timestamps[next];
			if (x == x2) {
				return y2;
			}

			switch(interpolationType){
			case LININT:
				interpolatedValue = (y2 - y1) / (x2 - x1) * (x - x1) + y1;
				break;
			case ZIMSUM:
				interpolatedValue = 0;
				break;
			default:
				throw new IllegalArgumentException("Invalid interpolation type specified");
			}
		}
		return interpolatedValue;
	}
251638
public function dump($value)
    {
        if (class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) {
            static $dumper = null;

            // re-use the same var-dumper instance, so it won't re-render the global styles/scripts on each dump.
            if (!$dumper) {
                $dumper = new HtmlDumper();

                $styles = array(
                    'default' => '',
                    'num' => '',
                    'const' => '',
                    'str' => '',
                    'note' => '',
                    'ref' => '',
                    'public' => '',
                    'protected' => '',
                    'private' => '',
                    'meta' => '',
                    'key' => '',
                    'index' => '',
                );
                $dumper->setStyles($styles);
            }

            $cloner = new VarCloner();
            return $dumper->dump($cloner->cloneVar($value));
        }
        return print_r($value, true);
    }
441146
public static function dump($data, $second = '')
    {
        if (static::isCli()) {
            $args = func_get_args();
            krumo::cli_dump($args);

            return true;
        }

        // If we're capturing call dump() with just data and capture the output
        if ($second === KRUMO_RETURN) {
            ob_start();

            static::dump($data);

            $str = ob_get_clean();

            return $str;
        // If we were given expand all, set the global variable
        } elseif ($second === KRUMO_EXPAND_ALL) {
            static::$expand_all = true;
            static::dump($data);

            return true;
        } elseif ($second === KRUMO_NO_SORT) {
            self::$sort = false;
            Krumo::dump($data);

            return true;
        } elseif ($second === KRUMO_SORT) {
            self::$sort = true;
            Krumo::dump($data);

            return true;
        }

        $clearObjectRecursionProtection   = false;
        if (static::$objectRecursionProtection === null) {
            static::$objectRecursionProtection = array();
            $clearObjectRecursionProtection  = true;
        }

        // disabled
        if (!static::_debug()) {
            return false;
        }

        // more arguments
        if (func_num_args() > 1) {
            $_ = func_get_args();
            $result = true;
            foreach ($_ as $d) {
                $result = $result && static::dump($d);
            }

            return $result;
        }

        // find caller
        $_ = debug_backtrace();
        while ($d = array_pop($_)) {
            $callback = static::$lineNumberTestCallback;
            $function = strToLower($d['function']);
            if (in_array($function, array("krumo","k","kd")) || (strToLower(@$d['class']) == 'krumo') || (is_callable($callback) && call_user_func($callback, $d))) {
                break;
            }
        }

        $showVersion  = static::_config('display', 'show_version', true);
        $showCallInfo = static::_config('display', 'show_call_info', true);
        $krumoUrl     = 'https://github.com/mmucklo/krumo';

        //////////////////////
        // Start HTML header//
        //////////////////////
        print "<div class=\"krumo-root\">\n";
        print "\t<ul class=\"krumo-node krumo-first\">\n";

        // The actual item itself
        static::_dump($data);

        if ($showVersion || $showCallInfo) {
            print "\t\t<li class=\"krumo-footnote\">\n";

            if ($showCallInfo && isset($d['file']) && $d['file']) {
                print "<span class=\"krumo-call\" style=\"white-space:nowrap;\">";
                print "Called from <strong><code>" . $d['file'] . "</code></strong>, ";
                print "line <strong><code>" . $d['line'] . "</code></strong></span>";
            }

            if ($showVersion) {
                $version = static::version();
                print "<span class=\"krumo-version\" style=\"white-space:nowrap;\">\n";
                print "<strong class=\"krumo-version-number\">Krumo version $version</strong> | <a href=\"$krumoUrl\" target=\"_blank\">$krumoUrl</a>\n";
                print "</span>\n";
            }

            print "</li>";
        }

        print "</ul></div>\n";
        print "<!-- Krumo - HTML -->\n\n";

        // Output the CSS and JavaScript AFTER the HTML
        static::_css();
        ////////////////////
        // End HTML header//
        ////////////////////

        // flee the hive
        $_recursion_marker = static::_marker();
        if ($hive =& static::_hive($dummy)) {
            foreach ($hive as $i => $bee) {
                if (is_object($bee)) {
                    if (($hash = spl_object_hash($bee)) && isset(static::$objectRecursionProtection[$hash])) {
                        unset(static::$objectRecursionProtection[$hash]);
                    }
                } elseif (isset($hive[$i]->$_recursion_marker)) {
                    unset($hive[$i][$_recursion_marker]);
                }
            }
        }

        if ($clearObjectRecursionProtection) {
            static::$objectRecursionProtection = null;
        }
        return true;
    }
1284597
function parse_interpol(value) {
    var items = [],
        pos = 0,
        next = 0,
        match;
    while (true) {
      // Match up to embedded string
      next = value.substr(pos).search(embedder);
      if (next < 0) {
        if (pos < value.length) {
          items.push(JSON.stringify(value.substr(pos)));
        }
        break;
      }
      items.push(JSON.stringify(value.substr(pos, next)));
      pos += next;

      // Match embedded string
      match = value.substr(pos).match(embedder);
      next = match[0].length;
      if (next < 0) { break; }
      items.push(match[1] || match[2]);
      pos += next;
    }
    return items.filter(function (part) { return part && part.length > 0}).join(" +\n");
  }
293454
public function convertToDatabaseValue($value, AbstractPlatform $platform)
	{
		if (is_null($value)) {
			return null;
		}
		
		$string = $value->getFullPath();
		
		return $string;
	}
765263
public function put($value)
    {
        $len = strlen($value);
        if ($len > 2147483647) {
            throw new \RuntimeException('value is too long');
        }
        $raw = pack('N', $len) . $value;
        $write_len = $this->pipe->write($raw);

        return $write_len == strlen($raw);
    }
1052147
public function interpolate($msg, array $args = array())
    {
        preg_match_all('/(?<!%)(?:%%)*%\\(([^\\)]*)\\)/', $msg, $matches);
        // Only define the variables if there are any.
        if (isset($matches[1][0])) {
            $args += array_combine(
                $matches[1],
                array_fill(0, count($matches[1]), null)
            );
        }

        if (!count($args)) {
            return $msg;
        }

        // Mapping = array(name => index)
        $keys       = array_keys($args);
        $mapping    = array_flip($keys);
        $keys       = array_map(
            function ($key) {
                return "%($key)";
            },
            $keys
        );
        $values     = array_map(
            function ($val) {
                return '%'.($val + 1).'$';
            },
            $mapping
        );
        $mapping    = array_combine($keys, $values);
        $msg        = strtr($msg, $mapping);
        return vsprintf($msg, array_values($args));
    }
686146
public static function formatForTitle($value = "", $delimiters=['-','_'])
    {
        // if value passed as empty or is not a string then return false
        if (!is_string($value) || strlen($value) === 0) {
            return false;
        }

        /** @var string $cache Cache Value */
        $cache = self::cacheString($value, $delimiters);

        // check for cache
        if (isset(static::$formatForTitleCache[$cache])) {
            return static::$formatForTitleCache[$cache];
        }

        // change underscores to spaces
        $stripDelimiters = str_replace($delimiters, array_fill(0, count($delimiters), ' '), $value);

        return static::$formatForTitleCache[$cache] = Strings::titleCase($stripDelimiters);
    }
1365419
public function dump($value) : string
    {
        if (! is_bool($value))
            throw new DumpException($this, $value, self::DUMP_ERROR);

        return $value ? 'true' : 'false';
    }
1333095
public static function dumpAsString($variable, $indentLevel = 0) {
        if (is_bool($variable)) {
            $result = $variable ? "true" : "false";
        } elseif (is_null($variable)) {
            $result = "null";
        } elseif (is_array($variable)) {
            $result = 'array (';

            foreach($variable as $key=>$item) {
                $result .= "\n". str_repeat(" ", ($indentLevel+1)*4);
                $result .= self::dumpAsString($key, $indentLevel+1);
                $result .= ' => ';
                $result .= self::dumpAsString($item, $indentLevel+1).',';
            }

            $result .= "\n".str_repeat(" ", ($indentLevel)*4).')';
        } elseif(is_string($variable) && (isset($variable[0]) && $variable[0] != '$')) {
            $result = '"'. (strpos($variable, '$__lv') === false ? str_replace('"', '\"', $variable) : $variable) .'"';
        } else {
            $result = $variable;
        }

        return $result;
    }
974905
public CommandLine setInterpolateVariables(boolean interpolate) {
        getCommandSpec().interpolateVariables(interpolate);
        for (CommandLine command : getCommandSpec().subcommands().values()) {
            command.setInterpolateVariables(interpolate);
        }
        return this;
    }