public function testDeprecatedTypeNode() { $class = new Class_('Foo', array('type' => Class_::MODIFIER_ABSTRACT)); $this->assertTrue($class->isAbstract()); $this->assertSame(Class_::MODIFIER_ABSTRACT, $class->flags); $this->assertSame(Class_::MODIFIER_ABSTRACT, $class->type); }
public function testGetMethod() { $methodConstruct = new ClassMethod('__CONSTRUCT'); $methodTest = new ClassMethod('test'); $class = new Class_('Foo', array('stmts' => array(new ClassConst(array()), $methodConstruct, new Property(0, array()), $methodTest))); $this->assertSame($methodConstruct, $class->getMethod('__construct')); $this->assertSame($methodTest, $class->getMethod('test')); $this->assertNull($class->getMethod('nonExisting')); }
public static function cast($num) { if (is_object($num) && Class_::hasMethod($num, '__toString')) { $num = sprintf('%s', $num); } if (!is_numeric($num)) { return 0; } $type = sprintf('\\apf\\type\\%s', \apf\util\Class_::removeNamespace(get_called_class())); return $type::cast($num); }
public static function cast($val) { if (is_string($val)) { return $val; } if (is_object($val)) { if (Class_::hasMethod(get_class($val), '__toString')) { return sprintf('%s', $val); } } if (is_numeric($val)) { return (string) $val; } if (is_array($val)) { return implode(',', $val); } if (is_resource($val)) { return get_resource_type($val); } return ""; }
public function testGetMethods() { $methods = array(new ClassMethod('foo'), new ClassMethod('bar'), new ClassMethod('fooBar')); $class = new Class_('Foo', array('stmts' => array(new TraitUse(array()), $methods[0], new Const_(array()), $methods[1], new Property(0, array()), $methods[2]))); $this->assertEquals($methods, $class->getMethods()); }
/** * Create a Property object based on the class it is in * * @param Class_ $clazz the class object * @param string $name the name of the property **/ public function __construct(Class_ $clazz, $name) { $this->reflect = new ReflectionProperty($clazz->getName(), $name); }