Get the current reflection environment.

@return BetterReflection
556261
private static function getReflectionEnvironment(): BetterReflection
    {
        if (self::$reflectionEnvironment === null) {
            self::$reflectionEnvironment = new BetterReflection();
        }

        return self::$reflectionEnvironment;
    }
1169877
protected static function getReflection($object)
    {
        $reflectionClass = get_class($object);

        if (!isset(self::$reflections[$reflectionClass])) {
            self::$reflections[$reflectionClass]
                = new \ReflectionClass($object);
        }

        return self::$reflections[$reflectionClass];
    }
695899
public function reflection_file()
	{	
		if ( is_null( $this->reflection_file ) )
		{
			if ( is_null( $reflection = $this->reflection() ) )
			{
				return null;
			}
			
			$this->reflection_file = file( $reflection->getFileName() );
		}
		
		return $this->reflection_file;
	}
63451
public static function fromReflection(ReflectionProperty $reflectionProperty)
    {
        $pg = new static($reflectionProperty->getName());
        if ($reflectionProperty->getReflectionDocComment()->isEmpty() !== true) {
            $pg->setDocumentation(DocCommentGenerator::fromReflection($reflectionProperty->getReflectionDocComment()));
        }

        if ($reflectionProperty->isDefault() === true) {
            $defaultValue = $reflectionProperty->getDeclaringClass()->getDefaultProperties();
            $pg->setDefaultValue($defaultValue[$reflectionProperty->getName()]);
        }

        if ($reflectionProperty->isStatic() === true) {
            $pg->setStatic(true);
        }

        if ($reflectionProperty->isPrivate() === true) {
            $pg->setVisibility(Modifiers::VISIBILITY_PRIVATE);
        } elseif ($reflectionProperty->isProtected() === true) {
            $pg->setVisibility(Modifiers::VISIBILITY_PROTECTED);
        } else {
            $pg->setVisibility(Modifiers::VISIBILITY_PUBLIC);
        }

        return $pg;
    }
232736
public function getDeclaringClass()
    {
        if (is_array($this->routineName) === false) {
            return null;
        }
        
        $refClass     = parent::getDeclaringClass();
        $moufRefClass = new MoufReflectionClass($refClass->getName());
        return $moufRefClass;
    }
1257397
private static function instance()
    {
        $currentClass = get_called_class();
        $instanceName = empty( self::$instance ) ? '' : new \ReflectionClass(self::$instance);
        if( empty( self::$instance ) || ( $instanceName->name != $currentClass ) ) {
            self::$instance = new static();
        }
        return self::$instance;
    }
1084496
private function doGetReflector()
    {
        switch ($this->getType()) {
            case static::C_TYPE_FUNCTION:
            case static::C_TYPE_CLOSURE:
                return new \ReflectionFunction($this->handler);
            case static::C_TYPE_STATIC_METHOD:
            case static::C_TYPE_INSTANCE_METHOD:
                return new \ReflectionMethod($this->getClass(), $this->getMethod());
            case static::C_TYPE_INVOKED_OBJECT:
                return new \ReflectionMethod($this->getClass(), '__invoke');
            case static::C_TYPE_ERROR:
                throw new \Exception;
                break;
        }
    }
619361
protected function getReflectionInfos()
    {
        try {
            $this->constructMethod = new \ReflectionMethod($this->className, "__construct");
            $params = $this->constructMethod->getParameters();
            $i = 0;
            foreach ($params as $param) {
                $paramsInfos = ['name' => $param->getName()];
                // Either the class is typehinted
                if (!empty($param->getClass())) {
                    $paramsInfos['class'] = $param->getClass()->getName();
                } elseif (!empty($this->propertyTypes[$param->getName()])) {
                    // Or we take it from the argument name
                    $paramsInfos['class'] = $this->propertyTypes[$param->getName()];
                }
                $this->requiredParams[$i++] = $paramsInfos;
            }
        } catch (\ReflectionException $e) {
            // There is no construct method but we don't really care
        }
    }
463948
public function getReflector()
    {
        if ($this->reflector === null) {
            $this->reflector = new ReflectionClosure($this->closure, $this->code);
            $this->code = null;
        }

        return $this->reflector;
    }
51641
public function getViewPath()
    {
        $ref = new \ReflectionClass($this);
        $controllerId = str_replace('Controller', '', $ref->getShortName());
        $path = dirname(dirname($ref->getFileName()));
        return $path . '/views/' . lcfirst($controllerId);
    }
1258309
public function setReflection(ReflectionClass $reflection) {
		$this->reflection = $reflection;
		$this->class      = $reflection->getName();
		
		$this->reset();
		
		return $this;
	}
1253219
final private function getRefClass()
    {
        if ($this->refClass === null) {
            $this->refClass = new \ReflectionClass($this);
        }

        return $this->refClass;
    }
223536
private static function getReflection(): ReflectionClass
    {
        $class = static::class;

        if (array_key_exists($class, self::$reflections)) {
            return self::$reflections[$class];
        }

        self::$reflections[$class] = $reflection = new ReflectionClass($class);

        $constants = $reflection->getConstants();
        if ([] === $constants) {
            throw new LogicException(sprintf('Class %s must define Constants', static::class));
        }

        foreach ($constants as $value) {
            if (!\is_int($value)) {
                throw new LogicException('All enum constants must be in integer type');
            }
        }

        return $reflection;
    }
362739
public function get_callback_reflection() {
		if ( is_array( $this->callback ) ) {
			return new \ReflectionMethod( $this->callback[0], $this->callback[1] );
		} else {
			return new \ReflectionFunction( $this->callback );
		}
	}
194593
public function getReflectionClass($className)
    {

        // check if we've already initialized the reflection class
        if (isset($this->reflectionClasses[$className]) === false) {
            $this->reflectionClasses[$className] = $this->newReflectionClass($className);
        }

        // return the reflection class instance
        return $this->reflectionClasses[$className];
    }
419317
protected function getReflectionProperty($name)
    {
        do
        {
            $reflClass = (!isset($reflClass)) ? new \ReflectionClass($this->getObject()) : $reflClass;
            $property = $reflClass->getProperty($name);
            if (isset($property))
            {
                break;
            }
        } while (($reflClass = $reflClass->getParentClass()) !== null);

        if ($property instanceof \ReflectionProperty)
        {
            $property->setAccessible(true);
            return $property;
        } else
        {
            throw new \Exception('Property ' . $name . ' doesn\'t exist on object of class ' . get_class($this->getObject()));
        }
    }
8069
public function callMe()
    {
        $output = $this->dispatchStartEvent();

        $refProps = array();
        /** @var \Brainworxx\Krexx\Service\Reflection\ReflectionClass $ref */
        $ref = $this->parameters[static::PARAM_REF];
        // We need to keep the original reference intact.
        $reflectionClass = $ref;

        // The main problem here is, that you only get the private properties of
        // the current class, but not the inherited private properties.
        // We need to get all parent classes and then poll them for private
        // properties to get the whole picture.
        do {
            $refProps = array_merge($refProps, $reflectionClass->getProperties(\ReflectionProperty::IS_PRIVATE));
            // And now for the parent class.
            $reflectionClass = $reflectionClass->getParentClass();
        } while (is_object($reflectionClass));

        if (empty($refProps) === true) {
            return $output;
        }

        usort($refProps, array($this, 'reflectionSorting'));

        return $output .
            $this->getReflectionPropertiesData(
                $refProps,
                $ref,
                'Private properties'
            );
    }