/var
/www
/probeip
/vendor
/rdlowrey
/auryn
/lib
/Injector.php
} elseif (!$ctor->isPublic()) {
throw new InjectionException(
$this->inProgressMakes,
sprintf(self::M_NON_PUBLIC_CONSTRUCTOR, $className),
self::E_NON_PUBLIC_CONSTRUCTOR
);
} elseif ($ctorParams = $this->reflector->getCtorParams($className)) {
$reflClass = $this->reflector->getClass($className);
$definition = isset($this->classDefinitions[$normalizedClass])
? array_replace($this->classDefinitions[$normalizedClass], $definition)
: $definition;
$args = $this->provisionFuncArgs($ctor, $definition, $ctorParams);
$obj = $reflClass->newInstanceArgs($args);
} else {
$obj = $this->instantiateWithoutCtorParams($className);
}
return $obj;
} catch (\ReflectionException $e) {
throw new InjectionException(
$this->inProgressMakes,
sprintf(self::M_MAKE_FAILURE, $className, $e->getMessage()),
self::E_MAKE_FAILURE,
$e
);
}
}
private function instantiateWithoutCtorParams($className)
{
$reflClass = $this->reflector->getClass($className);
if (!$reflClass->isInstantiable()) {
$type = $reflClass->isInterface() ? 'interface' : 'abstract class';
throw new InjectionException(
$this->inProgressMakes,
sprintf(self::M_NEEDS_DEFINITION, $type, $className),
self::E_NEEDS_DEFINITION
);
}
/var
/www
/probeip
/vendor
/rdlowrey
/auryn
/lib
/CachingReflector.php
const CACHE_KEY_CTORS = 'auryn.refls.ctors.';
const CACHE_KEY_CTOR_PARAMS = 'auryn.refls.ctor-params.';
const CACHE_KEY_FUNCS = 'auryn.refls.funcs.';
const CACHE_KEY_METHODS = 'auryn.refls.methods.';
private $reflector;
private $cache;
public function __construct(Reflector $reflector = null, ReflectionCache $cache = null)
{
$this->reflector = $reflector ?: new StandardReflector;
$this->cache = $cache ?: new ReflectionCacheArray;
}
public function getClass($class)
{
$cacheKey = self::CACHE_KEY_CLASSES . strtolower($class);
if (!$reflectionClass = $this->cache->fetch($cacheKey)) {
$reflectionClass = new \ReflectionClass($class);
$this->cache->store($cacheKey, $reflectionClass);
}
return $reflectionClass;
}
public function getCtor($class)
{
$cacheKey = self::CACHE_KEY_CTORS . strtolower($class);
$reflectedCtor = $this->cache->fetch($cacheKey);
if ($reflectedCtor === false) {
$reflectionClass = $this->getClass($class);
$reflectedCtor = $reflectionClass->getConstructor();
$this->cache->store($cacheKey, $reflectedCtor);
}
return $reflectedCtor;
}
/var
/www
/probeip
/vendor
/rdlowrey
/auryn
/lib
/CachingReflector.php
const CACHE_KEY_CTORS = 'auryn.refls.ctors.';
const CACHE_KEY_CTOR_PARAMS = 'auryn.refls.ctor-params.';
const CACHE_KEY_FUNCS = 'auryn.refls.funcs.';
const CACHE_KEY_METHODS = 'auryn.refls.methods.';
private $reflector;
private $cache;
public function __construct(Reflector $reflector = null, ReflectionCache $cache = null)
{
$this->reflector = $reflector ?: new StandardReflector;
$this->cache = $cache ?: new ReflectionCacheArray;
}
public function getClass($class)
{
$cacheKey = self::CACHE_KEY_CLASSES . strtolower($class);
if (!$reflectionClass = $this->cache->fetch($cacheKey)) {
$reflectionClass = new \ReflectionClass($class);
$this->cache->store($cacheKey, $reflectionClass);
}
return $reflectionClass;
}
public function getCtor($class)
{
$cacheKey = self::CACHE_KEY_CTORS . strtolower($class);
$reflectedCtor = $this->cache->fetch($cacheKey);
if ($reflectedCtor === false) {
$reflectionClass = $this->getClass($class);
$reflectedCtor = $reflectionClass->getConstructor();
$this->cache->store($cacheKey, $reflectedCtor);
}
return $reflectedCtor;
}
/var
/www
/probeip
/vendor
/rdlowrey
/auryn
/lib
/CachingReflector.php
public function getClass($class)
{
$cacheKey = self::CACHE_KEY_CLASSES . strtolower($class);
if (!$reflectionClass = $this->cache->fetch($cacheKey)) {
$reflectionClass = new \ReflectionClass($class);
$this->cache->store($cacheKey, $reflectionClass);
}
return $reflectionClass;
}
public function getCtor($class)
{
$cacheKey = self::CACHE_KEY_CTORS . strtolower($class);
$reflectedCtor = $this->cache->fetch($cacheKey);
if ($reflectedCtor === false) {
$reflectionClass = $this->getClass($class);
$reflectedCtor = $reflectionClass->getConstructor();
$this->cache->store($cacheKey, $reflectedCtor);
}
return $reflectedCtor;
}
public function getCtorParams($class)
{
$cacheKey = self::CACHE_KEY_CTOR_PARAMS . strtolower($class);
$reflectedCtorParams = $this->cache->fetch($cacheKey);
if (false !== $reflectedCtorParams) {
return $reflectedCtorParams;
} elseif ($reflectedCtor = $this->getCtor($class)) {
$reflectedCtorParams = $reflectedCtor->getParameters();
} else {
$reflectedCtorParams = null;
}
/var
/www
/probeip
/vendor
/rdlowrey
/auryn
/lib
/Injector.php
$obj = call_user_func_array(array($executable, '__invoke'), $args);
} else {
$obj = $this->provisionInstance($className, $normalizedClass, $args);
}
$obj = $this->prepareInstance($obj, $normalizedClass);
if (array_key_exists($normalizedClass, $this->shares)) {
$this->shares[$normalizedClass] = $obj;
}
unset($this->inProgressMakes[$normalizedClass]);
return $obj;
}
private function provisionInstance($className, $normalizedClass, array $definition)
{
try {
$ctor = $this->reflector->getCtor($className);
if (!$ctor) {
$obj = $this->instantiateWithoutCtorParams($className);
} elseif (!$ctor->isPublic()) {
throw new InjectionException(
$this->inProgressMakes,
sprintf(self::M_NON_PUBLIC_CONSTRUCTOR, $className),
self::E_NON_PUBLIC_CONSTRUCTOR
);
} elseif ($ctorParams = $this->reflector->getCtorParams($className)) {
$reflClass = $this->reflector->getClass($className);
$definition = isset($this->classDefinitions[$normalizedClass])
? array_replace($this->classDefinitions[$normalizedClass], $definition)
: $definition;
$args = $this->provisionFuncArgs($ctor, $definition, $ctorParams);
$obj = $reflClass->newInstanceArgs($args);
} else {
$obj = $this->instantiateWithoutCtorParams($className);
}
/var
/www
/probeip
/vendor
/rdlowrey
/auryn
/lib
/Injector.php
}
$this->inProgressMakes[$normalizedClass] = count($this->inProgressMakes);
// isset() is used specifically here because classes may be marked as "shared" before an
// instance is stored. In these cases the class is "shared," but it has a null value and
// instantiation is needed.
if (isset($this->shares[$normalizedClass])) {
unset($this->inProgressMakes[$normalizedClass]);
return $this->shares[$normalizedClass];
}
if (isset($this->delegates[$normalizedClass])) {
$executable = $this->buildExecutable($this->delegates[$normalizedClass]);
$reflectionFunction = $executable->getCallableReflection();
$args = $this->provisionFuncArgs($reflectionFunction, $args);
$obj = call_user_func_array(array($executable, '__invoke'), $args);
} else {
$obj = $this->provisionInstance($className, $normalizedClass, $args);
}
$obj = $this->prepareInstance($obj, $normalizedClass);
if (array_key_exists($normalizedClass, $this->shares)) {
$this->shares[$normalizedClass] = $obj;
}
unset($this->inProgressMakes[$normalizedClass]);
return $obj;
}
private function provisionInstance($className, $normalizedClass, array $definition)
{
try {
$ctor = $this->reflector->getCtor($className);
if (!$ctor) {
$obj = $this->instantiateWithoutCtorParams($className);
/var
/www
/probeip
/src
/bootstrap.php
}
$woops->register();
$injector = include('dependencies.php');
$request = $injector->make('Http\HttpRequest');
$response = $injector->make('Http\HttpResponse');
$routeDefinitionCallback = function (\FastRoute\RouteCollector $r) {
$routes = include('routes.php');
foreach ($routes as $route) {
$r->addRoute($route[0], $route[1], $route[2]);
}
};
$dispatcher = \FastRoute\simpleDispatcher($routeDefinitionCallback);
$routeInfo = $dispatcher->dispatch($request->getMethod(), $request->getPath());
switch ($routeInfo[0]) {
case \FastRoute\Dispatcher::NOT_FOUND:
$response->setContent('404 - Page not found');
$response->setStatusCode(404);
$class = $injector->make('ProbeIP\Controllers\NotFound');
$class->show();
break;
case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
$response->setContent('405 - Method not allowed');
$response->setStatusCode(405);
break;
case \FastRoute\Dispatcher::FOUND:
$className = $routeInfo[1][0];
$method = $routeInfo[1][1];
$vars = $routeInfo[2];
// echo "<pre>"; print_r($routeInfo);;
// die;
$class = $injector->make($className);
$class->$method($vars);
break;
}
foreach ($response->getHeaders() as $header) {
header($header, false);
/var
/www
/probeip
/public
/index.php
<?php
require_once __DIR__ . '/../src/bootstrap.php';