本文整理匯總了PHP中Nette\PhpGenerator\Helpers::isIdentifier方法的典型用法代碼示例。如果您正苦於以下問題:PHP Helpers::isIdentifier方法的具體用法?PHP Helpers::isIdentifier怎麽用?PHP Helpers::isIdentifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\PhpGenerator\Helpers
的用法示例。
在下文中一共展示了Helpers::isIdentifier方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: generate
/**
* Generates PHP classes. First class is the container.
* @return Nette\PhpGenerator\ClassType[]
*/
public function generate($className)
{
$this->builder->complete();
$this->generatedClasses = [];
$this->className = $className;
$containerClass = $this->generatedClasses[] = new Nette\PhpGenerator\ClassType($this->className);
$containerClass->setExtends(Container::class);
$containerClass->addMethod('__construct')->addBody('parent::__construct(?);', [$this->builder->parameters]);
$definitions = $this->builder->getDefinitions();
ksort($definitions);
$meta = $containerClass->addProperty('meta')->setVisibility('protected')->setValue([Container::TYPES => $this->builder->getClassList()]);
foreach ($definitions as $name => $def) {
$meta->value[Container::SERVICES][$name] = $def->getClass() ?: NULL;
foreach ($def->getTags() as $tag => $value) {
$meta->value[Container::TAGS][$tag][$name] = $value;
}
}
foreach ($definitions as $name => $def) {
try {
$name = (string) $name;
$methodName = Container::getMethodName($name);
if (!PhpHelpers::isIdentifier($methodName)) {
throw new ServiceCreationException('Name contains invalid characters.');
}
$containerClass->addMethod($methodName)->addComment('@return ' . ($def->getImplement() ?: $def->getClass()))->setBody($name === ContainerBuilder::THIS_CONTAINER ? 'return $this;' : $this->generateService($name))->setParameters($def->getImplement() ? [] : $this->convertParameters($def->parameters));
} catch (\Exception $e) {
throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), 0, $e);
}
}
$aliases = $this->builder->getAliases();
ksort($aliases);
$meta->value[Container::ALIASES] = $aliases;
return $this->generatedClasses;
}
示例2: afterCompile
public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
$initialize = $class->getMethod('initialize');
$container = $this->getContainerBuilder();
if ($this->debugMode && $this->config['debugger']) {
$initialize->addBody($container->formatPhp('?;', array(new Nette\DI\Statement('@Tracy\\Bar::addPanel', array(new Nette\DI\Statement('Nette\\Bridges\\DITracy\\ContainerPanel'))))));
}
foreach (array_filter($container->findByTag('run')) as $name => $on) {
$initialize->addBody('$this->getService(?);', array($name));
}
if (!empty($this->config['accessors'])) {
$definitions = $container->getDefinitions();
ksort($definitions);
foreach ($definitions as $name => $def) {
if (Nette\PhpGenerator\Helpers::isIdentifier($name)) {
$type = $def->getImplement() ?: $def->getClass();
$class->addDocument("@property {$type} \${$name}");
}
}
}
}
示例3: afterCompile
public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
$initialize = $class->methods['initialize'];
$container = $this->getContainerBuilder();
$config = $this->getConfig($this->defaults);
// debugger
foreach (array('email', 'editor', 'browser', 'strictMode', 'maxLen', 'maxDepth', 'showLocation', 'scream') as $key) {
if (isset($config['debugger'][$key])) {
$initialize->addBody('Nette\\Diagnostics\\Debugger::$? = ?;', array($key, $config['debugger'][$key]));
}
}
if ($container->parameters['debugMode']) {
if ($config['container']['debugger']) {
$config['debugger']['bar'][] = 'Nette\\DI\\Diagnostics\\ContainerPanel';
}
foreach ((array) $config['debugger']['bar'] as $item) {
$initialize->addBody($container->formatPhp('Nette\\Diagnostics\\Debugger::getBar()->addPanel(?);', Nette\DI\Compiler::filterArguments(array(is_string($item) ? new Nette\DI\Statement($item) : $item))));
}
foreach ((array) $config['debugger']['blueScreen'] as $item) {
$initialize->addBody($container->formatPhp('Nette\\Diagnostics\\Debugger::getBlueScreen()->addPanel(?);', Nette\DI\Compiler::filterArguments(array($item))));
}
}
if (!empty($container->parameters['tempDir'])) {
$initialize->addBody('Nette\\Caching\\Storages\\FileStorage::$useDirectories = ?;', array($this->checkTempDir($container->expand('%tempDir%/cache'))));
}
foreach ((array) $config['forms']['messages'] as $name => $text) {
$initialize->addBody('Nette\\Forms\\Rules::$defaultMessages[Nette\\Forms\\Form::?] = ?;', array($name, $text));
}
if ($config['session']['autoStart'] === 'smart') {
$initialize->addBody('$this->getByType("Nette\\Http\\Session")->exists() && $this->getByType("Nette\\Http\\Session")->start();');
} elseif ($config['session']['autoStart']) {
$initialize->addBody('$this->getByType("Nette\\Http\\Session")->start();');
}
if ($config['latte']['xhtml']) {
$initialize->addBody('Nette\\Utils\\Html::$xhtml = ?;', array(TRUE));
}
if (isset($config['security']['frames']) && $config['security']['frames'] !== TRUE) {
$frames = $config['security']['frames'];
if ($frames === FALSE) {
$frames = 'DENY';
} elseif (preg_match('#^https?:#', $frames)) {
$frames = "ALLOW-FROM {$frames}";
}
$initialize->addBody('header(?);', array("X-Frame-Options: {$frames}"));
}
foreach ($container->findByTag('run') as $name => $on) {
if ($on) {
$initialize->addBody('$this->getService(?);', array($name));
}
}
if (!empty($config['container']['accessors'])) {
$definitions = $container->definitions;
ksort($definitions);
foreach ($definitions as $name => $def) {
if (Nette\PhpGenerator\Helpers::isIdentifier($name)) {
$type = $def->implement ?: $def->class;
$class->addDocument("@property {$type} \${$name}");
}
}
}
$initialize->addBody("@header('Content-Type: text/html; charset=utf-8');");
$initialize->addBody('Nette\\Utils\\SafeStream::register();');
}
示例4: generateClasses
/**
* Generates PHP classes. First class is the container.
* @return Nette\PhpGenerator\ClassType[]
*/
public function generateClasses($className = 'Container', $parentName = 'Nette\\DI\\Container')
{
unset($this->definitions[self::THIS_CONTAINER]);
$this->addDefinition(self::THIS_CONTAINER)->setClass('Nette\\DI\\Container');
$this->generatedClasses = array();
$this->prepareClassList();
$containerClass = $this->generatedClasses[] = new Nette\PhpGenerator\ClassType($className);
$containerClass->setExtends($parentName);
$containerClass->addMethod('__construct')->addBody('parent::__construct(?);', array($this->parameters));
$definitions = $this->definitions;
ksort($definitions);
$meta = $containerClass->addProperty('meta', array())->setVisibility('protected')->setValue(array(Container::TYPES => $this->classes));
foreach ($definitions as $name => $def) {
foreach ($def->tags as $tag => $value) {
$meta->value[Container::TAGS][$tag][$name] = $value;
}
}
foreach ($definitions as $name => $def) {
try {
$name = (string) $name;
$methodName = Container::getMethodName($name);
if (!PhpHelpers::isIdentifier($methodName)) {
throw new ServiceCreationException('Name contains invalid characters.');
}
$containerClass->addMethod($methodName)->addDocument("@return " . ($def->implement ?: $def->class))->setBody($name === self::THIS_CONTAINER ? 'return $this;' : $this->generateService($name))->setParameters($def->implement ? array() : $this->convertParameters($def->parameters));
} catch (\Exception $e) {
throw new ServiceCreationException("Service '{$name}': " . $e->getMessage(), NULL, $e);
}
}
return $this->generatedClasses;
}