GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
BaseClassLoader Class Reference

Public Member Functions

 __construct (ClassLoader $parent=null)
 
 addPath ($path, $prepend=false)
 
 removePath ($path)
 
 getClasses ()
 
 getParent ()
 
 register ($prepend=false)
 
 loadClass ($name)
 
 findClass ($name)
 
- Public Member Functions inherited from Threaded
 chunk ($size, bool $preserve=false)
 
 count ()
 
 isRunning ()
 
 isTerminated ()
 
 merge ($from, $overwrite=true)
 
 notify ()
 
 notifyOne ()
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 pop ()
 
 run ()
 
 shift ()
 
 synchronized (\Closure $function, $args=null)
 
 wait ($timeout)
 
 getRefCount ()
 
 addRef ()
 
 delRef ()
 
 isGarbage ()
 

Protected Member Functions

 getAndRemoveLookupEntries ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Threaded
static extend ($obj)
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( ClassLoader  $parent = null)
Parameters
ClassLoader$parent

Implements ClassLoader.

31  {
32  $this->parent = $parent;
33  $this->lookup = new \Threaded;
34  $this->classes = new \Threaded;
35  }

Member Function Documentation

◆ addPath()

addPath (   $path,
  $prepend = false 
)

Adds a path to the lookup list

Parameters
string$path
bool$prepend

Implements ClassLoader.

43  {
44 
45  foreach($this->lookup as $p){
46  if($p === $path){
47  return;
48  }
49  }
50 
51  if($prepend){
52  $this->synchronized(function($path){
53  $entries = $this->getAndRemoveLookupEntries();
54  $this->lookup[] = $path;
55  foreach($entries as $entry){
56  $this->lookup[] = $entry;
57  }
58  }, $path);
59  }else{
60  $this->lookup[] = $path;
61  }
62  }

◆ findClass()

findClass (   $name)

Returns the path for the class, if any

Parameters
string$name
Returns
string|null

Implements ClassLoader.

157  {
158  $components = explode("\\", $name);
159 
160  $baseName = implode(DIRECTORY_SEPARATOR, $components);
161 
162 
163  foreach($this->lookup as $path){
164  if(PHP_INT_SIZE === 8 and file_exists($path . DIRECTORY_SEPARATOR . $baseName . "__64bit.php")){
165  return $path . DIRECTORY_SEPARATOR . $baseName . "__64bit.php";
166  }elseif(PHP_INT_SIZE === 4 and file_exists($path . DIRECTORY_SEPARATOR . $baseName . "__32bit.php")){
167  return $path . DIRECTORY_SEPARATOR . $baseName . "__32bit.php";
168  }elseif(file_exists($path . DIRECTORY_SEPARATOR . $baseName . ".php")){
169  return $path . DIRECTORY_SEPARATOR . $baseName . ".php";
170  }
171  }
172 
173  return null;
174  }

◆ getAndRemoveLookupEntries()

getAndRemoveLookupEntries ( )
protected
64  {
65  $entries = [];
66  while($this->count() > 0){
67  $entries[] = $this->shift();
68  }
69  return $entries;
70  }

◆ getClasses()

getClasses ( )

Returns an array of the classes loaded

Returns
string[]

Implements ClassLoader.

90  {
91  $classes = [];
92  foreach($this->classes as $class){
93  $classes[] = $class;
94  }
95  return $classes;
96  }

◆ getParent()

getParent ( )

Returns the parent ClassLoader, if any

Returns
ClassLoader

Implements ClassLoader.

103  {
104  return $this->parent;
105  }

◆ loadClass()

loadClass (   $name)

Called when there is a class to load

Parameters
string$name
Returns
bool

Implements ClassLoader.

125  {
126  $path = $this->findClass($name);
127  if($path !== null){
128  include($path);
129  if(!class_exists($name, false) and !interface_exists($name, false) and !trait_exists($name, false)){
130  if($this->getParent() === null){
131  throw new ClassNotFoundException("Class $name not found");
132  }
133  return false;
134  }
135 
136  if(method_exists($name, "onClassLoaded") and (new ReflectionClass($name))->getMethod("onClassLoaded")->isStatic()){
137  $name::onClassLoaded();
138  }
139 
140  $this->classes[] = $name;
141 
142  return true;
143  }elseif($this->getParent() === null){
144  throw new ClassNotFoundException("Class $name not found");
145  }
146 
147  return false;
148  }

◆ register()

register (   $prepend = false)

Attaches the ClassLoader to the PHP runtime

Parameters
bool$prepend
Returns
bool

Implements ClassLoader.

114  {
115  spl_autoload_register([$this, "loadClass"], true, $prepend);
116  }

◆ removePath()

removePath (   $path)

Removes a path from the lookup list

Parameters
$path

Implements ClassLoader.

77  {
78  foreach($this->lookup as $i => $p){
79  if($p === $path){
80  unset($this->lookup[$i]);
81  }
82  }
83  }

The documentation for this class was generated from the following file: