本文整理汇总了PHP中Zend\Code\Generator\FileGenerator::getClass方法的典型用法代码示例。如果您正苦于以下问题:PHP FileGenerator::getClass方法的具体用法?PHP FileGenerator::getClass怎么用?PHP FileGenerator::getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\FileGenerator
的用法示例。
在下文中一共展示了FileGenerator::getClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
/**
* @param FileGenerator $file
* @param Type $type
*
* @return string
*/
public function generate(FileGenerator $file, $type)
{
$class = $file->getClass() ?: new ClassGenerator();
$class->setNamespaceName($type->getNamespace());
$class->setName($type->getName());
$this->ruleSet->applyRules(new TypeContext($class, $type));
foreach ($type->getProperties() as $property) {
$this->ruleSet->applyRules(new PropertyContext($class, $type, $property));
}
$file->setClass($class);
return $file->generate();
}
示例2: Type
function it_generates_types(RuleSetInterface $ruleSet, FileGenerator $file, ClassGenerator $class)
{
$type = new Type('MyNamespace', 'MyType', ['prop1' => 'string']);
$property = $type->getProperties()[0];
$file->generate()->willReturn('code');
$file->getClass()->willReturn($class);
$class->setNamespaceName('MyNamespace')->shouldBeCalled();
$class->setName('MyType')->shouldBeCalled();
$file->setClass($class)->shouldBeCalled();
$ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type) {
return $context instanceof TypeContext && $context->getType() === $type;
}))->shouldBeCalled();
$ruleSet->applyRules(Argument::that(function (ContextInterface $context) use($type, $property) {
return $context instanceof PropertyContext && $context->getType() === $type && $context->getProperty() === $property;
}))->shouldBeCalled();
$this->generate($file, $type)->shouldReturn('code');
}