本文整理汇总了PHP中Nette\DI\ContainerBuilder::generateClass方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::generateClass方法的具体用法?PHP ContainerBuilder::generateClass怎么用?PHP ContainerBuilder::generateClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::generateClass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateCode
public function generateCode($className, $parentName)
{
foreach ($this->extensions as $extension) {
$extension->beforeCompile();
$this->container->addDependency(Nette\Reflection\ClassType::from($extension)->getFileName());
}
$classes[] = $class = $this->container->generateClass($parentName);
$class->setName($className)->addMethod('initialize');
foreach ($this->extensions as $extension) {
$extension->afterCompile($class);
}
$defs = $this->container->getDefinitions();
ksort($defs);
$list = array_keys($defs);
foreach (array_reverse($defs, TRUE) as $name => $def) {
if ($def->class === 'Nette\\DI\\NestedAccessor' && ($found = preg_grep('#^' . $name . '\\.#i', $list))) {
$list = array_diff($list, $found);
$def->class = $className . '_' . preg_replace('#\\W+#', '_', $name);
$class->documents = preg_replace("#\\S+(?= \\\${$name}\\z)#", $def->class, $class->documents);
$classes[] = $accessor = new Nette\Utils\PhpGenerator\ClassType($def->class);
foreach ($found as $item) {
if ($defs[$item]->internal) {
continue;
}
$short = substr($item, strlen($name) + 1);
$accessor->addDocument($defs[$item]->shared ? "@property {$defs[$item]->class} \${$short}" : "@method {$defs[$item]->class} create" . ucfirst("{$short}()"));
}
}
}
return implode("\n\n\n", $classes);
}