Skip to content

Commit 7069826

Browse files
committed
Merge branch 'hotfix/0.0.11'
2 parents fc48d18 + 4f5eac2 commit 7069826

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
=========
33

4+
0.0.11
5+
-----
6+
Issue : allow backslash within class name for namespace
7+
48
0.0.10
59
-----
610
allow to provide annotation max length to use

Element/AbstractElement.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,26 @@ public function getName()
4646
}
4747
/**
4848
* @param string $name
49+
* @param bool $allowBackslash
4950
* @return bool
5051
*/
51-
public static function nameIsValid($name)
52+
public static function nameIsValid($name, $allowBackslash = false)
5253
{
53-
return preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/D', $name) === 1;
54+
$pattern = '/^[a-zA-Z_][a-zA-Z0-9_]*$/D';
55+
if ($allowBackslash === true) {
56+
$pattern = '/^[a-zA-Z_\\\][a-zA-Z0-9_\\\]*$/D';
57+
}
58+
return preg_match($pattern, $name) === 1;
5459
}
5560
/**
5661
* @param mixed $string
5762
* @param bool $checkName
63+
* @param bool $allowBackslash
5864
* @return bool
5965
*/
60-
public static function stringIsValid($string, $checkName = true)
66+
public static function stringIsValid($string, $checkName = true, $allowBackslash = false)
6167
{
62-
return (is_string($string) && !empty($string) && (!$checkName || self::nameIsValid($string)));
68+
return (is_string($string) && !empty($string) && (!$checkName || self::nameIsValid($string, $allowBackslash)));
6369
}
6470
/**
6571
* @param mixed $object

Element/PhpClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function setExtends($extends)
9191
*/
9292
public static function extendsIsValid($extends)
9393
{
94-
return $extends === null || self::stringIsValid($extends) || $extends instanceof PhpClass;
94+
return $extends === null || self::stringIsValid($extends, true, true) || $extends instanceof PhpClass;
9595
}
9696
/**
9797
* @return string|PhpClass

Tests/Element/PhpClassTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,11 @@ public function testSimpleClassPublicMethodToString()
254254

255255
$this->assertSame("class Foo\n{\n private function bar(\$bar, \$foo, \$sample)\n {\n \$foo = 1;\n }\n}", $class->toString());
256256
}
257+
258+
public function testExtendsFromNamespace()
259+
{
260+
$class = new PhpClass('Foo', false, '\\DOMDocument');
261+
262+
$this->assertSame("class Foo extends \\DOMDocument\n{\n}", $class->toString());
263+
}
257264
}

0 commit comments

Comments
 (0)