本文整理匯總了PHP中Nette\PhpGenerator\Helpers::format方法的典型用法代碼示例。如果您正苦於以下問題:PHP Helpers::format方法的具體用法?PHP Helpers::format怎麽用?PHP Helpers::format使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\PhpGenerator\Helpers
的用法示例。
在下文中一共展示了Helpers::format方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: afterCompile
public function afterCompile(ClassType $class)
{
$container = $this->getContainerBuilder();
$config = $this->getConfig($this->defaults);
if ($config['panel'] && $container->parameters['debugMode']) {
$init = $class->methods['initialize'];
$init->addBody(Helpers::format('Foowie\\Cron\\Diagnostics\\Panel::register($this->getByType(?), $this->getByType(?));', 'Foowie\\Cron\\ICron', 'Nette\\Http\\Request'));
}
}
示例2: afterCompile
public function afterCompile(Code\ClassType $class)
{
$container = $this->getContainerBuilder();
if ($eventManager = $container->getByType('Kdyby\\Events\\EventManager')) {
$methodName = 'createService' . ucfirst($this->name) . '__command';
$method = $class->methods[$methodName];
$body = explode(';', substr(trim($method->getBody()), 0, -1));
$return = array_pop($body);
$body[] = Code\Helpers::format(PHP_EOL . '$service->setEventManager($this->getService(?))', $eventManager);
$body[] = $return;
$method->setBody(implode(';', $body) . ';');
}
}
示例3: afterCompile
public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
$config = $this->getConfig($this->defaults);
Nette\Utils\Validators::assertField($config, 'enabled', 'boolean');
Nette\Utils\Validators::assertField($config, 'accessToken', 'string');
Nette\Utils\Validators::assertField($config, 'roomName', 'string');
Nette\Utils\Validators::assertField($config, 'filters', 'array');
if (!$config['enabled']) {
return;
}
unset($config['enabled']);
$init = $class->methods['initialize'];
$init->addBody(Nette\PhpGenerator\Helpers::format('
$logger = new Vysinsky\\HipChat\\Bridges\\Tracy\\Logger(?, ?, ?, ?);
Tracy\\Debugger::setLogger($logger);
', $config['accessToken'], $config['roomName'], $config['filters'], $config['linkFactory']));
}
示例4: processRepositoryFactoryEntities
protected function processRepositoryFactoryEntities(Code\ClassType $class)
{
if (empty($this->postCompileRepositoriesQueue)) {
return;
}
$dic = self::evalAndInstantiateContainer($class);
foreach ($this->postCompileRepositoriesQueue as $manager => $items) {
$config = $this->managerConfigs[$manager];
/** @var Kdyby\Doctrine\EntityManager $entityManager */
$entityManager = $dic->getService($this->configuredManagers[$manager]);
/** @var Doctrine\ORM\Mapping\ClassMetadata $entityMetadata */
$metadataFactory = $entityManager->getMetadataFactory();
$allMetadata = [];
foreach ($metadataFactory->getAllMetadata() as $entityMetadata) {
if ($config['defaultRepositoryClassName'] === $entityMetadata->customRepositoryClassName || empty($entityMetadata->customRepositoryClassName)) {
continue;
}
$allMetadata[ltrim($entityMetadata->customRepositoryClassName, '\\')] = $entityMetadata;
}
foreach ($items as $item) {
if (!isset($allMetadata[$item[0]])) {
throw new Nette\Utils\AssertionException(sprintf('Repository class %s have been found in DIC, but no entity has it assigned and it has no entity configured', $item[0]));
}
$entityMetadata = $allMetadata[$item[0]];
$serviceMethod = Nette\DI\Container::getMethodName($item[1]);
$method = $class->getMethod($serviceMethod);
$methodBody = $method->getBody();
$method->setBody(str_replace('"%entityName%"', Code\Helpers::format('?', $entityMetadata->getName()), $methodBody));
}
}
}
示例5: __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();
}
示例6: afterCompile
public function afterCompile(Code\ClassType $class)
{
$init = $class->methods['initialize'];
/** @hack This tries to add the event invokation right after the code, generated by NetteExtension. */
$foundNetteInitStart = $foundNetteInitEnd = FALSE;
$lines = explode(";\n", trim($init->body));
$init->body = NULL;
while (($line = array_shift($lines)) || $lines) {
if ($foundNetteInitStart && !$foundNetteInitEnd && stripos($line, 'Nette\\') === FALSE && stripos($line, 'set_include_path') === FALSE && stripos($line, 'date_default_timezone_set') === FALSE) {
$init->addBody(Code\Helpers::format('$this->getService(?)->createEvent(?)->dispatch($this);', $this->prefix('manager'), array('Nette\\DI\\Container', 'onInitialize')));
$foundNetteInitEnd = TRUE;
}
if (!$foundNetteInitEnd && (stripos($line, 'Nette\\') !== FALSE || stripos($line, 'set_include_path') !== FALSE || stripos($line, 'date_default_timezone_set') !== FALSE)) {
$foundNetteInitStart = TRUE;
}
$init->addBody($line . ';');
}
if (!$foundNetteInitEnd) {
$init->addBody(Code\Helpers::format('$this->getService(?)->createEvent(?)->dispatch($this);', $this->prefix('manager'), array('Nette\\DI\\Container', 'onInitialize')));
}
}
示例7: compilePhpCache
/**
* @param Translator $translator
* @param MessageCatalogueInterface[] $availableCatalogues
* @param string $locale
* @return string
*/
protected function compilePhpCache(Translator $translator, array &$availableCatalogues, $locale)
{
$fallbackContent = '';
$current = new Code\PhpLiteral('');
foreach ($this->fallbackResolver->compute($translator, $locale) as $fallback) {
$fallbackSuffix = new Code\PhpLiteral(ucfirst(preg_replace('~[^a-z0-9_]~i', '_', $fallback)));
$fallbackContent .= Code\Helpers::format(<<<EOF
\$catalogue? = new MessageCatalogue(?, ?);
\$catalogue?->addFallbackCatalogue(\$catalogue?);
EOF
, $fallbackSuffix, $fallback, $availableCatalogues[$fallback]->all(), $current, $fallbackSuffix);
$current = $fallbackSuffix;
}
$content = Code\Helpers::format(<<<EOF
use Kdyby\\Translation\\MessageCatalogue;
\$catalogue = new MessageCatalogue(?, ?);
?
return \$catalogue;
EOF
, $locale, $availableCatalogues[$locale]->all(), new Code\PhpLiteral($fallbackContent));
return '<?php' . "\n\n" . $content;
}
示例8: doSerializeValueResolve
private function doSerializeValueResolve(ContainerBuilder $builder, $expression)
{
if ($expression instanceof Code\PhpLiteral) {
$expression = self::resolveExpression($expression);
} elseif (substr($expression, 0, 1) === '%') {
$expression = $builder->expand($expression);
} elseif (substr($expression, 0, 1) === '$') {
$expression = new Code\PhpLiteral($expression);
} else {
if (!($m = self::shiftAccessPath($expression))) {
return $expression;
// it's probably some kind of expression
} else {
if ($m['context'] === 'this') {
$targetObject = '$this';
} elseif ($m['context'] === 'context' && ($p = self::shiftAccessPath($m['path']))) {
if (class_exists($p['context']) || interface_exists($p['context'])) {
$targetObject = Code\Helpers::format('$this->_kdyby_aopContainer->getByType(?)', $p['context']);
} else {
$targetObject = Code\Helpers::format('$this->_kdyby_aopContainer->getService(?)', $p['context']);
}
$m['path'] = $p['path'];
} else {
throw new Kdyby\Aop\NotImplementedException();
}
$expression = Code\Helpers::format('PropertyAccess::createPropertyAccessor()->getValue(?, ?)', new Code\PhpLiteral($targetObject), $m['path']);
}
$expression = new Code\PhpLiteral($expression);
}
return $expression;
}