本文整理汇总了PHP中method_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP method_exists函数的具体用法?PHP method_exists怎么用?PHP method_exists使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了method_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
public function __call($s_method_name, $arr_arguments)
{
if (!method_exists($this, $s_method_name)) {
// если еще не имлементировали
$s_match = "";
$s_method_prefix = '';
$s_method_base = '';
$arr_matches = array();
$bSucc = preg_match("/[A-Z_]/", $s_method_name, $arr_matches);
if ($bSucc) {
$s_match = $arr_matches[0];
$i_match = strpos($s_method_name, $s_match);
$s_method_prefix = substr($s_method_name, 0, $i_match) . "/";
$s_method_base = substr($s_method_name, 0, $i_match + ($s_match === "_" ? 1 : 0));
}
$s_class_enter = "__" . $s_method_name;
// метод, общий для всех режимов
if (!class_exists($s_class_enter)) {
$s_entermethod_lib = "methods/" . $s_method_prefix . "__" . $s_method_name . ".lib.php";
$this->__loadLib($s_entermethod_lib);
$this->__implement($s_class_enter);
}
$s_class_mode = "__" . $s_method_name . "_";
// метод, выбираемый в зависимости от режима
if (!class_exists($s_class_mode)) {
$s_modemethod_lib = "methods/" . $s_method_prefix . "__" . $s_method_name . "_" . cmsController::getInstance()->getCurrentMode() . ".lib.php";
$this->__loadLib($s_modemethod_lib);
$this->__implement($s_class_mode);
}
}
return parent::__call($s_method_name, $arr_arguments);
}
示例2: __get
public function __get($name)
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->{$method}();
}
}
示例3: setValue
/**
* Sets selected items (by keys).
* @param array
* @return self
*/
public function setValue($values)
{
if (is_scalar($values) || $values === NULL) {
$values = (array) $values;
} elseif (!is_array($values)) {
throw new Nette\InvalidArgumentException(sprintf("Value must be array or NULL, %s given in field '%s'.", gettype($values), $this->name));
}
$flip = [];
foreach ($values as $value) {
if (!is_scalar($value) && !method_exists($value, '__toString')) {
throw new Nette\InvalidArgumentException(sprintf("Values must be scalar, %s given in field '%s'.", gettype($value), $this->name));
}
$flip[(string) $value] = TRUE;
}
$values = array_keys($flip);
if ($this->checkAllowedValues && ($diff = array_diff($values, array_keys($this->items)))) {
$set = Nette\Utils\Strings::truncate(implode(', ', array_map(function ($s) {
return var_export($s, TRUE);
}, array_keys($this->items))), 70, '...');
$vals = (count($diff) > 1 ? 's' : '') . " '" . implode("', '", $diff) . "'";
throw new Nette\InvalidArgumentException("Value{$vals} are out of allowed set [{$set}] in field '{$this->name}'.");
}
$this->value = $values;
return $this;
}
示例4: load
public function load(TemplateReferenceInterface $template)
{
if (method_exists($this, $method = 'get' . ucfirst($template->get('name')) . 'Template')) {
return new StringStorage($this->{$method}());
}
return false;
}
示例5: pipe
/**
* Add middleware to the pipe-line. Please note that middleware's will
* be called in the order they are added.
*
* A middleware CAN implement the Middleware Interface, but MUST be
* callable. A middleware WILL be called with three parameters:
* Request, Response and Next.
*
* @throws \RuntimeException when adding middleware to the stack to late
* @param callable $middleware
*/
public function pipe(callable $middleware)
{
// Check if the pipeline is locked
if ($this->locked) {
throw new \RuntimeException('Middleware can’t be added once the stack is dequeuing');
}
// Inject the dependency injection container
if (method_exists($middleware, 'setContainer') && $this->container !== null) {
$middleware->setContainer($this->container);
}
// Force serializers to register mime types
if ($middleware instanceof SerializerMiddleware) {
$middleware->registerMimeTypes();
}
// Add the middleware to the queue
$this->queue->enqueue($middleware);
// Check if middleware should be added to the error queue
if (!$this->errorQueueLocked) {
$this->errorQueue->enqueue($middleware);
// Check if we should lock the error queue
if ($middleware instanceof ErrorMiddleware) {
$this->errorQueueLocked = true;
}
}
}
示例6: validateString
/**
* validate a string
*
* @param mixed $str the value to evaluate as a string
*
* @throws \InvalidArgumentException if the submitted data can not be converted to string
*
* @return string
*/
protected function validateString($str)
{
if (is_object($str) && method_exists($str, '__toString') || is_string($str)) {
return trim($str);
}
throw new InvalidArgumentException('The data received is not OR can not be converted into a string');
}
示例7: __call
public function __call($func, $args)
{
$connectionObj = $this->connections[$this->defaultConnection];
if (method_exists($connectionObj, $func)) {
call_user_func_array([$connectionObj, $func], $args);
}
}
示例8: createLinks
/**
* Create the links for resources in the resource root
* @return array the links, name => config
*/
protected function createLinks()
{
$app = \Yii::app();
/* @var \Restyii\Web\Application $app */
$controller = $this->getController();
$module = $controller->getModule();
if (!$module) {
$module = $app;
}
$controllers = $app->getSchema()->getControllerInstances($module);
/* @var \Restyii\Controller\Base[]|\CController[] $controllers */
$links = array('self' => array('title' => $module->name, 'href' => trim($app->getBaseUrl(), '/') . '/'));
foreach ($controllers as $id => $controller) {
if ($id === $module->defaultController) {
continue;
}
$links[$id] = array('title' => method_exists($controller, 'classLabel') ? $controller->classLabel(true) : String::pluralize(String::humanize(substr(get_class($controller), 0, -10))), 'href' => $controller->createUrl('search'));
if (method_exists($controller, 'classDescription')) {
$links[$id]['description'] = $controller->classDescription();
}
if (isset($controller->modelClass)) {
$links[$id]['profile'] = array($controller->modelClass);
}
}
return $links;
}
示例9: parse
static function parse($args)
{
$method = strtolower(@$args[1]);
$string = @$args[0];
if (empty($string)) {
return false;
}
if (!method_exists('kirbytext', $method)) {
return $string;
}
$replace = array('(', ')');
$string = str_replace($replace, '', $string);
$attr = array_merge(self::$tags, self::$attr);
$search = preg_split('!(' . implode('|', $attr) . '):!i', $string, false, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$result = array();
$num = 0;
foreach ($search as $key) {
if (!isset($search[$num + 1])) {
break;
}
$key = trim($search[$num]);
$value = trim($search[$num + 1]);
$result[$key] = $value;
$num = $num + 2;
}
return self::$method($result);
}
示例10: __construct
/**
* Make a new experiment with given variants
*
* @since 0.1.0
*
* @param array $variants
* @param int|string $id Experiment (group) ID
* @param \MaBandit\MaBandit $bandit MaBandit object
*/
public function __construct(array $variants, $id, \MaBandit\MaBandit $bandit)
{
$this->experiment = $bandit->createExperiment((string) $id, $variants);
if (method_exists($bandit->getPersistor(), 'save_levers')) {
$bandit->getPersistor()->batchSave($this->experiment->getLevers(), $id);
}
}
示例11: displayLayout
function displayLayout($layout=null, $tpl = null) {
if ($layout) $this->setLayout ($layout);
$viewName = ucfirst($this->getName ());
$layoutName = ucfirst($this->getLayout ());
KUNENA_PROFILER ? $this->profiler->start("display {$viewName}/{$layoutName}") : null;
if (isset($this->common)) {
if ($this->config->board_offline && ! $this->me->isAdmin ()) {
// Forum is offline
$this->common->header = JText::_('COM_KUNENA_FORUM_IS_OFFLINE');
$this->common->body = $this->config->offline_message;
$this->common->display('default');
KUNENA_PROFILER ? $this->profiler->start("display {$viewName}/{$layoutName}") : null;
return;
} elseif ($this->config->regonly && ! $this->me->exists()) {
// Forum is for registered users only
$this->common->header = JText::_('COM_KUNENA_LOGIN_NOTIFICATION');
$this->common->body = JText::_('COM_KUNENA_LOGIN_FORUM');
$this->common->display('default');
KUNENA_PROFILER ? $this->profiler->start("display {$viewName}/{$layoutName}") : null;
return;
}
}
$this->assignRef ( 'state', $this->get ( 'State' ) );
$layoutFunction = 'display'.$layoutName;
if (method_exists($this, $layoutFunction)) {
$contents = $this->$layoutFunction ($tpl);
} else {
$contents = $this->display($tpl);
}
KUNENA_PROFILER ? $this->profiler->stop("display {$viewName}/{$layoutName}") : null;
return $contents;
}
示例12: testGenerator
public function testGenerator()
{
/** @var OpsWay\Test2\Solid\I $generator */
$generator = OpsWay\Test2\Solid\Factory::create('i');
$generator->generate();
$this->assertFileExists($file = __DIR__ . '/../../test/I/IGeometric.php');
include $file;
$this->assertTrue(interface_exists('IGeometric'));
$this->assertFileExists($file = __DIR__ . '/../../test/I/IAngular.php');
include $file;
$this->assertTrue(interface_exists('IAngular'));
$this->assertFileExists($file = __DIR__ . '/../../test/I/ISquarable.php');
include $file;
$this->assertTrue(interface_exists('ISquarable'));
$this->assertFileExists($file = __DIR__ . '/../../test/I/Square.php');
include $file;
$this->assertTrue(class_exists('Square'));
$this->assertTrue(in_array('IGeometric', class_implements('Square')));
$this->assertFileExists($file = __DIR__ . '/../../test/I/Circle.php');
include $file;
$this->assertTrue(class_exists('Circle'));
$this->assertTrue(in_array('IGeometric', class_implements('Circle')));
$this->assertTrue(method_exists('IGeometric', 'square'));
$this->assertTrue(method_exists('ISquarable', 'square'));
$this->assertTrue(method_exists('IAngular', 'countAngles'));
}
示例13: __construct
/**
* Constructor.
*
* @param callable|object $classLoader Passing an object is @deprecated since version 2.5 and support for it will be removed in 3.0
*/
public function __construct($classLoader)
{
$this->wasFinder = is_object($classLoader) && method_exists($classLoader, 'findFile');
if ($this->wasFinder) {
@trigger_error('The ' . __METHOD__ . ' method will no longer support receiving an object into its $classLoader argument in 3.0.', E_USER_DEPRECATED);
$this->classLoader = array($classLoader, 'loadClass');
$this->isFinder = true;
} else {
$this->classLoader = $classLoader;
$this->isFinder = is_array($classLoader) && method_exists($classLoader[0], 'findFile');
}
if (!isset(self::$caseCheck)) {
$file = file_exists(__FILE__) ? __FILE__ : rtrim(realpath('.'), DIRECTORY_SEPARATOR);
$i = strrpos($file, DIRECTORY_SEPARATOR);
$dir = substr($file, 0, 1 + $i);
$file = substr($file, 1 + $i);
$test = strtoupper($file) === $file ? strtolower($file) : strtoupper($file);
$test = realpath($dir . $test);
if (false === $test || false === $i) {
// filesystem is case sensitive
self::$caseCheck = 0;
} elseif (substr($test, -strlen($file)) === $file) {
// filesystem is case insensitive and realpath() normalizes the case of characters
self::$caseCheck = 1;
} elseif (false !== stripos(PHP_OS, 'darwin')) {
// on MacOSX, HFS+ is case insensitive but realpath() doesn't normalize the case of characters
self::$caseCheck = 2;
} else {
// filesystem case checks failed, fallback to disabling them
self::$caseCheck = 0;
}
}
}
示例14: render
/**
* Render captcha
*
* @param string $content
*
* @return string
*/
public function render($content)
{
$element = $this->getElement();
if (!method_exists($element, 'getCaptcha')) {
return $content;
}
$view = $element->getView();
if (null === $view) {
return $content;
}
$placement = $this->getPlacement();
$separator = $this->getSeparator();
/** @var \Zend_Captcha_Adapter $captcha */
$captcha = $element->getCaptcha();
$markup = '<label>' . $captcha->render($view) . '</label>';
switch ($placement) {
case 'PREPEND':
$content = $markup . $separator . $content;
break;
case 'APPEND':
default:
$content = $content . $separator . $markup;
break;
}
return $content;
}
示例15: processAPI
public function processAPI()
{
if (method_exists($this, $this->endpoint)) {
return $this->_response($this->{$this->endpoint}($this->args));
}
return $this->_response("No Endpoint: {$this->endpoint}", 404);
}