本文整理汇总了PHP中ReflectionClass::newInstanceArgs方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::newInstanceArgs方法的具体用法?PHP ReflectionClass::newInstanceArgs怎么用?PHP ReflectionClass::newInstanceArgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::newInstanceArgs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: evaluate
public function evaluate($configFiles)
{
$routeDefinitions = $this->parse($configFiles);
$routes = array();
$limit = count($this->routes) > 0;
foreach ($routeDefinitions as $name => $route) {
// we only load routes defined in the app.yml from
if ($limit && !in_array($this->getOriginalName($name), $this->routes)) {
continue;
}
$r = new ReflectionClass($route[0]);
if ($r->isSubclassOf('sfRouteCollection')) {
$route[1][0]['requirements']['sw_app'] = $this->app;
$route[1][0]['requirements']['sw_host'] = $this->host;
$collection_route = $r->newInstanceArgs($route[1]);
foreach ($collection_route->getRoutes() as $name => $route) {
$routes[$this->app . '.' . $name] = new swEncapsulateRoute($route, $this->host, $this->app);
}
} else {
$route[1][2]['sw_app'] = $this->app;
$route[1][2]['sw_host'] = $this->host;
$routes[$name] = new swEncapsulateRoute($r->newInstanceArgs($route[1]), $this->host, $this->app);
}
}
return $routes;
}
开发者ID:robinkanters,项目名称:dnsleergemeenschap,代码行数:26,代码来源:swCrossApplicationRoutingConfigHandler.class.php
示例2: getModuleInstanceByTypeAndName
public static function getModuleInstanceByTypeAndName($sType, $sName)
{
if (!$sName) {
throw new Exception("Exception in Module::getModuleInstanceByTypeAndName(): module name is empty");
}
$sClassName = self::getClassNameByTypeAndName($sType, $sName);
if (!self::isModuleEnabled($sType, $sName)) {
throw new Exception("Exception in Module::getModuleInstanceByTypeAndName(): tried to instanciate disabled module {$sType}.{$sName}");
}
$aArgs = array_slice(func_get_args(), 2);
$oClass = new ReflectionClass($sClassName);
if ($sClassName::isSingleton()) {
if (!isset(self::$SINGLETONS[$sClassName])) {
try {
self::$SINGLETONS[$sClassName] = $oClass->newInstanceArgs($aArgs);
} catch (ReflectionException $ex) {
self::$SINGLETONS[$sClassName] = $oClass->newInstance();
}
}
return self::$SINGLETONS[$sClassName];
}
try {
return $oClass->newInstanceArgs($aArgs);
//Does not work in PHP < 5.1.3
} catch (ReflectionException $ex) {
return $oClass->newInstance();
//Does not work in PHP < 5.1.3
}
}
示例3: toCall
/**
* 调用具体的业务逻辑接口,通常来说是项目中的
* controller,也可以RPC调用
* @param Request $request
* @return mixed
* @throws \Simple\Application\Game\Cycle\Exception\GameCycleException
*/
public function toCall(Request $request)
{
$head = $request->getHeader();
$module = ucfirst($head[0]);
$action = $head[1];
// TODO 获取类的命名空间
$cls = new \ReflectionClass(APP_TOP_NAMESPACE . '\\Controller\\' . $module . 'Controller');
$instance = null;
//优先调用init方法
if ($cls->hasMethod('__init__')) {
$initMethod = $cls->getMethod('__init__');
if ($initMethod->isPublic() == true) {
$instance = $cls->newInstanceArgs(array());
$initMethod->invokeArgs($instance, array());
}
}
$method = $cls->getMethod($action);
if ($method->isPublic() == false) {
throw new GameCycleException('无法调用接口:' . $module . '.' . $action);
}
if ($instance == null) {
$instance = $cls->newInstanceArgs(array());
}
$ret = $method->invokeArgs($instance, array($request));
if ($ret instanceof Response === false) {
throw new GameCycleException('接口返回的对象必须为:Response对象。');
}
return $ret;
}
示例4: invoke
/**
* @param array|null $args
*
* @return object
*/
function invoke(array $args = null)
{
if ($args !== null) {
return $this->reflectionClass->newInstanceArgs($args);
}
return $this->reflectionClass->newInstance();
}
示例5: create
public function create($component, array $args = [], $forceNewInstance = false, $share = [])
{
if (!$forceNewInstance && isset($this->instances[$component])) {
return $this->instances[$component];
}
if (empty($this->cache[$component])) {
$rule = $this->getRule($component);
$class = new \ReflectionClass($rule->instanceOf ? $rule->instanceOf : $component);
$constructor = $class->getConstructor();
$params = $constructor ? $this->getParams($constructor, $rule) : null;
$this->cache[$component] = function ($args) use($component, $rule, $class, $constructor, $params, $share) {
if ($rule->shared) {
if ($constructor) {
try {
$this->instances[$component] = $object = $class->newInstanceWithoutConstructor();
$constructor->invokeArgs($object, $params($args, $share));
} catch (\ReflectionException $r) {
$this->instances[$component] = $object = $class->newInstanceArgs($params($args, $share));
}
} else {
$this->instances[$component] = $object = $class->newInstanceWithoutConstructor();
}
} else {
$object = $params ? $class->newInstanceArgs($params($args, $share)) : new $class->name();
}
if ($rule->call) {
foreach ($rule->call as $call) {
$class->getMethod($call[0])->invokeArgs($object, call_user_func($this->getParams($class->getMethod($call[0]), $rule), $this->expand($call[1])));
}
}
return $object;
};
}
return $this->cache[$component]($args);
}
示例6: create
public static function create($arg1, $arg2 = null)
{
if ($arg1 instanceof AbstractValidator) {
return $arg1;
}
if (is_array($arg1) && !isset($arg1['class'])) {
return self::createGroup($arg1);
}
if (is_string($arg1)) {
$class = $arg1;
$options = $arg2;
} else {
$class = $arg1['class'];
if (isset($arg1['options'])) {
$options = $arg1['options'];
}
}
$reflection = new \ReflectionClass($class);
if (isset($options)) {
$validator = $reflection->newInstanceArgs($options);
} else {
$validator = $reflection->newInstanceArgs();
}
return $validator;
}
示例7: createMultiple
/**
* Populates a set of models with the data from end user.
* This method is mainly used to collect tabular data input.
* The data to be loaded for each model is `$data[formName][index]`, where `formName`
* refers to the sort name of model class, and `index` the index of the model in the `$data` array.
* If `$formName` is empty, `$data[index]` will be used to populate each model.
* The data being populated to each model is subject to the safety check by [[setAttributes()]].
* @param string $class Model class name.
* @param array $data the data array. This is usually `$_POST` or `$_GET`, but can also be any valid array
* supplied by end user.
* @param string $formName the form name to be used for loading the data into the models.
* If not set, it will use the sort name of called class.
* @param Model[] $origin original models to be populated. It will be check using `$keys` with supplied data.
* If same then will be used for result model.
* @param array $options Option to model
* - scenario for model.
* - arguments The parameters to be passed to the class constructor as an array.
* @return boolean|Model[] whether at least one of the models is successfully populated.
*/
public static function createMultiple($class, $data, $formName = null, &$origin = [], $options = [])
{
$reflector = new \ReflectionClass($class);
$args = isset($options['arguments']) ? $options['arguments'] : [];
if ($formName === null) {
/* @var $model Model */
$model = empty($args) ? new $class() : $reflector->newInstanceArgs($args);
$formName = $model->formName();
}
if ($formName != '') {
$data = isset($data[$formName]) ? $data[$formName] : null;
}
if ($data === null) {
return false;
}
$models = [];
foreach ($data as $i => $row) {
$model = null;
if (isset($origin[$i])) {
$model = $origin[$i];
unset($origin[$i]);
} else {
$model = empty($args) ? new $class() : $reflector->newInstanceArgs($args);
}
if (isset($options['scenario'])) {
$model->scenario = $options['scenario'];
}
$model->load($row, '');
$models[$i] = $model;
}
return $models;
}
示例8: testSimilarTo
/**
* Test the Notice->similar_to(<Notice>) method
*
* @test
* @dataProvider providerSimilarTo
*/
public function testSimilarTo($args_one, $args_two, $expected)
{
$reflected = new ReflectionClass('Notice');
$notice_one = $reflected->newInstanceArgs($args_one);
$notice_two = $reflected->newInstanceArgs($args_two);
$this->assertSame($expected, $notice_one->similar_to($notice_two));
}
示例9: testGetAllowed
public function testGetAllowed()
{
$options = new ParserOptions();
$options->allowed_tags = ['noparse', 'code', 'img'];
$method = $this->reflectionClass->getMethod('getAllowed');
$this->parser = $this->reflectionClass->newInstanceArgs([$options]);
$this->assertEquals(['code', 'img', 'noparse'], $method->invoke($this->parser));
}
示例10: constructClass
/**
* Construct new class by class name
* @param string $className class that want to be constructed.
* @param array $args Constructor params if exist
* @return object Constructed Class
*/
public static function constructClass($className, array $args = array())
{
$reflector = new \ReflectionClass($className);
if ($reflector->hasMethod('__construct') && count($args) > 0) {
return $reflector->newInstanceArgs($args);
}
return $reflector->newInstanceArgs();
}
示例11: createInstance
/**
* @param array $args
*
* @return \IntlDateFormatter
*/
protected static function createInstance(array $args = array())
{
if (!self::$reflection) {
self::$reflection = new \ReflectionClass('IntlDateFormatter');
}
$instance = self::$reflection->newInstanceArgs($args);
self::checkInternalClass($instance, '\\IntlDateFormatter', $args);
return $instance;
}
示例12: getInst
/**
* Метод формирует экземпляр класса на основе строки.
* После будет применён фильтр, если он есть.
*
* @return object
*/
private function getInst(array $row)
{
if ($this->constructorParams) {
$args = $this->constructorParams;
$args[] = $row;
return $this->RC->newInstanceArgs($args);
} else {
return $this->RC->newInstance($row);
}
}
示例13: create
/**
* {@inheritdoc}
*/
public function create(array $arguments = [])
{
if (empty($arguments[0])) {
$arguments[0] = $this->createEntity();
}
if (!$this->modelClassReflection) {
$this->modelClassReflection = new \ReflectionClass($this->modelClassName);
}
return $this->modelClassReflection->newInstanceArgs($arguments);
}
示例14: instantiate
/**
* @param $class
* @param $args
* @return object
*/
private static function instantiate($class, $args)
{
//BOOOOO, this produces a parse error on less than 5.6.0
// if (version_compare(phpversion(), '5.6.0') !== -1) {
// $instance = new $class(...$args);
// } else {
$reflect = new \ReflectionClass($class);
$instance = $args === null || $args === false ? $reflect->newInstanceArgs() : $reflect->newInstanceArgs($args);
// }
return $instance;
}
示例15: create
public function create($class, array $args = array())
{
$this->validate($class, $args);
$reflection = new \ReflectionClass($class);
if ($reflection->getConstructor()) {
$object = $reflection->newInstanceArgs($args);
} else {
$object = $reflection->newInstanceArgs();
}
return $object;
}