本文整理汇总了PHP中trait_exists函数的典型用法代码示例。如果您正苦于以下问题:PHP trait_exists函数的具体用法?PHP trait_exists怎么用?PHP trait_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了trait_exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoload
function autoload($className)
{
global $loads;
$classNameOld = $className;
$className = str_replace("nextfw\\", "", strtolower(ltrim($className, '\\')));
$fileName = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
if (file_exists(PATH . $fileName)) {
require_once PATH . $fileName;
$loads[] = PATH . $fileName;
}
$type = null;
if (!class_exists($classNameOld)) {
$type = "Class";
} elseif (!trait_exists($classNameOld) and class_exists($classNameOld)) {
$type = "Trait";
} elseif (!interface_exists($classNameOld) and (trait_exists($classNameOld) and class_exists($classNameOld))) {
$type = "Interface";
}
if ($type != null) {
header('HTTP/1.0 404 Not Found');
}
}
示例2: loadClass
public function loadClass($class_name)
{
if ($this->runAutoloaders($class_name)) {
return;
}
if ($this->composerAutoloader->loadClass($class_name)) {
return;
}
if (is_int(strpos($class_name, '\\'))) {
$parts = explode('\\', $class_name);
$file = array_pop($parts);
$class_file_path = implode('/', $parts) . '/' . $file . '.php';
} else {
$class_file_path = str_replace('_', '/', $class_name) . '.php';
}
$paths = $this->paths;
$found = false;
foreach ($paths as $path) {
if ($found = is_file($class_file = $path . '/' . $class_file_path)) {
break;
}
}
if (!$found) {
require_once __DIR__ . '/Exception/FileNotFoundException.php';
throw new Exception\FileNotFoundException(sprintf("Couldn't find file for class %s, searched for %s in:\n%s", $class_name, $class_file_path, implode("\n", $paths)));
}
require $class_file;
if (!class_exists($class_name, false) && !interface_exists($class_name, false) && !trait_exists($class_name, false)) {
require_once __DIR__ . '/Exception/ClassNotFoundException.php';
throw new Exception\ClassNotFoundException(sprintf("File %s doesn't contain class/interface/trait %s.", $class_file, $class_name));
}
}
示例3: class_parents
static function class_parents($c, $autoload = true)
{
if (is_object($c)) {
$class = get_class($c);
} else {
if (!class_exists($c, $autoload) && !interface_exists($c, false) && !trait_exists($c, false)) {
user_error(__FUNCTION__ . '(): Class ' . $c . ' does not exist and could not be loaded', E_USER_WARNING);
return false;
} else {
$c = self::ns2us($c);
}
}
/**/
if (!function_exists('class_parents')) {
$autoload = array();
while (false !== ($class = get_parent_class($class))) {
$autoload[$class] = $class;
}
/**/
} else {
$autoload = class_parents($c, false);
/**/
}
foreach ($autoload as $c) {
isset(self::$us2ns[$a = strtolower($c)]) && ($autoload[$c] = self::$us2ns[$a]);
}
return $autoload;
}
示例4: __construct
/**
* TypeVisitor constructor.
* @param $type
*/
public function __construct($type)
{
if (!class_exists($type) || interface_exists($type) || trait_exists($type)) {
throw new InvalidArgumentException($type . ' does not exist');
}
$this->type = $type;
}
示例5: includeAllRecursivePsr4
/**
* @param string $dir
* @param string $namespace
* @param array $skip
*
* @throws \Exception
*/
private function includeAllRecursivePsr4($dir, $namespace, array $skip)
{
foreach (scandir($dir) as $candidate) {
if ('.' === $candidate || '..' === $candidate) {
continue;
}
$path = $dir . '/' . $candidate;
if (in_array($path, $skip)) {
continue;
}
if (is_dir($path)) {
$this->includeAllRecursivePsr4($dir . '/' . $candidate, $namespace . '\\' . $candidate, $skip);
} elseif (is_file($path)) {
if ('.php' === substr($candidate, -4)) {
$class = $namespace . '\\' . substr($candidate, 0, -4);
if (class_exists($class)) {
continue;
}
if (interface_exists($class)) {
continue;
}
if (function_exists('trait_exists') && trait_exists($class)) {
continue;
}
throw new \Exception("Non-existing class, trait or interface '{$class}'.");
}
}
}
}
示例6: exists
/**
* Check whenever class or trait or interface exists.
* It does autoload if needed.
* @param string $class
* @return bool True if class or trait or interface exists
*/
public static function exists($class)
{
if (Blacklister::ignores($class)) {
return false;
}
if (self::isConfirmed($class)) {
return true;
}
try {
if (class_exists($class)) {
return self::confirm($class);
}
} catch (Exception $ex) {
// Some class loaders throw exception if class not found
}
try {
if (trait_exists($class)) {
return self::confirm($class);
}
} catch (Exception $ex) {
// Some class loaders throw exception if class not found
}
try {
if (interface_exists($class)) {
return self::confirm($class);
}
} catch (Exception $ex) {
// Some class loaders throw exception if class not found
}
Blacklister::ignore($class);
return false;
}
示例7: tryLoad
/**
* Handles autoloading of classes, interfaces or traits.
* @param string
* @return void
*/
public function tryLoad($type)
{
$type = ltrim(strtolower($type), '\\');
// PHP namespace bug #49143
$info =& $this->list[$type];
if ($this->autoRebuild && empty($this->checked[$type]) && (is_array($info) ? !is_file($info[0]) : $info < self::RETRY_LIMIT)) {
$info = is_int($info) ? $info + 1 : 0;
$this->checked[$type] = TRUE;
if ($this->rebuilt) {
$this->getCache()->save($this->getKey(), $this->list, array(Cache::CONSTS => 'Nette\\Framework::REVISION'));
} else {
$this->rebuild();
}
}
if (isset($info[0])) {
Nette\Utils\LimitedScope::load($info[0], TRUE);
if ($this->autoRebuild && !class_exists($type, FALSE) && !interface_exists($type, FALSE) && (PHP_VERSION_ID < 50400 || !trait_exists($type, FALSE))) {
$info = 0;
$this->checked[$type] = TRUE;
if ($this->rebuilt) {
$this->getCache()->save($this->getKey(), $this->list, array(Cache::CONSTS => 'Nette\\Framework::REVISION'));
} else {
$this->rebuild();
}
}
self::$count++;
}
}
示例8: run
public static function run($class)
{
// ----------------------------------------------------------------------------------------
// ClassMap oluşturulmamış ise oluştur.
// Sistemin çalışması için gerekli bir kontroldür.
// ----------------------------------------------------------------------------------------
$path = CONFIG_DIR . 'ClassMap.php';
// ClassMap daha önce oluşturulmamış ise oluturuluyor...
if (!file_exists($path)) {
self::createClassMap();
}
// Sınıf bilgileri alınıyor...
$classInfo = self::getClassFileInfo($class);
// Sınıfın yolu alınıyor...
$file = restorationPath($classInfo['path']);
// Böyle bir sınıf varsa dahil ediliyor...
if (file_exists($file)) {
require_once $file;
// Namespace olduğu halde class ismi bildirilirse
// Sınıf haritasını yeniden oluşturmayı dene
if (!class_exists($classInfo['namespace']) && !trait_exists($classInfo['namespace']) && !interface_exists($classInfo['namespace'])) {
self::tryAgainCreateClassMap($class);
}
} else {
// Aranılan dosya bulunamazsa 1 kereye mahsuz
// sınıf haritasını yeniden oluşturmayı dene
self::tryAgainCreateClassMap($class);
}
}
示例9: isValid
/**
* Determines if a given string can resolve correctly.
*
* @param string $name A fully qualified class name or namespace name.
*
* @return boolean true if the object exists within the source tree, the libraries or PHP.
*/
public function isValid($name)
{
$name = implode('\\', array_filter(explode('\\', $name), 'strlen'));
if (class_exists($name) || interface_exists($name) || trait_exists($name)) {
return true;
}
return false;
}
示例10: exists
private function exists(string $className) : bool
{
try {
return class_exists($className) || interface_exists($className) || trait_exists($className);
} catch (\Throwable $t) {
throw new \PHPStan\Broker\ClassAutoloadingException($className, $t);
}
}
示例11: __construct
/**
*
*/
public function __construct()
{
if (!class_exists('\\Crypto\\Cipher')) {
throw new \RuntimeException("The PHP extension 'Crypto' is required to use AES GCM based algorithms");
}
if (!trait_exists('\\AESKW\\AESKW')) {
throw new \RuntimeException("The library 'spomky-labs/aes-key-wrap' is required to use Key Wrap based algorithms");
}
}
示例12: loadClass
/**
* {@inheritDoc}
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
require $file;
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
throw new RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
}
}
示例13: __construct
/**
*
*/
public function __construct()
{
if (!trait_exists('\\AESKW\\AESKW')) {
throw new \RuntimeException("The library 'spomky-labs/aes-key-wrap' is required to use Key Wrap based algorithms");
}
if (!class_exists('\\PBKDF2\\PBKDF2')) {
throw new \RuntimeException("The library 'spomky-labs/pbkdf2' is required to use PBES2-* based algorithms");
}
}
示例14: Autoload
/**
* @param $className
* @throws Exception
*/
public static function Autoload($className)
{
echo 'Autoload : ' . $className;
$path = APP . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, strtolower($className)) . '.php';
@(include $path);
if (!class_exists($className, false) && !interface_exists($className, false) && !trait_exists($className, false)) {
throw new Exception("Class '" . $className . "' not found in '" . $path . "' on autoload");
}
}
示例15: classOrTraitExists
function classOrTraitExists($classOrTrait, $shouldAutoload = true)
{
if (traitsSupported()) {
if (trait_exists($classOrTrait, $shouldAutoload)) {
return true;
}
}
return class_exists($classOrTrait, $shouldAutoload);
}