Documentation
External libraries
Table of Contents ▼
Presentation
When you're developing a website or an API, it's common to use function libraries to perform certain processes (to avoid having to develop everything yourself).
Temma is very flexible and adapts to the way you want to load these libraries. Generally speaking, libraries can be loaded either by copying them into the lib/ directory, or by using the Composer dependency manager.
Copying the library
If the library is a set of .php files or a .phar file, you can copy the file(s) into the project's lib/ directory.
.php files
If you place .php files in the lib/ directory, and they contain PSR-4 compliant objects, they will be handled automatically by Temma's autoloader.
For example, the \Skywalker\Luke object must be stored in the lib/Skywalker/Luke.php file, and can be instantiated directly:
$luke = new \Skywalker\Luke();
If, on the other hand, the files don't comply with the PSR-4 standard, you'll need to include them explicitly before you can use the objects and functions they contain.
For example, if the lib/skywalker/family.php file contains the \Skywalker\Luke object, you'll need to include it before instantiating the:
<?php
require_once('skywalker/family.php');
// some code
$luke = new \Skywalker\Luke();
.phar file
If you place a .phar file directly in the lib/ directory, all your objects that use the contents of this file will have to include it:
<?php
require_once("a_library.phar");
If you have placed the .phar file in a subdirectory, you must include the entire path below lib/:
<?php
require_once("path/to/a_library.phar");
Using Composer
Composer is the dependency manager commonly used in PHP projects. It makes it easy to load libraries declared on the Packagist service.
Assuming you already have Composer installed, you can create a composer.json file at the root of your project, and list the libraries that need to be installed there:
{
"require": {
"lib1": ">=1.0.0",
"lib2": "2.*"
}
}
Then, to have Composer download the listed libraries (and any dependencies), run the command: composer update
If you've installed Composer as a .phar file, you'll need to run php composer.phar update
Composer will place the downloaded files in the vendors/ directory.
If you've installed libraries with Composer, Temma will automatically load the Composer autoloader, making library objects directly instantiable.
Previous: | Configuration |
Next: | Routing |
Table of Contents
- Migration : How to upgrade from Temma 1.x to version 2
- Installation : Download Temma and install it to start your web project
- Configuration : All the configuration directives of the etc/temma.json file and the optional environment variables
- External libraries : How to use external function libraries
- Routing : Temma's default routing system, and advanced routing
- Log : Use of the log system, management by criticality levels
- Controllers : Essential parts of your web application
- Views : Smarty templates or JSON/CSV/RSS/iCal/INI exports
- Dependency injection : The backbone of your application developments
- Sessions : Extension of user sessions managed by PHP
- Data sources : Unified data access management
- Model : How to use DAOs to access databases
- Execution flow : How to manage the execution flow, between plugins and the controller
- Plugins : How to use plugins, and create your own plugins to modularize your code
- Attributes : How to filter access to controllers and actions
- Tests : To write automated integration tests.
- Command-line interface : To create executable scripts on the command line, automatically initialized by Temma
- Helpers : Items offered by Temma to help you in various circumstances