当前位置: 首页>>代码示例>>PHP>>正文


PHP Strings::indent方法代码示例

本文整理汇总了PHP中Nette\Utils\Strings::indent方法的典型用法代码示例。如果您正苦于以下问题:PHP Strings::indent方法的具体用法?PHP Strings::indent怎么用?PHP Strings::indent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nette\Utils\Strings的用法示例。


在下文中一共展示了Strings::indent方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __toString

 /**
  * @return string  PHP code
  */
 public function __toString()
 {
     $parameters = array();
     foreach ($this->parameters as $param) {
         $variadic = $this->variadic && $param === end($this->parameters);
         $hint = in_array($param->getTypeHint(), array('array', '')) ? $param->getTypeHint() : ($this->namespace ? $this->namespace->unresolveName($param->getTypeHint()) : $param->getTypeHint());
         $parameters[] = ($hint ? $hint . ' ' : '') . ($param->isReference() ? '&' : '') . ($variadic ? '...' : '') . '$' . $param->getName() . ($param->isOptional() && !$variadic ? ' = ' . Helpers::dump($param->defaultValue) : '');
     }
     $uses = array();
     foreach ($this->uses as $param) {
         $uses[] = ($param->isReference() ? '&' : '') . '$' . $param->getName();
     }
     return ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . ($this->visibility ? $this->visibility . ' ' : '') . ($this->static ? 'static ' : '') . 'function' . ($this->returnReference ? ' &' : '') . ($this->name ? ' ' . $this->name : '') . '(' . implode(', ', $parameters) . ')' . ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '') . ($this->abstract || $this->body === FALSE ? ';' : ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(trim($this->body), 1) . "\n}");
 }
开发者ID:re1la2pse,项目名称:GromesProjekt,代码行数:17,代码来源:Method.php

示例2: createGrid

 protected function createGrid()
 {
     $context = $this->getItems();
     $grid = $this->createPreparedGrid();
     $grid->setModel($context);
     $grid->addColumnNumber('id', 'ID')->setSortable()->setFilterNumber();
     $grid->addColumnText('name', 'Název')->setCustomRender(function ($row) {
         return Strings::indent($row['name'], $row['level'] * 5, ' ');
     })->setSortable()->setFilterText();
     $grid->addColumnText('type_name', 'Typ');
     $activeCol = $grid->addColumnText('show', 'Zobrazit');
     $this->helpers->setupAsBool($activeCol);
     $grid->addActionEvent('left', '<', $this->clickLeft);
     $grid->addActionEvent('right', '>', $this->clickRight);
     $grid->addActionEvent('up', '/\\', $this->clickUp);
     $grid->addActionEvent('down', '\\/', $this->clickDown);
     $grid->addActionHref('add', 'Add');
     $this->helpers->addEditAction($grid);
     $this->helpers->addDeleteEvent($grid, $this->deleteRow);
     return $grid;
 }
开发者ID:kysela-petr,项目名称:generator-kysela,代码行数:21,代码来源:MenuGrid.php

示例3: __toString

 /** @return string  PHP code */
 public function __toString()
 {
     $consts = array();
     foreach ($this->consts as $name => $value) {
         $consts[] = "const {$name} = " . Helpers::dump($value) . ";\n";
     }
     $properties = array();
     foreach ($this->properties as $property) {
         $properties[] = ($property->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $property->documents)) . "\n */\n" : '') . $property->visibility . ($property->static ? ' static' : '') . ' $' . $property->name . ($property->value === null ? '' : ' = ' . Helpers::dump($property->value)) . ";\n";
     }
     return Nette\Utils\Strings::normalize(($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . $this->type . ' ' . $this->name . ' ' . ($this->extends ? 'extends ' . implode(', ', (array) $this->extends) . ' ' : '') . ($this->implements ? 'implements ' . implode(', ', (array) $this->implements) . ' ' : '') . "\n{\n\n" . Nette\Utils\Strings::indent(($this->traits ? "use " . implode(', ', (array) $this->traits) . ";\n\n" : '') . ($this->consts ? implode('', $consts) . "\n\n" : '') . ($this->properties ? implode("\n", $properties) . "\n\n" : '') . implode("\n\n\n", $this->methods), 1) . "\n\n}") . "\n";
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:13,代码来源:ClassType.php

示例4: __toString

 /**
  * @return string  PHP code
  */
 public function __toString()
 {
     $consts = array();
     foreach ($this->consts as $name => $value) {
         $consts[] = "const {$name} = " . Helpers::dump($value) . ";\n";
     }
     $properties = array();
     foreach ($this->properties as $property) {
         $doc = str_replace("\n", "\n * ", implode("\n", $property->getDocuments()));
         $properties[] = ($property->getDocuments() ? strpos($doc, "\n") === FALSE ? "/** {$doc} */\n" : "/**\n * {$doc}\n */\n" : '') . $property->getVisibility() . ($property->isStatic() ? ' static' : '') . ' $' . $property->getName() . ($property->value === NULL ? '' : ' = ' . Helpers::dump($property->value)) . ";\n";
     }
     $namespace = $this->namespace;
     $mapper = function (array $arr) use($namespace) {
         return $namespace ? array_map(array($namespace, 'unresolveName'), $arr) : $arr;
     };
     return Strings::normalize(($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . $this->type . ' ' . $this->name . ' ' . ($this->extends ? 'extends ' . implode(', ', $mapper((array) $this->extends)) . ' ' : '') . ($this->implements ? 'implements ' . implode(', ', $mapper($this->implements)) . ' ' : '') . "\n{\n" . Strings::indent(($this->traits ? 'use ' . implode(";\nuse ", $mapper($this->traits)) . ";\n\n" : '') . ($this->consts ? implode('', $consts) . "\n" : '') . ($this->properties ? implode("\n", $properties) . "\n" : '') . ($this->methods ? "\n" . implode("\n\n\n", $this->methods) . "\n\n" : ''), 1) . '}') . "\n";
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:20,代码来源:ClassType.php

示例5: formatBody

 public function formatBody($body, $request = TRUE)
 {
     if (empty($body)) {
         return '';
     }
     $body = $this->tryFormatJson($body, $request);
     $result = Strings::indent($body, 8, ' ');
     $result = Strings::indent("+ Body" . PHP_EOL . PHP_EOL . $result, 4, ' ');
     return PHP_EOL . $result;
 }
开发者ID:kdyby,项目名称:tester-extras,代码行数:10,代码来源:HttpLogger.php

示例6: __toString

 /**
  * @return string  PHP code
  */
 public function __toString()
 {
     $consts = array();
     foreach ($this->consts as $name => $value) {
         $consts[] = "const {$name} = " . Helpers::dump($value) . ";\n";
     }
     $properties = array();
     foreach ($this->properties as $property) {
         $doc = str_replace("\n", "\n * ", implode("\n", (array) $property->getDocuments()));
         $properties[] = ($property->getDocuments() ? strpos($doc, "\n") === FALSE ? "/** {$doc} */\n" : "/**\n * {$doc}\n */\n" : '') . $property->getVisibility() . ($property->isStatic() ? ' static' : '') . ' $' . $property->getName() . ($property->value === NULL ? '' : ' = ' . Helpers::dump($property->value)) . ";\n";
     }
     $extends = $implements = $traits = array();
     if ($this->namespace) {
         foreach ((array) $this->extends as $name) {
             $extends[] = $this->namespace->unresolveName($name);
         }
         foreach ((array) $this->implements as $name) {
             $implements[] = $this->namespace->unresolveName($name);
         }
         foreach ((array) $this->traits as $name) {
             $traits[] = $this->namespace->unresolveName($name);
         }
     } else {
         $extends = (array) $this->extends;
         $implements = (array) $this->implements;
         $traits = (array) $this->traits;
     }
     foreach ($this->methods as $method) {
         $method->setNamespace($this->namespace);
     }
     return Strings::normalize(($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . $this->type . ' ' . $this->name . ' ' . ($this->extends ? 'extends ' . implode(', ', $extends) . ' ' : '') . ($this->implements ? 'implements ' . implode(', ', $implements) . ' ' : '') . "\n{\n\n" . Strings::indent(($this->traits ? 'use ' . implode(', ', $traits) . ";\n\n" : '') . ($this->consts ? implode('', $consts) . "\n\n" : '') . ($this->properties ? implode("\n", $properties) . "\n\n" : '') . implode("\n\n\n", $this->methods), 1) . "\n\n}") . "\n";
 }
开发者ID:jave007,项目名称:test,代码行数:35,代码来源:ClassType.php

示例7: __toString

 /**
  * @return string PHP code
  */
 public function __toString() : string
 {
     $uses = [];
     asort($this->uses);
     foreach ($this->uses as $alias => $name) {
         $useNamespace = Helpers::extractNamespace($name);
         if ($this->name !== $useNamespace) {
             if ($alias === $name || substr($name, -(strlen($alias) + 1)) === '\\' . $alias) {
                 $uses[] = "use {$name};";
             } else {
                 $uses[] = "use {$name} as {$alias};";
             }
         }
     }
     $body = ($uses ? implode("\n", $uses) . "\n\n" : '') . implode("\n", $this->classes);
     if ($this->bracketedSyntax) {
         return 'namespace' . ($this->name ? ' ' . $this->name : '') . " {\n\n" . Strings::indent($body) . "\n}\n";
     } else {
         return ($this->name ? "namespace {$this->name};\n\n" : '') . $body;
     }
 }
开发者ID:kukulich,项目名称:php-generator,代码行数:24,代码来源:PhpNamespace.php

示例8: indent

 /**
  * Indents the HTML content from the left.
  * @param  string UTF-8 encoding or 8-bit
  * @param  int
  * @param  string
  * @return string
  */
 public static function indent($s, $level = 1, $chars = "\t")
 {
     if ($level >= 1) {
         $s = Strings::replace($s, '#<(textarea|pre).*?</\\1#si', function ($m) {
             return strtr($m[0], " \t\r\n", "");
         });
         $s = Strings::indent($s, $level, $chars);
         $s = strtr($s, "", " \t\r\n");
     }
     return $s;
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:18,代码来源:Helpers.php

示例9: __toString

 /** @return string  PHP code */
 public function __toString()
 {
     $parameters = array();
     foreach ($this->parameters as $param) {
         $parameters[] = ($param->typeHint ? $param->typeHint . ' ' : '') . ($param->reference ? '&' : '') . '$' . $param->name . ($param->optional ? ' = ' . Helpers::dump($param->defaultValue) : '');
     }
     $uses = array();
     foreach ($this->uses as $param) {
         $uses[] = ($param->reference ? '&' : '') . '$' . $param->name;
     }
     return ($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . ($this->visibility ? $this->visibility . ' ' : '') . ($this->static ? 'static ' : '') . 'function' . ($this->returnReference ? ' &' : '') . ($this->name ? ' ' . $this->name : '') . '(' . implode(', ', $parameters) . ')' . ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '') . ($this->abstract || $this->body === FALSE ? ';' : ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(trim($this->body), 1) . "\n}");
 }
开发者ID:anagio,项目名称:woocommerce,代码行数:13,代码来源:Method.php

示例10: __toString

 /**
  * @return string
  */
 public function __toString()
 {
     $this->setBody('');
     if (strtolower($this->getName()) === '__construct') {
         $this->addParameter('_kdyby_aopContainer')->setTypeHint('\\Nette\\DI\\Container');
         $this->addBody('$this->_kdyby_aopContainer = $_kdyby_aopContainer;');
     }
     $this->addBody('$__arguments = func_get_args(); $__exception = $__result = NULL;');
     if ($this->before) {
         foreach ($this->before as $before) {
             $this->addBody($before);
         }
     }
     if ($this->afterThrowing || $this->after) {
         $this->addBody('try {');
     }
     if (!$this->around) {
         $parentCall = Code\Helpers::format('$__result = call_user_func_array("parent::?", $__arguments);', $this->getName());
     } else {
         $parentCall = Code\Helpers::format('$__around = new \\Kdyby\\Aop\\JoinPoint\\AroundMethod($this, __FUNCTION__, $__arguments);');
         foreach ($this->around as $around) {
             $parentCall .= "\n" . $around;
         }
         $parentCall .= "\n" . Code\Helpers::format('$__result = $__around->proceed();');
     }
     $this->addBody($this->afterThrowing || $this->after ? Nette\Utils\Strings::indent($parentCall) : $parentCall);
     if ($this->afterThrowing || $this->after) {
         $this->addBody('} catch (\\Exception $__exception) {');
     }
     if ($this->afterThrowing) {
         foreach ($this->afterThrowing as $afterThrowing) {
             $this->addBody(Nette\Utils\Strings::indent($afterThrowing));
         }
     }
     if ($this->afterThrowing || $this->after) {
         $this->addBody('}');
     }
     if ($this->afterReturning) {
         if ($this->afterThrowing || $this->after) {
             $this->addBody('if (empty($__exception)) {');
         }
         foreach ($this->afterReturning as $afterReturning) {
             $this->addBody($this->afterThrowing || $this->after ? Nette\Utils\Strings::indent($afterReturning) : $afterReturning);
         }
         if ($this->afterThrowing || $this->after) {
             $this->addBody('}');
         }
     }
     if ($this->after) {
         foreach ($this->after as $after) {
             $this->addBody($after);
         }
     }
     if ($this->afterThrowing || $this->after) {
         $this->addBody('if ($__exception) { throw $__exception; }');
     }
     $this->addBody('return $__result;');
     return parent::__toString();
 }
开发者ID:kdyby,项目名称:aop,代码行数:62,代码来源:PointcutMethod.php

示例11: __toString

 /**
  * @return string  PHP code
  */
 public function __toString() : string
 {
     $parameters = [];
     foreach ($this->parameters as $param) {
         $variadic = $this->variadic && $param === end($this->parameters);
         $hint = $this->namespace ? $this->namespace->unresolveName((string) $param->getTypeHint()) : $param->getTypeHint();
         $parameters[] = ($hint ? $hint . ' ' : '') . ($param->isReference() ? '&' : '') . ($variadic ? '...' : '') . '$' . $param->getName() . ($param->isOptional() && !$variadic ? ' = ' . Helpers::dump($param->defaultValue) : '');
     }
     $uses = [];
     foreach ($this->uses as $param) {
         $uses[] = ($param->isReference() ? '&' : '') . '$' . $param->getName();
     }
     $returnType = $this->namespace ? $this->namespace->unresolveName((string) $this->returnType) : $this->returnType;
     return ($this->comment ? str_replace("\n", "\n * ", "/**\n" . $this->comment) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . ($this->visibility ? $this->visibility . ' ' : '') . ($this->static ? 'static ' : '') . 'function' . ($this->returnReference ? ' &' : '') . ' ' . $this->name . '(' . implode(', ', $parameters) . ')' . ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '') . ($returnType ? ': ' . $returnType : '') . ($this->abstract || $this->body === FALSE ? ';' : ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(ltrim(rtrim($this->body) . "\n"), 1) . '}');
 }
开发者ID:kukulich,项目名称:php-generator,代码行数:18,代码来源:Method.php

示例12: onGenerate

 public function onGenerate(AbstractMetaSpec $spec, MetaSpecMatcher $matcher, Type $type, ClassType $class)
 {
     $ns = $class->getNamespace();
     $ns->addUse("Skrz\\Meta\\XML\\XmlMetaInterface");
     $ns->addUse($type->getName(), null, $typeAlias);
     $class->addImplement("Skrz\\Meta\\XML\\XmlMetaInterface");
     $groups = array();
     $i = 0;
     $valueGroupIdMask = 0;
     foreach ($type->getProperties() as $property) {
         foreach ($property->getAnnotations("Skrz\\Meta\\XML\\XmlAnnotationInterface") as $xmlAnnotation) {
             /** @var XmlAnnotationInterface $xmlAnnotation */
             if (!isset($groups[$xmlAnnotation->getGroup()])) {
                 $groups[$xmlAnnotation->getGroup()] = 1 << $i++;
             }
             if ($xmlAnnotation instanceof XmlValue) {
                 $valueGroupIdMask |= $groups[$xmlAnnotation->getGroup()];
             }
         }
     }
     $class->addProperty("xmlGroups", $groups)->setStatic(true);
     // fromXml()
     $fromXml = $class->addMethod("fromXml");
     $fromXml->setStatic(true);
     $fromXml->addParameter("xml");
     $fromXml->addParameter("group")->setOptional(true);
     $fromXml->addParameter("object")->setOptional(true);
     $fromXml->addComment("Creates \\{$type->getName()} from XML")->addComment("")->addComment("@param \\XMLReader|\\DOMElement \$xml")->addComment("@param string \$group")->addComment("@param {$typeAlias} \$object")->addComment("")->addComment("@throws \\InvalidArgumentException")->addComment("")->addComment("@return {$typeAlias}");
     $fromXml->addBody("if (!isset(self::\$xmlGroups[\$group])) {")->addBody("\tthrow new \\InvalidArgumentException('Group \\'' . \$group . '\\' not supported for ' . " . var_export($type->getName(), true) . " . '.');")->addBody("} else {")->addBody("\t\$id = self::\$xmlGroups[\$group];")->addBody("}")->addBody("")->addBody("if (\$object === null) {")->addBody("\t\$object = new {$typeAlias}();")->addBody("} elseif (!(\$object instanceof {$typeAlias})) {")->addBody("\tthrow new \\InvalidArgumentException('You have to pass object of class {$type->getName()}.');")->addBody("}")->addBody("")->addBody("if (\$xml instanceof \\XMLReader) {")->addBody("\treturn self::fromXmlReader(\$xml, \$group, \$id, \$object);")->addBody("} elseif (\$xml instanceof \\DOMElement) {")->addBody("\treturn self::fromXmlElement(\$xml, \$group, \$id, \$object);")->addBody("} else {")->addBody("\tthrow new \\InvalidArgumentException('Expected XMLReader or DOMElement, got ' . gettype(\$xml) . (is_object(\$xml) ? ' of class ' . get_class(\$xml) : '') . '.');")->addBody("}");
     $fromXmlReader = $class->addMethod("fromXmlReader");
     $fromXmlReader->setStatic(true)->setVisibility("private");
     $fromXmlReader->addParameter("xml")->setTypeHint("\\XMLReader");
     $fromXmlReader->addParameter("group");
     $fromXmlReader->addParameter("id");
     $fromXmlReader->addParameter("object")->setTypeHint($type->getName());
     $fromXmlReader->addBody("if (\$xml->nodeType !== \\XMLReader::ELEMENT) {")->addBody("\tthrow new \\InvalidArgumentException('Expects XMLReader to be positioned on ELEMENT node.');")->addBody("}")->addBody("");
     $attributesByName = array();
     foreach ($type->getProperties() as $property) {
         foreach ($property->getAnnotations("Skrz\\Meta\\XML\\XmlAttribute") as $xmlAttribute) {
             /** @var XmlAttribute $xmlAttribute */
             $groupId = $groups[$xmlAttribute->group];
             $name = strtolower($xmlAttribute->name);
             if (!isset($attributesByName[$name])) {
                 $attributesByName[$name] = "";
             }
             $attributesByName[$name] .= "if ((\$id & {$groupId}) > 0 && \$xml->namespaceURI === " . var_export($xmlAttribute->namespace, true) . ") {\n";
             $attributesByName[$name] .= Strings::indent($this->assignObjectProperty($xmlAttribute, $property, "\$xml->value"), 1, "\t") . "\n";
             $attributesByName[$name] .= "}\n";
         }
     }
     if (!empty($attributesByName)) {
         $fromXmlReader->addBody("if (\$xml->moveToFirstAttribute()) {")->addBody("\tdo {")->addBody("\t\tswitch (strtolower(\$xml->localName)) {");
         $i = 0;
         foreach ($attributesByName as $name => $code) {
             $fromXmlReader->addBody("\t\t\tcase " . var_export($name, true) . ":")->addBody(Strings::indent($code, 4, "\t"))->addBody("\t\t\t\tbreak;");
             if ($i < count($attributesByName) - 1) {
                 $fromXmlReader->addBody("");
             }
             ++$i;
         }
         $fromXmlReader->addBody("\t\t}")->addBody("\t} while (\$xml->moveToNextAttribute());")->addBody("")->addBody("\t\$xml->moveToElement();")->addBody("}")->addBody("");
     }
     $fromXmlReader->addBody("if ((\$id & {$valueGroupIdMask}) > 0) {");
     $valueCount = 0;
     foreach ($type->getProperties() as $property) {
         foreach ($property->getAnnotations("Skrz\\Meta\\XML\\XmlValue") as $xmlValue) {
             /** @var XmlValue $xmlValue */
             $groupId = $groups[$xmlValue->group];
             $fromXmlReader->addBody("\tif ((\$id & {$groupId}) > 0) {")->addBody("\t\t\$value = self::xmlReadValue(\$xml);")->addBody(Strings::indent($this->assignObjectProperty($xmlValue, $property, "\$value"), 2, "\t"))->addBody("\t}")->addBody("");
             ++$valueCount;
         }
     }
     if (!$valueCount) {
         $fromXmlReader->addBody("\t// @XmlValue not specified");
     }
     $fromXmlReader->addBody("} else {");
     $elementsByName = array();
     $endElementsByName = array();
     $wrappers = [];
     foreach ($type->getProperties() as $property) {
         foreach ($property->getAnnotations("Skrz\\Meta\\XML\\XmlElementWrapper") as $xmlElementWrapper) {
             /** @var XmlElementWrapper $xmlElementWrapper */
             $groupId = $groups[$xmlElementWrapper->group];
             $name = strtolower($xmlElementWrapper->name);
             $wrapperId = $xmlElementWrapper->group . ":" . $property->getName();
             if (!isset($wrappers[$wrapperId])) {
                 $wrappers[$wrapperId] = 1 << count($wrappers);
             }
             if (!isset($elementsByName[$name])) {
                 $elementsByName[$name] = "";
             }
             $elementsByName[$name] .= "if ((\$id & {$groupId}) > 0 && \$xml->namespaceURI === " . var_export($xmlElementWrapper->namespace, true) . " && \$depth === 2) {\n";
             $elementsByName[$name] .= "\t\$wrapped |= {$wrappers[$wrapperId]};\n";
             $elementsByName[$name] .= "}\n";
             if (!isset($endElementsByName[$name])) {
                 $endElementsByName[$name] = "";
             }
             $endElementsByName[$name] .= "if ((\$id & {$groupId}) > 0 && \$xml->namespaceURI === " . var_export($xmlElementWrapper->namespace, true) . " && \$depth === 2) {\n";
             $endElementsByName[$name] .= "\t\$wrapped &= ~{$wrappers[$wrapperId]};\n";
             $endElementsByName[$name] .= "}\n";
//.........这里部分代码省略.........
开发者ID:jakubkulhan,项目名称:meta,代码行数:101,代码来源:XmlModule.php

示例13: indent

	/**
	 * Indents the HTML content from the left.
	 * @param  string UTF-8 encoding or 8-bit
	 * @param  int
	 * @param  string
	 * @return string
	 */
	public static function indent($s, $level = 1, $chars = "\t")
	{
		if ($level >= 1) {
			$s = Strings::replace($s, '#<(textarea|pre).*?</\\1#si', /*5.2* callback(*/function($m) {
				return strtr($m[0], " \t\r\n", "\x1F\x1E\x1D\x1A");
			}/*5.2* )*/);
			$s = Strings::indent($s, $level, $chars);
			$s = strtr($s, "\x1F\x1E\x1D\x1A", " \t\r\n");
		}
		return $s;
	}
开发者ID:norbe,项目名称:nette,代码行数:18,代码来源:DefaultHelpers.php

示例14: onGenerate


//.........这里部分代码省略.........
         $from->addComment("Creates \\{$type->getName()} object from " . strtolower($what))->addComment("")->addComment("@param " . strtolower($what) . " \$input")->addComment("@param string \$group")->addComment("@param {$inputOutputTypeHint} \$object")->addComment("")->addComment("@throws \\Exception")->addComment("")->addComment("@return {$inputOutputTypeHint}");
         if ($what === "Object") {
             $from->addBody("\$input = (array)\$input;\n");
         }
         // TODO: more groups - include/exclude
         $from->addBody("if (!isset(self::\$groups[\$group])) {")->addBody("\tthrow new \\InvalidArgumentException('Group \\'' . \$group . '\\' not supported for ' . " . var_export($type->getName(), true) . " . '.');")->addBody("} else {")->addBody("\t\$id = self::\$groups[\$group];")->addBody("}")->addBody("");
         if (!empty($discriminatorMetaMap)) {
             foreach ($discriminatorMetaMap as $groupId => $groupDiscriminatorMetaMap) {
                 if (isset($discriminatorOffsetMap[$groupId])) {
                     $groupDiscriminatorOffset = $discriminatorOffsetMap[$groupId];
                     foreach ($groupDiscriminatorMetaMap as $value => $metaClass) {
                         $ns->addUse($metaClass, null, $alias);
                         $from->addBody("if ((\$id & {$groupId}) > 0 && " . "isset(\$input[" . var_export($groupDiscriminatorOffset, true) . "]) && " . "\$input[" . var_export($groupDiscriminatorOffset, true) . "] === " . var_export($value, true) . ") {")->addBody("\treturn {$alias}::from{$what}(\$input, \$group, \$object);")->addBody("}")->addBody("");
                     }
                 } else {
                     foreach ($groupDiscriminatorMetaMap as $value => $metaClass) {
                         $ns->addUse($metaClass, null, $alias);
                         $from->addBody("if ((\$id & {$groupId}) > 0 && " . "isset(\$input[" . var_export($value, true) . "])) {")->addBody("\treturn {$alias}::from{$what}(\$input[" . var_export($value, true) . "], \$group, \$object);")->addBody("}")->addBody("");
                     }
                 }
             }
         }
         $from->addBody("if (\$object === null) {")->addBody("\t\$object = new {$typeAlias}();")->addBody("} elseif (!(\$object instanceof {$typeAlias})) {")->addBody("\tthrow new \\InvalidArgumentException('You have to pass object of class {$type->getName()}.');")->addBody("}")->addBody("");
         foreach ($type->getProperties() as $property) {
             foreach ($property->getAnnotations("Skrz\\Meta\\PHP\\PhpArrayOffset") as $arrayOffset) {
                 /** @var PhpArrayOffset $arrayOffset */
                 $groupId = $groups[$arrayOffset->group];
                 $arrayKey = var_export($arrayOffset->offset, true);
                 $baseArrayPath = $arrayPath = "\$input[{$arrayKey}]";
                 $baseObjectPath = $objectPath = "\$object->{$property->getName()}";
                 $from->addBody("if ((\$id & {$groupId}) > 0 && isset({$arrayPath})) {");
                 // FIXME: group group IDs by offset
                 $baseType = $property->getType();
                 $indent = "\t";
                 $before = "";
                 $after = "";
                 for ($i = 0; $baseType instanceof ArrayType; ++$i) {
                     $arrayType = $baseType;
                     $baseType = $arrayType->getBaseType();
                     $before .= "{$indent}if (!(isset({$objectPath}) && is_array({$objectPath}))) {\n";
                     $before .= "{$indent}\t{$objectPath} = array();\n";
                     $before .= "{$indent}}\n";
                     $before .= "{$indent}foreach ({$arrayPath} instanceof \\Traversable ? {$arrayPath} : (array){$arrayPath} as \$k{$i} => \$v{$i}) {\n";
                     $after = "{$indent}}\n" . $after;
                     $indent .= "\t";
                     $arrayPath = "\$v{$i}";
                     $objectPath .= "[\$k{$i}]";
                 }
                 if (!empty($before)) {
                     $from->addBody(rtrim($before));
                 }
                 $matchingPropertySerializer = $this->getMatchingPropertySerializer($property, $arrayOffset);
                 if ($matchingPropertySerializer !== null) {
                     $sevo = $matchingPropertySerializer->deserialize($property, $arrayOffset->group, $arrayPath);
                     if ($sevo->getStatement()) {
                         $from->addBody(Strings::indent($sevo->getStatement(), 1, $indent));
                     }
                     $from->addBody("{$indent}{$objectPath} = {$sevo->getExpression()};");
                 } elseif ($baseType instanceof ScalarType) {
                     $from->addBody("{$indent}{$objectPath} = {$arrayPath};");
                 } elseif ($baseType instanceof Type) {
                     $propertyTypeMetaClassName = $spec->createMetaClassName($baseType);
                     $ns->addUse($propertyTypeMetaClassName, null, $propertyTypeMetaClassNameAlias);
                     $from->addBody("{$indent}{$objectPath} = {$propertyTypeMetaClassNameAlias}::from{$what}(" . "{$arrayPath}, " . "\$group, " . "isset({$objectPath}) ? {$objectPath} : null" . ");");
                 } else {
                     throw new MetaException("Unsupported property type " . get_class($baseType) . " ({$type->getName()}::\${$property->getName()}).");
开发者ID:jakubkulhan,项目名称:meta,代码行数:67,代码来源:PhpModule.php


注:本文中的Nette\Utils\Strings::indent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。