Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions src/Mouf/Reflection/MoufReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ public function performToJson($exportMode) {


private $useNamespaces;

/**
* For the current class, returns a list of "use" statement used in the file for that class.
* The key is the "alias" of the path, and the value the path.
Expand All @@ -690,67 +689,68 @@ public function performToJson($exportMode) {
* @return array<string, string>
*/
public function getUseNamespaces() {
if ($this->useNamespaces === null) {
$this->useNamespaces = array();
if ($this->useNamespaces === null) {
$this->useNamespaces = array();

// Optim from Doctrine / Symfony 2: let's not analyze the "use" statements after the start of the class!
$contents = $this->getFileContent($this->getFileName(), $this->getStartLine());
//$contents = file_get_contents($this->getFileName());
// Optim from Doctrine / Symfony 2: let's not analyze the "use" statements after the start of the class!
$contents = $this->getFileContent($this->getFileName(), $this->getStartLine());
//$contents = file_get_contents($this->getFileName());

// Optim to avoid doing the token_get_all think that is costly.
if (strpos($contents, 'use ') === false) {
return array();
}
// Optim to avoid doing the token_get_all think that is costly.
if (strpos($contents, 'use ') === false) {
return array();
}

$tokens = token_get_all($contents);
$tokens = token_get_all($contents);

$classes = array();
$classes = array();

//$namespace = '';
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
$token = $tokens[$i];
//$namespace = '';
for ($i = 0, $max = count($tokens); $i < $max; $i++) {
$token = $tokens[$i];

if (is_string($token)) {
continue;
}

$class = '';

$path = '';

if ($token[0] == T_USE) {
while (($t = $tokens[++$i]) && is_array($t)) {
//if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) {
$type = $t[0];
if ($type == T_STRING || $type == T_NS_SEPARATOR) {
$path .= $t[1];
if ($type == T_STRING) {
$as = $t[1];
}
} elseif ($type === T_AS) {
break;
}
}

if (empty($path)) {
// Path can be empty if the USE statement is not at the beginning of the file but part of a closure
// (function() use ($var))
continue;
}

$nextToken = $tokens[$i];
if ($nextToken[0] === T_AS) {
$i += 2;
$as = $tokens[$i][1];
}
$path = ltrim($path, '\\');
if (is_string($token)) {
continue;
}

$this->useNamespaces[$as] = $path;
}
}
$class = '';

$path = '';

if ($token[0] == T_USE) {
while (($t = $tokens[++$i]) && is_array($t)) {
//if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) {
$type = $t[0];
if ($type == T_STRING || $type == T_NS_SEPARATOR) {
$path .= $t[1];
} elseif ($type === T_NAME_QUALIFIED || $type === T_NAME_FULLY_QUALIFIED) {
$path = $t[1];
} elseif ($type === T_AS) {
break;
}
}

if (empty($path)) {
// Path can be empty if the USE statement is not at the beginning of the file but part of a closure
// (function() use ($var))
continue;
}

$nextToken = $tokens[$i];
if ($nextToken[0] === T_AS) {
$i += 2;
$as = $tokens[$i][1];
} else {
$as = substr($path, strrpos($path,"\\") + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking, what happens in case there is no \, like for instance:

<?php

use InvalidArgumentException;

class MyClass {
  public function __construct(InvalidArgumentException $exception) {}
}

}
$path = ltrim($path, '\\');

$this->useNamespaces[$as] = $path;
}
}

}
return $this->useNamespaces;
}
return $this->useNamespaces;
}

/**
Expand Down
28 changes: 19 additions & 9 deletions src/Mouf/Reflection/MoufXmlReflectionParameter.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/*
* This file is part of the Mouf core package.
*
* (c) 2012 David Negrier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
/*
* This file is part of the Mouf core package.
*
* (c) 2012 David Negrier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/
namespace Mouf\Reflection;


/**
* This class behaves like MoufReflectionParameter, except it is completely based on a Xml message.
* It does not try to access the real class.
Expand Down Expand Up @@ -179,6 +179,16 @@ public function isArray() {
public function getType() {
return (string)$this->xmlElem['class'];
}

/**
*Returns Class Type from xmlElem
*
*@return string
*/
public function getClassName() {

return $this->getType();
}

/**
* Returns the position of the parameter in the parameters list (starting 0)
Expand Down