-
Notifications
You must be signed in to change notification settings - Fork 131
adding support for optional and referenced parameters in BUILT-IN functions #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -3,54 +3,123 @@ | |||
|
|||
class FunctionInjector | |||
{ | |||
protected $template = <<<EOF | |||
protected $template = <<<EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
} | ||
EOF; | ||
|
||
protected $templateByRefOptional = <<<EOF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$this->function = $function; | ||
$this->place('ns', $this->namespace); | ||
$this->place('func', $this->function); | ||
protected $namespace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
|
||
} | ||
protected $function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
|
||
} | ||
protected $function; | ||
protected $fileName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$this->fileName = tempnam(sys_get_temp_dir(), $this->function); | ||
file_put_contents($this->fileName, $this->template); | ||
} | ||
function __construct($namespace, $function) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Spaces must be used to indent lines; tabs are not allowed
- Visibility must be declared on method
__construct
file_put_contents($this->fileName, $this->template); | ||
} | ||
function __construct($namespace, $function) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
} | ||
function __construct($namespace, $function) | ||
{ | ||
$this->namespace = $namespace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
function __construct($namespace, $function) | ||
{ | ||
$this->namespace = $namespace; | ||
$this->function = $function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
{ | ||
$this->namespace = $namespace; | ||
$this->function = $function; | ||
$this->placeOptionalAndReferenceFunction($namespace, $function); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$this->namespace = $namespace; | ||
$this->function = $function; | ||
$this->placeOptionalAndReferenceFunction($namespace, $function); | ||
$this->place('ns', $this->namespace); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$this->function = $function; | ||
$this->placeOptionalAndReferenceFunction($namespace, $function); | ||
$this->place('ns', $this->namespace); | ||
$this->place('func', $this->function); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$this->placeOptionalAndReferenceFunction($namespace, $function); | ||
$this->place('ns', $this->namespace); | ||
$this->place('func', $this->function); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
{ | ||
require_once $this->fileName; | ||
} | ||
public function getParameterDeclaration(\ReflectionParameter $parameter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
require_once $this->fileName; | ||
} | ||
public function getParameterDeclaration(\ReflectionParameter $parameter) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
} | ||
public function getParameterDeclaration(\ReflectionParameter $parameter) | ||
{ | ||
$text = (string)$parameter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
public function getParameterDeclaration(\ReflectionParameter $parameter) | ||
{ | ||
$text = (string)$parameter; | ||
if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
{ | ||
$text = (string)$parameter; | ||
if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) { | ||
$text = $match(2).$match[4]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$text = (string)$parameter; | ||
if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) { | ||
$text = $match(2).$match[4]; | ||
} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) { | ||
$text = $match(2).$match[4]; | ||
} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) { | ||
$text = $match[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$text = $match(2).$match[4]; | ||
} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) { | ||
$text = $match[2]; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) { | ||
$text = $match[2]; | ||
} else { | ||
throw new \Exception('reflection api changed. adjust code.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$text = $match[2]; | ||
} else { | ||
throw new \Exception('reflection api changed. adjust code.'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
} else { | ||
throw new \Exception('reflection api changed. adjust code.'); | ||
} | ||
if ($parameter->isOptional()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
throw new \Exception('reflection api changed. adjust code.'); | ||
} | ||
if ($parameter->isOptional()) { | ||
$text .= "=NULL"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
} | ||
if ($parameter->isOptional()) { | ||
$text .= "=NULL"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
if ($parameter->isOptional()) { | ||
$text .= "=NULL"; | ||
} | ||
return $text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$text .= "=NULL"; | ||
} | ||
return $text; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
{ | ||
return $this->fileName; | ||
} | ||
public function placeOptionalAndReferenceFunction($namespace, $function) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
return $this->fileName; | ||
} | ||
public function placeOptionalAndReferenceFunction($namespace, $function) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
} | ||
public function placeOptionalAndReferenceFunction($namespace, $function) | ||
{ | ||
$reflect = new \ReflectionFunction($function); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
public function placeOptionalAndReferenceFunction($namespace, $function) | ||
{ | ||
$reflect = new \ReflectionFunction($function); | ||
$parameters = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
{ | ||
$reflect = new \ReflectionFunction($function); | ||
$parameters = []; | ||
$args = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$reflect = new \ReflectionFunction($function); | ||
$parameters = []; | ||
$args = ''; | ||
$byRef = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$parameters = []; | ||
$args = ''; | ||
$byRef = false; | ||
$optionals = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
$args = ''; | ||
$byRef = false; | ||
$optionals = false; | ||
$names = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces must be used to indent lines; tabs are not allowed
@sergeyklay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@DavertMik Could you please take a look
@DavertMik
fixes bug:
#106