Download the PHP package brad-jones/import without Composer
On this page you can find all versions of the php package brad-jones/import. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download brad-jones/import
More information about brad-jones/import
Files in brad-jones/import
Package import
Short Description Includes a PHP file in such a way as to isolate it from where it was included.
License MIT
Homepage https://github.com/brad-jones/import
Informations about the package import
Brads PHP File Importer
Includes a PHP file in such a way as to isolate it from where it was included. This package provides a new pseudo language construct, you will be familiar with how and work, well we have now added .
Credit: https://gist.github.com/Eraknelo/6795b983825fc6a720ef
Installation:
Getting access to the import function:
There are various ways you can access the import function.
-
If using PHP 5.6 or greater, you can import the import function.
-
Or you can call the static method on the Importer class.
-
Or you can create an instance of the Importer.
- Or if you would rather install the import function globally.
Dependency Injection:
The importer is Di & Test friendly, it implements the ImporterInterface.
A simple contrived php-di example:
Example Usage:
Firstly for these examples assume the contents of is:
Secondly assume we are just using the globalised import function. Regardless of how you access it the result is the same.
Exported Value:
The import function will return any value that is returned by the imported file. Just the same as or . When combined with closures and a di container, you can end up with something akin to the node.js CommonJs module system.
Isolated Import:
The whole point of this project is to ensure the imported file does not have access to any variables from the parent file. So with a normal or you would have something like this:
With our import function this is what happens:
Providing a Custom Scope:
Sometimes we might want the imported file to have access to some specific data.
Include or Require:
Under the hood import does use the normal or .
By default we use but you can changes this easily.