Пример #1
0
 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
0
 /**
  * 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;
 }
Пример #3
0
 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
0
 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));
     }
 }
Пример #5
0
 /**
  * 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;
 }
 /**
  * @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}'.");
             }
         }
     }
 }
Пример #7
0
 /**
  * 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
0
 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
0
 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);
     }
 }
 /**
  * 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;
 }
Пример #11
0
 /**
  *
  */
 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");
     }
 }
Пример #12
0
 /**
  *
  */
 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");
     }
 }
Пример #13
0
function classOrTraitExists($classOrTrait, $shouldAutoload = true)
{
    if (traitsSupported()) {
        if (trait_exists($classOrTrait, $shouldAutoload)) {
            return true;
        }
    }
    return class_exists($classOrTrait, $shouldAutoload);
}
Пример #14
0
 /**
  * @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");
     }
 }
 /**
  * {@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));
         }
     }
 }
Пример #16
0
 /**
  * @param $level string
  */
 public function activatePlugins($level = null)
 {
     foreach ($this->plugins_tree as $tree_level => $plugins) {
         foreach (array_keys($plugins) as $class_name) {
             if (class_exists($class_name, false) || trait_exists($class_name, false) || $tree_level === $level) {
                 $this->get($class_name, $level);
             }
         }
     }
 }
 /**
  * @param string $className
  *
  * @return self
  */
 public static function fromNonExistingClass($className)
 {
     if (interface_exists($className)) {
         return new self(sprintf('The provided type "%s" is an interface, and can not be instantiated', $className));
     }
     if (PHP_VERSION_ID >= 50400 && trait_exists($className)) {
         return new self(sprintf('The provided type "%s" is a trait, and can not be instantiated', $className));
     }
     return new self(sprintf('The provided class "%s" does not exist', $className));
 }
 /**
  * @param $mockRequest
  *
  * @return string
  */
 private static function getType($mockRequest)
 {
     if (class_exists($mockRequest) || interface_exists($mockRequest) || trait_exists($mockRequest)) {
         return 'class';
     }
     if (preg_match("/^[\\w\\\\_]*(::|->)[\\w\\d_]+/um", $mockRequest)) {
         return 'method';
     }
     return 'function';
 }
 /**
  * throws exceptions if $item is not a PHP class or interface that exists
  *
  * this is a wrapper around our IsDefinedObjectType check
  *
  * @param  mixed $item
  *         the container to check
  * @param  string $eNoSuchClass
  *         the exception to throw if $item isn't a valid PHP class
  * @param  string $eUnsupportedType
  *         the exception to throw if $item isn't something that we can check
  * @return void
  */
 public static function check($item, $eNoSuchClass = E4xx_NoSuchClass::class, $eUnsupportedType = E4xx_UnsupportedType::class)
 {
     RequireStringy::check($item, $eUnsupportedType);
     if (trait_exists($item)) {
         throw new $eUnsupportedType(SimpleType::from($item));
     }
     // make sure we have a PHP class that exists
     if (!IsDefinedObjectType::check($item)) {
         throw new $eNoSuchClass($item);
     }
 }
Пример #20
0
 /**
  * Loads a class, interface or trait by name.
  *
  * @param string $name the name of the class, interface or trait to load
  * @throws ClassNotFoundException when the class, interface or trait doesn't exist
  */
 private function load($name)
 {
     $path = $this->rootDirectory . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $name) . '.php';
     if (is_readable($path)) {
         require $path;
     } else {
         throw new ClassNotFoundException("Could not find file {$path}");
     }
     if (!class_exists($name) && !interface_exists($name) && (function_exists('trait_exists') && !trait_exists($name))) {
         throw new ClassNotFoundException("Could not find class, interface or trait {$name}");
     }
 }
 /**
  * Get a ReflectionClass (or ReflectionObject) if possible.
  *
  * @throws \InvalidArgumentException if $value is not a class name or instance.
  *
  * @param mixed $value
  *
  * @return \ReflectionClass
  */
 private static function getClass($value)
 {
     if (is_object($value)) {
         return new \ReflectionObject($value);
     }
     if (!is_string($value)) {
         throw new \InvalidArgumentException('Mirror expects an object or class');
     } elseif (!class_exists($value) && !interface_exists($value) && !(function_exists('trait_exists') && trait_exists($value))) {
         throw new \InvalidArgumentException('Unknown class or function: ' . $value);
     }
     return new \ReflectionClass($value);
 }
Пример #22
0
 public static function autoload($className)
 {
     if (isset(static::$classMap[$className])) {
         $classFile = static::$classMap[$className];
     } else {
         return;
     }
     include $classFile;
     if (!class_exists($className, false) && !interface_exists($className, false) && !trait_exists($className, false)) {
         throw new \Exception("Unable to find '{$className}' in file: {$classFile}. Namespace missing?");
     }
 }
Пример #23
0
 /**
  * Determine the type of class
  */
 protected function computeType()
 {
     if (interface_exists($this->class, false)) {
         $this->type = 'Interface';
         return;
     }
     if (trait_exists($this->class, false)) {
         $this->type = 'Trait';
         return;
     }
     $this->type = 'Class';
 }
 public static function instance($class)
 {
     \Arg::_($class, 'Class name')->is_string()->assert(class_exists($class) || interface_exists($class) || trait_exists($class), 'Class must be a defined one');
     $instance = new self();
     $instance->requestClassName = $class;
     $instance->isStaticMethod = false;
     $instance->isInstanceMethod = true;
     $instance->isFunction = false;
     $instance->isMethod = true;
     $instance->methodName = '';
     return $instance;
 }
Пример #25
0
 private function debugInfo($fl, $class)
 {
     if (trait_exists($class)) {
         $type = "trait";
     } elseif (class_exists($class, false)) {
         $type = "class";
     } elseif (interface_exists($class, false)) {
         $type = "interface";
     } else {
         $type = "<???>";
     }
     $this->debug("Autoloaded %s for %s %s", $fl, $type, $class);
 }
 /**
  * @param Identifier $identifier
  *
  * @return null|string
  */
 private function getInternalReflectionClassName(Identifier $identifier)
 {
     if (!$identifier->isClass()) {
         return null;
     }
     $name = $identifier->getName();
     if (!(class_exists($name, false) || interface_exists($name, false) || trait_exists($name, false))) {
         return null;
         // not an available internal class
     }
     $reflection = new \ReflectionClass($name);
     return $reflection->getFileName() ? $reflection->getName() : null;
 }
 /**
  * do we have the name of a trait that has been defined?
  *
  * @param mixed $name
  *        the name to check
  * @return boolean
  *         TRUE if $name is a trait that has been defined
  *         FALSE otherwise
  */
 public static function check($name)
 {
     // this prevents PHP runtime errors
     if (!IsStringy::check($name)) {
         return false;
     }
     // general cases
     if (trait_exists($name)) {
         return true;
     }
     // if we get here, we have run out of ideas
     return false;
 }
Пример #28
0
 /**
  * Loads the given class or interface.
  *
  * @param string $class The name of the class
  *
  * @return Boolean|null True, if loaded
  */
 public function loadClass($class)
 {
     if ($file = $this->classFinder->findFile($class)) {
         require $file;
         if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
             if (false !== strpos($class, '/')) {
                 throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\\" in PHP, not "/".', $class));
             }
             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));
         }
         return true;
     }
 }
Пример #29
0
 /**
  * Loads a Mock Object Class
  */
 protected function loadMock($name)
 {
     $path = dirname(__FILE__) . '/Mock';
     $name = 'Jazz\\Test\\Mock' . str_replace(array('Jazz\\Test\\Mock', 'Jazz_Test_Mock'), '', $name);
     if (!(class_exists($name, false) || interface_exists($name, false) || trait_exists($name, false))) {
         // define the path to the file
         $path .= '/' . str_replace(array('_', '\\'), '/', substr($name, 14)) . '.php';
         if (!file_exists($path)) {
             throw new \Exception('File Does Not Exist: ' . $path);
         }
         require_once $path;
     }
     return true;
 }
Пример #30
-4
function autoload($class)
{
    if (strpos($class, __NAMESPACE__ . '\\') === 0) {
        $file = __DIR__ . '/' . str_replace('\\', '/', substr($class, strlen(__NAMESPACE__) + 1)) . '.php';
        require $file;
        if (!class_exists($class, false) && !interface_exists($class, false) && !trait_exists($class, false)) {
            throw new \Exception('Class "' . $class . '" not found as expected in "' . $file . '"');
        }
    }
}