本文整理汇总了PHP中ReflectionClass::IsInstantiable方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::IsInstantiable方法的具体用法?PHP ReflectionClass::IsInstantiable怎么用?PHP ReflectionClass::IsInstantiable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::IsInstantiable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* @param array $argv
* @return Pflow_CommandInterface
* @throws BadMethodCallException
*/
public function dispatch(array $argv)
{
for ($i = count($argv); $i > 1; $i--) {
$command = sprintf('Pflow_Command_%s', implode('_', array_map('ucfirst', array_slice($argv, 1, $i - 1))));
if (class_exists($command)) {
$reflectionClass = new ReflectionClass($command);
if ($reflectionClass->IsInstantiable() && $reflectionClass->implementsInterface('Pflow_CommandInterface')) {
return new $command($this->git, $this->output, $this->input, $this->history);
}
}
}
throw new BadMethodCallException(sprintf('Could not find command in "%s"', implode(' ', $argv)));
}
示例2: cast
/**
* cast() - casts generic object to Et-Specific object
*
* @param stdClass $obj - standard php object
* @param string $class - Et-class
* @param EtClient $client
*
* @return <typeOf $class>
*
*/
public function cast($obj, $class, $client = null)
{
$reflectionClass = new \ReflectionClass($class);
if (!$reflectionClass->IsInstantiable()) {
throw new \Exception($class . " is not instantiable!");
}
if ($obj instanceof $class) {
return $obj;
// nothing to do.
}
// lets instantiate the new object
$tmpObject = null;
try {
$r = new \ReflectionMethod($class, '__construct');
$params = $r->getParameters();
if (count($params)) {
$tmpObject = $reflectionClass->newInstance($client);
}
} catch (\ReflectionException $e) {
// do nothing
}
if ($tmpObject === null) {
$tmpObject = $reflectionClass->newInstance();
}
$properties = array();
foreach ($reflectionClass->getProperties() as $property) {
$properties[$property->getName()] = $property;
}
// we'll take all the properties from the fathers as well
// overwriting the old properties from the son as well if needed.
$parentClass = $reflectionClass;
// loop init
while ($parentClass = $parentClass->getParentClass()) {
foreach ($parentClass->getProperties() as $property) {
$properties[$property->getName()] = $property;
}
}
// now lets see what we have set in $obj and transfer that to the new object
$vars = get_object_vars($obj);
foreach ($vars as $varName => $varValue) {
if (array_key_exists($varName, $properties)) {
$prop = $properties[$varName];
if (!$prop->isPublic()) {
$prop->setAccessible(true);
}
$prop->setValue($tmpObject, $varValue);
}
}
return $tmpObject;
}
示例3: load
/**
* Loader
*
* @param ClassLoader $loader Loader
*
* @return array
*/
public static function load(ClassLoader $loader)
{
$modules = array();
$classmap = $loader->getClassMap();
foreach ($classmap as $class => $file) {
// The following is required as class_exists, is_subclass_of and ReflectionClass will throw a fatal error if class extends a non-existent class
// @todo allow custom namespaces
if (!preg_match('/^main|phpforge|module/i', $class) && !preg_match('/^' . str_replace('/', '\\/', self::getModDir()) . '/i', $file)) {
continue;
}
if (class_exists($class)) {
if (is_subclass_of($class, 'Forge\\Application\\Module')) {
$ref = new \ReflectionClass($class);
if ($ref->IsInstantiable()) {
$mod = $ref->newInstanceWithoutConstructor();
$acls = array();
if (method_exists($mod, 'acl')) {
$acls = $mod->acl();
}
$routemap = array();
$methods = $ref->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if (preg_match('/Post|Get|Put|Delete$/', $method->name)) {
$methodName = preg_replace('/Post|Get|Put|Delete$/', '', $method->name);
$methodType = strtoupper(preg_replace('/.*(Post|Get|Put|Delete)$/', '$1', $method->name));
$urls = array();
if (strtolower($methodName) == strtolower($ref->getShortName())) {
if (strtolower($method->class) == strtolower(self::$defaultModule) && $methodType == 'GET') {
$urls[] = '/';
}
$urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class));
} else {
$urls[] = '/' . strtolower(preg_replace('/\\\\/', '/', $class) . '/' . $methodName);
}
$route = new Route();
$route->setClass($class)->setMethod($method->name)->setRequestMethod($methodType)->setUrls($urls);
if (key_exists($method->name, $acls)) {
$route->setAcls($acls[$method->name]);
}
$routemap[] = $route;
}
}
$mod->setRoutes($routemap);
$modules[] = $mod;
}
}
}
}
return $modules;
}
示例4: getPluginInstance
private function getPluginInstance($pluginPath, $pluginFqcn)
{
require_once $pluginPath;
if (!class_exists($pluginFqcn)) {
throw new RuntimeException("Class '{$pluginFqcn}' not found in '{$pluginPath}'.", self::NON_EXISTENT_BUNDLE_CLASS);
}
$reflectionClass = new \ReflectionClass($pluginFqcn);
if (!$reflectionClass->IsInstantiable()) {
throw new RuntimeException("Class '{$pluginFqcn}' is not instantiable.", self::NON_INSTANTIABLE_BUNDLE_CLASS);
}
if (!$reflectionClass->isSubclassOf('Claroline\\CoreBundle\\Library\\PluginBundle')) {
throw new RuntimeException("Class '{$pluginFqcn}' doesn't extend Claroline 'PluginBundle' class.", self::UNEXPECTED_BUNDLE_TYPE);
}
return new $pluginFqcn();
}
示例5: getDefaultCommands
protected function getDefaultCommands()
{
$commands = parent::getDefaultCommands();
$finder = new Finder();
$finder->files()->name('*.php')->depth('0')->in(__DIR__ . '/Commands/')->sortByName();
foreach ($finder as $file) {
$fileName = $file->getFilename();
$class = substr($fileName, 0, strlen($fileName) - 4);
$fullClassName = '\\Spark\\Commands\\' . $class;
$reflectionClass = new \ReflectionClass($fullClassName);
if ($reflectionClass->IsInstantiable()) {
$commands[] = new $fullClassName();
}
}
return $commands;
}
示例6: getCommandClasses
/**
* @return array
*/
public function getCommandClasses()
{
$classes = array();
foreach ($this->libDirs as $libDir) {
$commandDir = $libDir . '/Pflow/Command/';
$ite = new RecursiveDirectoryIterator($commandDir);
foreach (new RecursiveIteratorIterator($ite) as $fileName => $splFile) {
if ($splFile->isDir()) {
continue;
}
$className = str_replace('/', '_', substr($fileName, strlen($libDir . '/'), -4));
// Trigger autoload
class_exists($className);
$reflectionClass = new ReflectionClass($className);
if ($reflectionClass->IsInstantiable() && $reflectionClass->implementsInterface('Pflow_CommandInterface')) {
$classes[] = $className;
}
}
}
sort($classes);
return $classes;
}
示例7: __construct
}
class privateCtorNew
{
private function __construct()
{
}
}
class publicCtorOld
{
public function publicCtorOld()
{
}
}
class protectedCtorOld
{
protected function protectedCtorOld()
{
}
}
class privateCtorOld
{
private function privateCtorOld()
{
}
}
$classes = array("noCtor", "publicCtorNew", "protectedCtorNew", "privateCtorNew", "publicCtorOld", "protectedCtorOld", "privateCtorOld");
foreach ($classes as $class) {
$reflectionClass = new ReflectionClass($class);
echo "Is {$class} instantiable? ";
var_dump($reflectionClass->IsInstantiable());
}
示例8: isInstantiable
/**
* Checks if a bridge is an instantiable bridge.
* @param string $nameBridge name of the bridge that you want to use
* @return true if it is an instantiable bridge, false otherwise.
*/
public static function isInstantiable($nameBridge)
{
$re = new ReflectionClass($nameBridge);
return $re->IsInstantiable();
}
示例9: generateDocs
protected function generateDocs($loadModels, $ignore = '')
{
$output = "<?php\n/**\n * An helper file for your Eloquent Models\n * Copy the phpDocs from this file to the correct Model,\n * And remove them from this file, to prevent double declarations.\n *\n * @author Barry vd. Heuvel <barryvdh@gmail.com>\n */\n\n\n";
if (empty($loadModels)) {
$models = $this->loadModels();
} else {
$models = array();
foreach ($loadModels as $model) {
$models = array_merge($models, explode(',', $model));
}
}
$ignore = explode(',', $ignore);
foreach ($models as $name) {
if (in_array($name, $ignore)) {
$this->comment("Ignoring model '{$name}'");
continue;
} else {
$this->comment("Loading model '{$name}'");
}
$this->properties = array();
$this->methods = array();
if (class_exists($name)) {
try {
// handle abstract classes, interfaces, ...
$reflectionClass = new \ReflectionClass($name);
if (!$reflectionClass->IsInstantiable()) {
throw new \Exception($name . ' is not instanciable.');
} elseif (!$reflectionClass->isSubclassOf('Illuminate\\Database\\Eloquent\\Model')) {
$this->comment("Class '{$name}' is not a model");
continue;
}
$model = new $name();
$this->getPropertiesFromTable($model);
$this->getPropertiesFromMethods($model);
$output .= $this->createPhpDocs($name);
} catch (\Exception $e) {
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class {$name}.");
}
} else {
$this->error("Class {$name} does not exist");
}
}
return $output;
}
示例10: checkInstantiable
private function checkInstantiable($class)
{
$reflectionClass = new \ReflectionClass($class);
if (!$reflectionClass->IsInstantiable()) {
$this->addError('Controller error!', "Class: <b>\"{$class}\"</b> is can not initialize!", 404);
$this->checkError();
}
}
示例11: exec_ogp_module
function exec_ogp_module()
{
?>
<h2>XML Config Creator</h2>
<table BORDER=1>
<tr>
<td>
Query protocol
</td>
<form action="" method="POST">
<td>
<select name="protocol" onchange="this.form.submit()">
<option value="">None</option>
<option value="lgsl" <?php
if (isset($_POST['protocol']) && $_POST['protocol'] == "lgsl") {
echo 'selected="selected"';
}
?>
>LGSL</option>
<option value="gameq" <?php
if (isset($_POST['protocol']) && $_POST['protocol'] == "gameq") {
echo 'selected="selected"';
}
?>
>GameQ</option>
</select>
</td>
</form>
</tr>
<form action='home.php?m=config_games&p=cli-params&type=cleared' method='POST' name='xml_creator'>
<?php
if (isset($_POST['protocol'])) {
echo "\n\t<tr>\n\t <td>\n\t <input type='hidden' name='protocol' value='" . $_POST['protocol'] . "'/>\n\t";
if ($_POST['protocol'] == "lgsl") {
echo "LGSL Query Name</td><td><select name='query_name'>";
require 'protocol/lgsl/lgsl_protocol.php';
$lgsl_type_list = lgsl_type_list();
asort($lgsl_type_list);
foreach ($lgsl_type_list as $type => $description) {
echo "<option value='{$type}'>{$description}</option>";
}
} elseif ($_POST['protocol'] == "gameq") {
require 'protocol/GameQ/GameQ.php';
// Define the protocols path
$protocols_path = "protocol/GameQ/gameq/protocols/";
// Grab the dir with all the classes available
$dir = dir($protocols_path);
$protocols = array();
// Now lets loop the directories
while (false !== ($entry = $dir->read())) {
if (!is_file($protocols_path . $entry)) {
continue;
}
// Figure out the class name
$class_name = 'GameQ_Protocols_' . ucfirst(pathinfo($entry, PATHINFO_FILENAME));
// Lets get some info on the class
$reflection = new ReflectionClass($class_name);
// Check to make sure we can actually load the class
if (!$reflection->IsInstantiable()) {
continue;
}
// Load up the class so we can get info
$class = new $class_name();
// Add it to the list
$protocols[$class->name()] = array('name' => $class->name_long(), 'port' => $class->port(), 'state' => $class->state());
// Unset the class
unset($class);
}
// Close the directory
unset($dir);
ksort($protocols);
echo "GameQ Query Name</td><td><select name='query_name'>";
foreach ($protocols as $gameq => $info) {
echo "<option value='" . $gameq . "'>" . htmlentities($info['name']) . "</option>";
}
}
echo "\n\t </select>\n\t </td>\n\t</tr>";
} else {
}
?>
<tr>
<td>
OS:
</td>
<td>
<select name="os">
<option value="linux">Linux</option>
<option value="win">Windows</option>
</select>
</td>
</tr>
<tr>
<td>
Architecture
</td>
<td>
<select name="arch">
<option value="32">32bit</option>
<option value="64">64bit</option>
</select>
//.........这里部分代码省略.........
示例12: dir
$protocols_path = GAMEQ_BASE . 'gameq/protocols/';
// Grab the dir with all the classes available
$dir = dir($protocols_path);
$protocols = array();
// Now lets loop the directories
while (false !== ($entry = $dir->read())) {
if (!is_file($protocols_path . $entry)) {
continue;
}
// Figure out the class name
$class_name = 'GameQ_Protocols_' . ucfirst(pathinfo($entry, PATHINFO_FILENAME));
// Lets get some info on the class
$reflection = new ReflectionClass($class_name);
// Check to make sure we can actually load the class
try {
if (!$reflection->IsInstantiable()) {
continue;
}
// Load up the class so we can get info
$class = new $class_name();
// Add it to the list
$protocols[$class->name()] = $class->name_long();
// Unset the class
unset($class);
} catch (ReflectionException $e) {
$errors['reflection'] = $e->getMessage();
}
}
// Close the directory
unset($dir);
ksort($protocols);
示例13: Instantiate
protected final function Instantiate($classname)
{
$classname = ucfirst(strtolower(trim($classname)));
$classfile = PANEL_BASE_PATH . '/server/modules/comp/' . $classname . '.class.php';
if (is_file($classfile)) {
require_once $classfile;
}
if (!class_exists($classname, false)) {
exit('ERROR: ' . $classname . ' is not defined as a Class');
}
$class = new ReflectionClass($classname);
if (!$class->isSubclassOf('PanelCommon')) {
exit("ERROR: {$classname} must extends PanelCommon");
}
if (!$class->isUserDefined()) {
exit("ERROR: {$classname} must be user defined and not internal to PHP");
}
if (!$class->IsInstantiable()) {
exit("ERROR: {$classname} must be instantiable and not an Interface or Abstract class");
}
if (!$class->hasMethod('home')) {
exit("ERROR: {$classname} lacks required method/function home()");
}
if (!$class->hasProperty('menu')) {
exit("ERROR: {$classname} lacks \$menu as a class property");
}
return new $classname();
}
示例14: _checkMethods
/**
* Check and Add/delete controller Methods
*
* @param string $className The classname to check
* @param string $controllerName The controller name
* @param array $node The node to check.
* @param string $pluginPath The plugin path to use.
* @return void
*/
protected function _checkMethods($className, $controllerName, $node, $pluginPath = false)
{
$excludes = $this->_getCallbacks($className, $pluginPath);
$baseMethods = get_class_methods(new Controller());
$namespace = $this->_getNamespace($className, $pluginPath);
$reflectionClass = new \ReflectionClass($namespace);
$actions = null;
if ($reflectionClass->IsInstantiable()) {
$methods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
$actions[] = $method->getName();
}
}
$prefix = $this->_getPrefix($namespace, $pluginPath);
if ($actions == null) {
$this->err(__d('cake_acl', 'Unable to get methods for {0}', $className));
return false;
}
$methods = array_diff($actions, $baseMethods);
$methods = array_diff($methods, $excludes);
foreach ($methods as $key => $action) {
if (strpos($action, '_', 0) === 0) {
continue;
}
$path = $this->rootNode . '/' . $pluginPath . $controllerName . '/' . $prefix . $action;
$this->_checkNode($path, $prefix . $action, $node->id);
$methods[$key] = $prefix . $action;
}
if ($this->_clean) {
$actionNodes = $this->Aco->find('children', ['for' => $node->id]);
$methodFlip = array_flip($methods);
foreach ($actionNodes as $action) {
if (!isset($methodFlip[$action->alias])) {
$entity = $this->Aco->get($action->id);
if ($this->Aco->delete($entity)) {
$path = $this->rootNode . '/' . $controllerName . '/' . $action->alias;
$this->out(__d('cake_acl', 'Deleted Aco node: <warning>{0}</warning>', $path));
}
}
}
}
return true;
}
示例15: load
/**
* Load a module
*
* @param string $path path of module
*/
public static function load($path)
{
$basePath = basename($path);
if (!empty(self::$list[$basePath])) {
return;
}
self::$list[$basePath] = $path;
if (file_exists($path . '/boot.php')) {
include $path . '/boot.php';
}
$files = self::getAllFiles($path . "/Controller");
foreach ($files as $file) {
self::$files[] = $file;
require_once $file;
$name_class = str_replace(PATH_SRC, "", $file);
$name_class = str_replace("/", "\\", $name_class);
$name_class = str_replace(".php", "", $name_class);
if (is_subclass_of($name_class, Controller::class)) {
$reflectionClass = new \ReflectionClass($name_class);
if ($reflectionClass->IsInstantiable()) {
self::$controllers[] = new $name_class();
}
}
}
$files = self::getAllFiles($path . "/Command");
foreach ($files as $file) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ($ext == 'php') {
self::$files[] = $file;
require_once $file;
$name_class = str_replace(PATH_SRC, "", $file);
$name_class = str_replace("/", "\\", $name_class);
$name_class = str_replace(".php", "", $name_class);
if (is_subclass_of($name_class, Command::class)) {
Console::addCommand($name_class);
}
}
}
if (file_exists($path . "/Exceptions/Handler.php")) {
$name_class = str_replace(PATH_SRC, "", $path . "/Exceptions/Handler.php");
$name_class = str_replace("/", "\\", $name_class);
$name_class = str_replace(".php", "", $name_class);
if (is_subclass_of($name_class, \Kernel\Exceptions\ExceptionHandler::class)) {
\Kernel\Exceptions\Handler::add($name_class);
}
}
$files = self::getAllFiles($path . "/Service");
foreach ($files as $file) {
self::$files[] = $file;
require_once $file;
$name_class = str_replace(PATH_SRC, "", $file);
$name_class = str_replace("/", "\\", $name_class);
$name_class = str_replace(".php", "", $name_class);
if (is_subclass_of($name_class, Service::class)) {
$last_name = explode("\\", $name_class);
$last_name = end($last_name);
class_alias($name_class, $last_name);
}
}
if (!file_exists(PATH . "/src/")) {
mkdir(PATH . "/src", 0755);
}
# Create symlink to access
if (!file_exists(PATH . "/src/" . $basePath)) {
if (file_exists(PATH . "/../src/" . $basePath . "/Resources/public/")) {
try {
symlink(PATH . "/../src/" . $basePath . "/Resources/public/", PATH . "/src/" . $basePath);
} catch (\Exception $e) {
throw new \Exception($e);
}
}
}
# Set config
foreach (glob($path . '/Resources/config/*') as $file) {
$cfgs = (require_once $file);
$base = basename($file, ".php");
foreach ($cfgs as $cfg_name => $cfg_value) {
Cfg::set($base . "." . $cfg_name, $cfg_value);
}
}
}