Skip to content

grithin/php-file-include

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileInclude

For including files in an isolated context, but with injected variables, and potentially extracted variables.

composer require grithin/file-include

Use

use \Grithin\FileInclude;
# inject `bob` into the file context, so file code can access $bob
FileInclude::include('file.php', ['bob'=>$bob]);

# inject the global $bob into the file
global $bob;
FileInclude::require_once('file2.php', null, ['globals'=>['bob']]);

Extraction

Extraction will adjust the return value. Whereas, normally, the return value is the return of the file, when variables are being extracted, the return changes into an array, where the normal return can be found in ['_return'=>$x]

file.php

$bob = 'bob';
return 123;
$result = FileInclude::include_once('file.php', null, ['extract'=>['bob']]);
/*>
[
	'_return'=>123,
	'bob'=>'bob'
]
*/

Notes

This is a rewrite and selection from \Grithin\Files in phpbase

About

Include files in isolated context with options

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages