Skip to content

Commit 307892b

Browse files
committed
ClassType: added getMethod() and getProperty()
1 parent 277b0ad commit 307892b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,18 @@ public function getProperties()
446446
}
447447

448448

449+
/**
450+
* @return Property
451+
*/
452+
public function getProperty($name)
453+
{
454+
if (!isset($this->properties[$name])) {
455+
throw new Nette\InvalidArgumentException("Property '$name' not found.");
456+
}
457+
return $this->properties[$name];
458+
}
459+
460+
449461
/**
450462
* @param string without $
451463
* @param mixed
@@ -483,6 +495,18 @@ public function getMethods()
483495
}
484496

485497

498+
/**
499+
* @return Method
500+
*/
501+
public function getMethod($name)
502+
{
503+
if (!isset($this->methods[$name])) {
504+
throw new Nette\InvalidArgumentException("Method '$name' not found.");
505+
}
506+
return $this->methods[$name];
507+
}
508+
509+
486510
/**
487511
* @param string
488512
* @return Method

tests/PhpGenerator/ClassType.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ $class->addProperty('handle')
3434
$class->addProperty('order')
3535
->setValue(new PhpLiteral('RecursiveIteratorIterator::SELF_FIRST'));
3636

37-
$class->addProperty('sections', array('first' => TRUE))
37+
$p = $class->addProperty('sections', array('first' => TRUE))
3838
->setStatic(TRUE);
3939

40-
$class->addMethod('getHandle')
40+
Assert::same($p, $class->getProperty('sections'));
41+
42+
$m = $class->addMethod('getHandle')
4143
->addDocument('Returns file handle.')
4244
->addDocument('@return resource')
4345
->setFinal(TRUE)
4446
->setBody('return $this->?;', array('handle'));
4547

48+
Assert::same($m, $class->getMethod('getHandle'));
49+
4650
$class->addMethod('getSections')
4751
->setStatic(TRUE)
4852
->setVisibility('protected')

0 commit comments

Comments
 (0)