本文整理匯總了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');
}