Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a whole project into a phar file?

Tags:

php

phar

I have my index.php that uses a class inside a php library (including folders, classes, subclasses) etc..

my index.php uses that whole library

...
include("Classes/Crawler.php");
$crawl = new Crawler(); // 
...
  1. Is there a simple command line to create the phar files that includes all content inside Classes ?
  2. Do I need then to modify content of files so I can use index.php as it was ?

My goal is to distribute 2 files (index.php and Crawler.phar) without having to changing the source code

like image 347
yarek Avatar asked Dec 12 '25 21:12

yarek


1 Answers

I use phing's pharpackage task to build my phar files, see https://github.com/cweiske/phorkie/blob/master/build.xml#L82 for an example.

But apart from that, you can write your own script (it's easy; see the examples in the PHP manual).


About using index.php as it was: You can do that as long as you enable file interception with Phar::interceptFileFuncs().

like image 175
cweiske Avatar answered Dec 14 '25 14:12

cweiske



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!