I am writing a script that talks to a database, and transforms the content and puts it into an XML file.
I am trying to utilize best practices, and as part of library re-use, I have found the following classes to be beneficial:
Symfony components:
- Yaml : for parsing and loading database info.,
- DI Container : for injecting dependencies
Others:
- PHPExcel, the amazing excel library
- Doctrine DBAL to get an easy PDO wrapper
- Mockery for obtaining easy mocks during testing
My core business class, ExcelExporter, will need all these files functioning harmoniously with each other. I also need a place where I can initialize by own class, and inject these dependencies in.
I am confused as to where to do this. If I were building a web page, I’d say I’d put the initialization & configuration process inside index.php and finally call ExcelExporter to do its thing when a user loads index.php in the browser. Is there a better way for this bootstrapping process? What’s the most common approach?
I assume you are not using any framework. Only using symphony components. If you were using a framework it would have been done by the framework. But for vanila framework you need
index.php)bootstrap.phpfile that loads initial classes and external resources. Many framework uses this bootstrap files. Just look at the file structure you’ll find them. The name might not bebootstrap.php.Once your application is loaded use a autoloader to load on-demand classes. This autoloader should be initialized on bootstrap.