Download the PHP package jasny/reflection-factory without Composer

On this page you can find all versions of the php package jasny/reflection-factory. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package reflection-factory

Jasny Reflection factory

PHP Scrutinizer Code Quality Code Coverage Packagist Stable Version Packagist License

Factory to use in dependency injection when using PHP Reflection.

Why use a factory instead or just doing new ReflectionClass()?

Dependency injection might seem like making things needlessly complex. However it's a key component in building maintainable (and testable) code.

Using new within your classes creates a strong coupling between classes. This makes it more difficult when writing unit tests because there is no opertunity to mock the reflection. In practice this means that a class using ReflectionClass can only be tested with real, existing classes.

Using ReflectionFactory with dependency injection, allows you to inject a mock of the factory instead. This in term allows you to create mock Reflection objects, for non-existing classes, functions, properties, etc.

Installation

composer require jasny/reflection-factory

Usage

Example use case

Without dependency injection

But writing the test is hard, as it doesn't allow mocking. Instead we need to create a SomeToolTestFooSupport class just to test this feature.

In the unit test we do

Adding one test class isn't so bad. But consider we need to add one per test, it quickly becomes a mess.

With dependency injection

Dependency injection adds a little overhead to the class as we need to pass the reflection factory to SomeTool.

In the unit test, we mock the ReflectionClass and ReflectionFactory. The tests class FakeClass doesn't need to exist.

Methods

Method Reflection class
reflectClass ReflectionClass
reflectClassConstant ReflectionClassConstant
reflectZendExtension ReflectionZendExtension
reflectExtension ReflectionExtension
reflectFunction ReflectionFunction
reflectMethod ReflectionMethod
reflectObject ReflectionObject
reflectParameter ReflectionParameter
reflectProperty ReflectionProperty
reflectGenerator ReflectionGenerator

Some PHP functions have been wrapped, so they can be mocked

Method Function
functionExists function_exists
classExists class_exists
methodExists method_exists
propertyExists property_exists
extensionLoaded extension_loaded
isA is_a
isCallable is_callable

All versions of reflection-factory with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jasny/reflection-factory contains the following files

Loading the files please wait ....