コード例 #1
0
 public function testNoModifiers()
 {
     $node = new ClassMethod('foo', array('type' => 0));
     $this->assertTrue($node->isPublic());
     $this->assertFalse($node->isProtected());
     $this->assertFalse($node->isPrivate());
     $this->assertFalse($node->isAbstract());
     $this->assertFalse($node->isFinal());
     $this->assertFalse($node->isStatic());
 }
コード例 #2
0
 public function testAccessors()
 {
     $class_method = new ClassMethod('basicMethod');
     $this->assertEquals('basicMethod', $class_method->getMethod());
     $this->assertEquals([], $class_method->getArgs());
     $class_method->setMethod('methodWithArgs');
     $class_method->setArgs(['arg_1' => 'val_1']);
     $this->assertEquals('methodWithArgs', $class_method->getMethod());
     $this->assertEquals(['arg_1' => 'val_1'], $class_method->getArgs());
 }
コード例 #3
0
 /**
  * Checks that implicit public modifier detection for method is working
  *
  * @dataProvider implicitPublicModifiers
  *
  * @param integer $modifier Node type modifier
  */
 public function testImplicitPublic($modifier)
 {
     $node = new ClassMethod('foo', array('type' => constant('PhpParser\\Node\\Stmt\\Class_::MODIFIER_' . strtoupper($modifier))));
     $this->assertTrue($node->isPublic(), 'Node should be implicitly public');
 }
コード例 #4
0
 /**
  * Transform class/interface name to FQN format
  * @todo WHY WHY :'(
  *
  * @param string $className
  * @return string
  */
 public function getFullName($className)
 {
     $namespace = isset($this->currentMethod) && $this->currentMethod instanceof FunctionDefinition ? $this->currentMethod->getNamespace() : $this->classDefinition->getNamespace();
     return Utils::getFullName($className, $namespace, $this->aliasManager);
 }
コード例 #5
0
ファイル: ClassDefinition.php プロジェクト: NumbDai/zephir
 /**
  * Builds a class definition from reflection
  *
  * @param \ReflectionClass $class
  */
 public static function buildFromReflection(\ReflectionClass $class)
 {
     $classDefinition = new ClassDefinition($class->getNamespaceName(), $class->getName());
     $methods = $class->getMethods();
     if (count($methods) > 0) {
         foreach ($methods as $method) {
             $parameters = array();
             foreach ($method->getParameters() as $row) {
                 $parameters[] = array('type' => 'parameter', 'name' => $row->getName(), 'const' => 0, 'data-type' => 'variable', 'mandatory' => !$row->isOptional());
             }
             $classMethod = new ClassMethod($classDefinition, array(), $method->getName(), new ClassMethodParameters($parameters));
             $classMethod->setIsStatic($method->isStatic());
             $classMethod->setIsInternal(true);
             $classDefinition->addMethod($classMethod);
         }
     }
     $constants = $class->getConstants();
     if (count($constants) > 0) {
         foreach ($constants as $constantName => $constantValue) {
             $type = self::_convertPhpConstantType(gettype($constantValue));
             $classConstant = new ClassConstant($constantName, array('value' => $constantValue, 'type' => $type), null);
             $classDefinition->addConstant($classConstant);
         }
     }
     $classDefinition->setIsInternal(true);
     return $classDefinition;
 }
コード例 #6
0
{
    public function hello()
    {
        echo "hello" . PHP_EOL;
    }
    public abstract function say($something);
}
class ClassMethod
{
    use AbstractMethod;
    public function say($something)
    {
        echo $something . PHP_EOL;
    }
}
$cm = new ClassMethod();
$cm->hello();
$cm->say("hello");
// properties
trait Prop
{
    public $var = 10;
    static $sta = 20;
}
class CProp
{
    use Prop;
}
$prop = new CProp();
echo $prop->var . PHP_EOL;
echo CProp::$sta . PHP_EOL;