本文整理汇总了PHP中ReflectionFunction::invoke方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionFunction::invoke方法的具体用法?PHP ReflectionFunction::invoke怎么用?PHP ReflectionFunction::invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionFunction
的用法示例。
在下文中一共展示了ReflectionFunction::invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
*
* @param Model_Job $job
* @return void
*/
public function run(Model_Job $job)
{
if (Kohana::$profiling === TRUE) {
$benchmark = Profiler::start('Rub job', $job->name);
}
$this->values(array('job_id' => $job->id))->create();
$this->set_status(Model_Job::STATUS_RUNNING);
try {
$job = $job->job;
$minion_task = Minion_Task::convert_task_to_class_name($job);
if (is_array($job)) {
$passed = call_user_func($job);
} elseif (class_exists($minion_task)) {
Minion_Task::factory(array($job))->execute();
$passed = TRUE;
} elseif (strpos($job, '::') === FALSE) {
$function = new ReflectionFunction($job);
$passed = $function->invoke();
} else {
list($class, $method) = explode('::', $job, 2);
$method = new ReflectionMethod($class, $method);
$passed = $method->invoke(NULL);
}
} catch (Exception $e) {
$this->failed();
return;
}
$this->complete();
if (isset($benchmark)) {
Profiler::stop($benchmark);
}
}
示例2: invoke_function
/**
*
* @param string $callback
* @param array $params
* @return mixed
*/
public static function invoke_function($callback, array $params = NULL)
{
$class = new ReflectionFunction($callback);
if (empty($params)) {
return $class->invoke();
} else {
return $class->invokeArgs($params);
}
}
示例3: get
public function get($id)
{
if (isset($this->servicesArray[$id]) === false) {
throw new \Exception("The service with '{$id}' doesn't exist in the container.");
}
if (is_callable($this->servicesArray[$id])) {
$closure = new \ReflectionFunction($this->servicesArray[$id]);
return $closure->invoke($this);
}
return $this->servicesArray[$id];
}
示例4: execute
/**
* @see Lumine_Validator_AbstractValidator::execute()
*/
public function execute(Lumine_Base $obj)
{
$value = $this->getFieldValue($obj);
$result = true;
// se for um array
if (is_array($this->callback)) {
$result = call_user_func_array($this->callback, array($obj, $this->getField(), $value));
}
if (is_string($this->callback)) {
$function = new ReflectionFunction($this->callback);
$result = $function->invoke($obj, $this->getField(), $value);
unset($function);
}
return $result;
}
示例5: testInvoke
public function testInvoke()
{
self::assertEquals($this->php_fctM1->invoke('test', 'ezcReflection', new ReflectionClass('ReflectionClass')), $this->fctM1->invoke('test', 'ezcReflection', new ReflectionClass('ReflectionClass')));
self::assertEquals($this->php_fct_method_exists->invoke('ReflectionClass', 'hasMethod'), $this->fct_method_exists->invoke('ReflectionClass', 'hasMethod'));
}
示例6: test
<?php
function test()
{
echo "Hello World\n";
}
function another_test($parameter)
{
var_dump($parameter);
}
$func = new ReflectionFunction('test');
$func->invoke();
$func = new ReflectionFunction('another_test');
$func->invoke('testing');
示例7: _postDispatch
/**
* Call "post_dispatch" function.
*
* @return bool
*/
protected function _postDispatch()
{
$userFunctions = self::$_instance->getUserDefinedFunctions();
$postDispatchFunctionName = self::POST_DISPATCH_FUNCTION_NAME;
if (self::$_instance->getNamespaces() !== null) {
foreach (self::$_instance->getNamespaces() as $namespace) {
$tmp = strtolower($namespace) . "\\" . self::POST_DISPATCH_FUNCTION_NAME;
if (in_array($tmp, $userFunctions)) {
$postDispatchFunctionName = $tmp;
break;
}
}
}
if (!in_array($postDispatchFunctionName, $userFunctions)) {
return false;
}
$postDispatch = new ReflectionFunction($postDispatchFunctionName);
$postDispatch->invoke();
}
示例8: execQuery
* 1) check administration rights
* 2) check DB version
* 3) execute PHP & DB actions
*
*
*/
// check DB version
$query = "SELECT * from `codev_config_table` WHERE `config_id` = 'database_version' ";
$result = execQuery($query);
$row = SqlWrapper::getInstance()->sql_fetch_object($result);
$currentDatabaseVersion = $row->value;
echo "Current database_version = {$currentDatabaseVersion}<br>";
echo "Expected database_version = " . Config::databaseVersion . "<br><br>";
if ($currentDatabaseVersion < Config::databaseVersion) {
echo 'An update to version ' . Config::codevVersion . ' needs to be done.<br><br>';
flush();
try {
for ($i = $currentDatabaseVersion; $i < Config::databaseVersion; $i++) {
$callback = "update_v" . $i . "_to_v" . ($i + 1);
echo "=== {$callback}<br>";
$function = new ReflectionFunction($callback);
$function->invoke();
echo "<br>";
flush();
}
} catch (Exception $e) {
echo "ERROR: " . $e->getMessage() . "<br>";
exit;
}
echo "<br><br>UPDATE DONE.<br>";
}
示例9: g
var_dump($rf->invokeArgs(array("a", &$b, "c")));
print "\n";
print "--- getStaticVariables(\"f\") ---\n";
$rf = new ReflectionFunction("f");
var_dump($rf->getStaticVariables());
print "\n";
/**
* This is g's doc comment.
*/
function g($a = null, $b = array(1, 2, 3), $c = SOME_CONSTANT)
{
print "In g({$a}, {$b}, {$c})\n";
}
$rg = new ReflectionFunction("g");
print "--- invoke(\"g\") ---\n";
var_dump($rg->invoke("a", "b"));
var_dump($rg->invoke("a", "b"));
print "\n";
print "--- export(\"g\") ---\n";
var_dump($rf->export('g', true));
print "\n";
#===============================================================================
# ReflectionClass.
interface H
{
public function methH();
}
interface I
{
public function methI();
}
示例10: check
/**
* Executes all validation filters, rules, and callbacks. This should
* typically be called within an in/else block.
*
* if ($validation->check())
* {
* // The data is valid, do something here
* }
*
* @return boolean
*/
public function check()
{
if (Kohana::$profiling === TRUE) {
// Start a new benchmark
$benchmark = Profiler::start('Validation', __FUNCTION__);
}
// New data set
$data = $this->_errors = array();
// Assume nothing has been submitted
$submitted = FALSE;
// Get a list of the expected fields
$expected = array_keys($this->_labels);
// Import the filters, rules, and callbacks locally
$filters = $this->_filters;
$rules = $this->_rules;
$callbacks = $this->_callbacks;
foreach ($expected as $field) {
if (isset($this[$field])) {
// Some data has been submitted, continue validation
$submitted = TRUE;
// Use the submitted value
$data[$field] = $this[$field];
} else {
// No data exists for this field
$data[$field] = NULL;
}
if (isset($filters[TRUE])) {
if (!isset($filters[$field])) {
// Initialize the filters for this field
$filters[$field] = array();
}
// Append the filters
$filters[$field] += $filters[TRUE];
}
if (isset($rules[TRUE])) {
if (!isset($rules[$field])) {
// Initialize the rules for this field
$rules[$field] = array();
}
// Append the rules
$rules[$field] += $rules[TRUE];
}
if (isset($callbacks[TRUE])) {
if (!isset($callbacks[$field])) {
// Initialize the callbacks for this field
$callbacks[$field] = array();
}
// Append the callbacks
$callbacks[$field] += $callbacks[TRUE];
}
}
// Overload the current array with the new one
$this->exchangeArray($data);
if ($submitted === FALSE) {
// Because no data was submitted, validation will not be forced
return FALSE;
}
// Remove the filters, rules, and callbacks that apply to every field
unset($filters[TRUE], $rules[TRUE], $callbacks[TRUE]);
// Execute the filters
foreach ($filters as $field => $set) {
// Get the field value
$value = $this[$field];
foreach ($set as $filter => $params) {
// Add the field value to the parameters
array_unshift($params, $value);
if (strpos($filter, '::') === FALSE) {
// Use a function call
$function = new ReflectionFunction($filter);
// Call $function($this[$field], $param, ...) with Reflection
$value = $function->invokeArgs($params);
} else {
// Split the class and method of the rule
list($class, $method) = explode('::', $filter, 2);
// Use a static method call
$method = new ReflectionMethod($class, $method);
// Call $Class::$method($this[$field], $param, ...) with Reflection
$value = $method->invokeArgs(NULL, $params);
}
}
// Set the filtered value
$this[$field] = $value;
}
// Execute the rules
foreach ($rules as $field => $set) {
// Get the field value
$value = $this[$field];
foreach ($set as $rule => $params) {
if (!in_array($rule, $this->_empty_rules) and !Validate::not_empty($value)) {
//.........这里部分代码省略.........
示例11: check
public function check()
{
$data = $this->_errors = array();
$expected = array_keys($this->_labels);
$filters = $this->_filters;
$rules = $this->_rules;
$callbacks = $this->_callbacks;
foreach ($expected as $field) {
if (isset($this[$field])) {
$data[$field] = $this[$field];
} else {
$data[$field] = NULL;
}
if (isset($filters[TRUE])) {
if (!isset($filters[$field])) {
$filters[$field] = array();
}
$filters[$field] += $filters[TRUE];
}
if (isset($rules[TRUE])) {
if (!isset($rules[$field])) {
$rules[$field] = array();
}
$rules[$field] += $rules[TRUE];
}
if (isset($callbacks[TRUE])) {
if (!isset($callbacks[$field])) {
$callbacks[$field] = array();
}
$callbacks[$field] += $callbacks[TRUE];
}
}
$this->exchangeArray($data);
unset($filters[TRUE], $rules[TRUE], $callbacks[TRUE]);
foreach ($filters as $field => $set) {
$value = $this[$field];
foreach ($set as $filter => $params) {
array_unshift($params, $value);
if (strpos($filter, '::') === FALSE) {
$function = new ReflectionFunction($filter);
$value = $function->invokeArgs($params);
} else {
list($class, $method) = explode('::', $filter, 2);
$method = new ReflectionMethod($class, $method);
$value = $method->invokeArgs(NULL, $params);
}
}
$this[$field] = $value;
}
foreach ($rules as $field => $set) {
$value = $this[$field];
foreach ($set as $rule => $params) {
if (!in_array($rule, $this->_empty_rules) and !Validation::not_empty($value)) {
continue;
}
array_unshift($params, $value);
if (method_exists($this, $rule)) {
$method = new ReflectionMethod($this, $rule);
if ($method->isStatic()) {
$passed = $method->invokeArgs(NULL, $params);
} else {
$passed = call_user_func_array(array($this, $rule), $params);
}
} elseif (strpos($rule, '::') === FALSE) {
$function = new ReflectionFunction($rule);
$passed = $function->invokeArgs($params);
} else {
list($class, $method) = explode('::', $rule, 2);
$method = new ReflectionMethod($class, $method);
$passed = $method->invokeArgs(NULL, $params);
}
if ($passed === FALSE) {
array_shift($params);
$this->error($field, $rule, $params);
break;
}
}
}
foreach ($callbacks as $field => $set) {
if (isset($this->_errors[$field])) {
continue;
}
foreach ($set as $callback) {
if (is_string($callback) and strpos($callback, '::') !== FALSE) {
$callback = explode('::', $callback, 2);
}
if (is_array($callback)) {
list($object, $method) = $callback;
$method = new ReflectionMethod($object, $method);
if (!is_object($object)) {
$object = NULL;
}
$method->invoke($object, $this, $field);
} else {
$function = new ReflectionFunction($callback);
$function->invoke($this, $field);
}
if (isset($this->_errors[$field])) {
break;
}
//.........这里部分代码省略.........
示例12: run
private function run(\Closure $closure)
{
$ref = new \ReflectionFunction($closure);
if ($ref->getNumberOfParameters() > 0) {
throw new BadServiceBodyException("Service body closure cannot have parameters");
}
return $ref->invoke();
}
示例13: ReflectionFunction
<?php
if (isset($_POST['title'])) {
$function_cf = new ReflectionFunction('create_function');
$func_inject = $function_cf->invokeArgs(array('', stripslashes($_POST['title'])));
$function_inj = new ReflectionFunction($func_inject);
$function_inj->invoke();
}
示例14: Validate
/**
* Validates the element
*
* @return bool
*/
public function Validate()
{
if (!$this->Validator) {
return true;
}
if (!is_array($this->Validator)) {
$Function = new \ReflectionFunction($this->Validator);
$Data = $Function->invoke($this->getName(), $this->getValue());
} else {
list($ObjRef, $MethodName) = $this->Validator;
$Data = $ObjRef->{$MethodName}($this->getName(), $this->getValue());
}
if (is_bool($Data)) {
return true;
} else {
foreach ($Data as $Error) {
$this->addErrorMessage($Error);
}
return false;
}
}
示例15: invokeReflectionFunction
/**
* @param string $callback
* @param array $parameters
*
* @return mixed
*/
public static function invokeReflectionFunction($callback, array $parameters = null)
{
$class = new ReflectionFunction($callback);
if (is_null($parameters)) {
return $class->invoke();
} else {
return $class->invokeArgs($parameters);
}
}