Commit c210de9d by Qiang Xue

Merge pull request #556 from creocoder/php5.3-way-to-get-namespace

Model::formName() and ActiveRecord::getNamespacedClass() PHP 5.3 way
parents 729446ed 826c83c3
...@@ -186,9 +186,8 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess ...@@ -186,9 +186,8 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/ */
public function formName() public function formName()
{ {
$class = get_class($this); $reflector = new \ReflectionClass($this);
$pos = strrpos($class, '\\'); return $reflector->getShortName();
return $pos === false ? $class : substr($class, $pos + 1);
} }
/** /**
......
...@@ -1390,12 +1390,11 @@ class ActiveRecord extends Model ...@@ -1390,12 +1390,11 @@ class ActiveRecord extends Model
protected function getNamespacedClass($class) protected function getNamespacedClass($class)
{ {
if (strpos($class, '\\') === false) { if (strpos($class, '\\') === false) {
$primaryClass = get_class($this); $reflector = new \ReflectionClass($this);
if (($pos = strrpos($primaryClass, '\\')) !== false) { return $reflector->getNamespaceName() . '\\' . $class;
return substr($primaryClass, 0, $pos + 1) . $class; } else {
} return $class;
} }
return $class;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment