---
Joomla Framework
- What is Joomla Framework
- Libraries
- Using libraries inside Joomla
- Using libraries outside Joomla
---
What is Joomla Framework
----
### Why this talk?
- Most people think Joomla = CMS only
- Under the hood:
framework of modular PHP packages
- Used inside Joomla
- Usable outside Joomla
(CLI tools, microservices, standalone apps)
----
### What is the Joomla Framework?
- A set of decoupled PHP packages
- Each package does one job well
- Installable via Composer (from Packagist)
- Usable without the Joomla CMS
----
### Examples of packages
- Database connection/queries
- HTTP client / request & response
- Filesystem abstractions
- Event system
- Registry (config management)
See: framework.joomla.org
and Packagist for the full list.
---
Libraries
Reusing PHP code....
----
### PHP Libraries
- Save time - don’t reinvent the wheel
- Quality & security - tested by the community
- Consistency - follow standards (PSR, coding style)
- Maintainability - easier upgrades and bug fixes)
- Ecosystem - uncountable open-source solutions
----
### Confession (don't tell anyone!)
- for 4 years without updating
----
### Better: Composer
- Dependency manager for PHP projects
- Handles downloading, installing, and updating
- Uses composer.json to define project requirements
- Stores packages in folder: /vendor/
- Automates library installation & autoloading
- Keeps versions in sync with composer.lock
- Huge ecosystem via Packagist.org
----
### Packagist
Search Joomla packages:
```bash
open https://packagist.org/?query=joomla
```
Install a package:
```bash
composer require joomla/http
```
Autoloading:
```php
Using libraries inside Joomla
----
### Using libraries inside Joomla
Joomla from joomla-cms github repo?
Need to do
Steps to Set up the Local Environment
----
### Using libraries inside Joomla
Joomla from downloads.joomla.org?
All libraries have been added
Joomla ships libraries under /libraries/vendor/
Do NOT update those yourself!
----
### Using composer libraries
inside your extension
Avoid conflicts of own extension with core and other extensions!
Put vendor inside your extension
/components/com_mycomponent/vendor/
---
Using libraries outside Joomla
----
### Example 1: Hello Joomla world
Install a single package:
```bash
composer require joomla/registry
```
Use that package:
```php
set('welcome', 'Hello Joomla world!');
echo $registry->get('welcome'); // Hello Joomla world!
```
----
### Example 2: List articles from DB
- Standalone PHP app (no CMS) to query #__content
- Features
- Headless; no Joomla CMS runtime
- Uses Joomla Framework via Composer
- Responsive output with Bootstrap 5
- Requirements
- PHP 8.1+ and Composer
- Access to a Joomla 4.x/5.x database
- Web server or php -S
----
### Example 2: quick start
Clone & install:
```bash
git clone https://github.com/pe7er/db8-joomla-framework-example
cd db8-joomla-framework-example
composer install
cp .env.example .env # add DB credentials
php -S localhost:8000
```
Visit:
```
http://localhost:8000
```
---
Demo:
Simple Framework Example
----
#### Demo: simple framework example 1/4
1. get necessary libraries
```bash
composer require joomla/database
```
2. add autoload:
```php
require_once __DIR__ . '/vendor/autoload.php';
```
3. add namespace
```php
use Joomla\Database\DatabaseFactory;
```
----
#### Demo: simple framework example 2/4
4. add database credentials
```php
$config = [
'driver' => 'mysqli',
'host' => '10.10.10.10',
'user' => 'dbuser',
'password' => '123',
'database' => 'dbname',
'port' => '3306',
'socket' => '',
'prefix' => 'jd25_'
];
```
(actually, not recommended to add in code!)
----
#### Demo: simple framework example 3/4
5. Instantiate new DatabaseFactory object
```php
$db = (new DatabaseFactory())->getDriver(
$config['driver'],
$config
);
```
----
#### Demo: simple framework example 4/4
6. get and display data
```php
echo "Simple Framework Example
";
$query = $db->getQuery(true)
->select('*')
->from($db->quoteName('#__content'));
$db->setQuery($query);
$rows = $db->loadObjectList();
print_r($rows);
```
----
## References
- **Framework portal**: https://framework.joomla.org/
- **GitHub org**: https://github.com/joomla-framework
- **Packagist (search)**: https://packagist.org/?query=joomla
- **Article (source)**: https://magazine.joomla.org/all-issues/april-2025/what-is-joomla-framework-and-how-can-you-use-it
----
## Contribute
- Help improve **docs**
- Maintain / enhance packages
- Share examples and tutorials
---
Questions?
----
## Photo Credits