PHPackages                             joomla/application - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. joomla/application

ActiveLibrary[Framework](/categories/framework)

joomla/application
==================

Joomla Application Package

4.0.0(9mo ago)23404.8k↓22.7%33[3 PRs](https://github.com/joomla-framework/application/pulls)11GPL-2.0-or-laterPHPPHP ^8.3.0CI passing

Since Jul 24Pushed 8mo ago19 watchersCompare

[ Source](https://github.com/joomla-framework/application)[ Packagist](https://packagist.org/packages/joomla/application)[ Docs](https://github.com/joomla-framework/application)[ Fund](https://community.joomla.org/sponsorship-campaigns.html)[ GitHub Sponsors](https://github.com/sponsors/joomla)[ RSS](/packages/joomla-application/feed)WikiDiscussions 3.x-dev Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (43)Used By (11)Security (1)

The Application Package [![Build Status](https://github.com/joomla-framework/application/actions/workflows/ci.yml/badge.svg?branch=3.x-dev)](https://github.com/joomla-framework/application)
=============================================================================================================================================================================================

[](#the-application-package-)

[![Latest Stable Version](https://camo.githubusercontent.com/9b00667b468420b4c7c4f918d05906b0e7a0048f9ed5c1378dfc6fdb49ec918b/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f6170706c69636174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/joomla/application)[![Total Downloads](https://camo.githubusercontent.com/836518d875f46efaa1bf3c94af98c1f67232b10aaf5cccd567f532124fb7a446/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f6170706c69636174696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/joomla/application)[![Latest Unstable Version](https://camo.githubusercontent.com/d1b2bb8e6c277d3e99169718bd2f94b3873b4698ca33e449458a66c1947ecf90/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f6170706c69636174696f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/joomla/application)[![License](https://camo.githubusercontent.com/1219a339ea6973e96904fac548e2dc36860af7b8912ae132c603efaa0d2c69b7/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6f6d6c612f6170706c69636174696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/joomla/application)

Initialising Applications
-------------------------

[](#initialising-applications)

`AbstractApplication` implements an `initialise` method that is called at the end of the constructor. This method is intended to be overridden in derived classes as needed by the developer.

If you are overriding the `__construct` method in your application class, remember to call the parent constructor last.

```
use Joomla\Application\AbstractApplication;
use Joomla\Input\Input;
use Joomla\Registry\Registry;

class MyApplication extends AbstractApplication
{
	/**
	 * Customer constructor for my application class.
	 *
	 * @param   Input     $input
	 * @param   Registry  $config
	 *
	 * @since   1.0
	 */
	public function __construct(Input $input = null, Registry $config = null, Foo $foo)
	{
		// Do some extra assignment.
		$this->foo = $foo;

		// Call the parent constructor last of all.
		parent::__construct($input, $config);
	}

	/**
	 * Method to run the application routines.
	 *
	 * @return  void
	 *
	 * @since   1.0
	 */
	protected function doExecute()
	{
		try
		{
			// Do stuff.
		}
		catch(\Exception $e)
		{
			// Set status header of exception code and response body of exception message
			$this->setHeader('status', $e->getCode() ?: 500);
			$this->setBody($e->getMessage());
		}
	}

	/**
	 * Custom initialisation for my application.
	 *
	 * @return  void
	 *
	 * @since   1.0
	 */
	protected function initialise()
	{
		// Do stuff.
		// Note that configuration has been loaded.
	}
}
```

Logging within Applications
---------------------------

[](#logging-within-applications)

`AbstractApplication` implements the `Psr\Log\LoggerAwareInterface` so is ready for intergrating with an logging package that supports that standard.

The following example shows how you could set up logging in your application using `initialise` method from `AbstractApplication`.

```
use Joomla\Application\AbstractApplication;
use Monolog\Logger;
use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;

class MyApplication extends AbstractApplication
{
	/**
	 * Custom initialisation for my application.
	 *
	 * Note that configuration has been loaded.
	 *
	 * @return  void
	 *
	 * @since   1.0
	 */
	protected function initialise()
	{
		// Get the file logging path from configuration.
		$logPath = $this->get('logger.path');
		$log = new Logger('MyApp');

		if ($logPath)
		{
			// If the log path is set, configure a file logger.
			$log->pushHandler(new StreamHandler($logPath, Logger::WARNING);
		}
		else
		{
			// If the log path is not set, just use a null logger.
			$log->pushHandler(new NullHandler, Logger::WARNING);
		}

		$this->setLogger($logger);
	}
}
```

The logger variable is private so you must use the `getLogger` method to access it. If a logger has not been initialised, the `getLogger` method will throw an exception.

To check if the logger has been set, use the `hasLogger` method. This will return `true` if the logger has been set.

Consider the following example:

```
use Joomla\Application\AbstractApplication;

class MyApplication extends AbstractApplication
{
	protected function doExecute()
	{
		// In this case, we always want the logger set.
		$this->getLogger()->logInfo('Performed this {task}', array('task' => $task));

		// Or, in this case logging is optional, so we check if the logger is set first.
		if ($this->get('debug') && $this->hasLogger())
		{
			$this->getLogger()->logDebug('Performed {task}', array('task' => $task));
		}
	}
}
```

Mocking the Application Package
-------------------------------

[](#mocking-the-application-package)

For more complicated mocking where you need to similate real behaviour, you can use the `Application\Tests\Mocker` class to create robust mock objects.

There are three mocking methods available:

1. `createMockBase` will create a mock for `AbstractApplication`.
2. `createMockCli` will create a mock for `AbstractCliApplication`.
3. `createMockWeb` will create a mock for `AbstractWebApplication`.

```
use Joomla\Application\Tests\Mocker as AppMocker;

class MyTest extends \PHPUnit_Framework_TestCase
{
	private $instance;

	protected function setUp()
	{
		parent::setUp();

		// Create the mock input object.
		$appMocker = new AppMocker($this);
		$mockApp = $appMocker->createMockWeb();

		// Create the test instance injecting the mock dependency.
		$this->instance = new MyClass($mockApp);
	}
}
```

The `createMockWeb` method will return a mock with the following methods mocked to roughly simulate real behaviour albeit with reduced functionality:

- `appendBody($content)`
- `get($name [, $default])`
- `getBody([$asArray])`
- `getHeaders()`
- `prependBody($content)`
- `set($name, $value)`
- `setBody($content)`
- `setHeader($name, $value [, $replace])`

You can provide customised implementations these methods by creating the following methods in your test class respectively:

- `mockWebAppendBody`
- `mockWebGet`
- `mockWebGetBody`
- `mockWebGetHeaders`
- `mockWebSet`
- `mockWebSetBody`
- `mockWebSetHeader`

Web Application
---------------

[](#web-application)

### Configuration options

[](#configuration-options)

The `AbstractWebApplication` sets following application configuration:

- Execution datetime and timestamp

    - `execution.datetime` - Execution datetime
    - `execution.timestamp` - Execution timestamp
- URIs

    - `uri.request` - The request URI
    - `uri.base.full` - full URI
    - `uri.base.host` - URI host
    - `uri.base.path` - URI path
    - `uri.route` - Extended (non-base) part of the request URI
    - `uri.media.full` - full media URI
    - `uri.media.path` - relative media URI

and uses following ones during object construction:

- `gzip` to compress the output
- `site_uri` to see if an explicit base URI has been set (helpful when chaining request uri using mod\_rewrite)
- `media_uri` to get an explicitly set media URI (relative values are appended to `uri.base` ). If it's not set explicitly, it defaults to a `media/` path of `uri.base`.

#### The `setHeader` method

[](#the-setheader-method)

**Accepted parameters**

- `$name` - The name of the header to set.
- `$value` - The value of the header to set.
- `$replace` - True to replace any headers with the same name.

Example: Using `WebApplication::setHeader` to set a status header.

```
$app->setHeader('status', '401 Auhtorization required', true);
```

Will result in response containing header

```
Status Code: 401 Authorization required

```

Command Line Applications
-------------------------

[](#command-line-applications)

The Joomla Framework provides an application class for making command line applications.

An example command line application skeleton:

```
use Joomla\Application\AbstractCliApplication;

// Bootstrap the autoloader (adjust path as appropriate to your situation).
require_once __DIR__ . '/../vendor/autoload.php';

class MyCli extends AbstractCliApplication
{
	protected function doExecute()
	{
		// Output string
		$this->out('It works');

		// Get user input
		$this->out('What is your name? ', false);

		$userInput = $this->in();
		$this->out('Hello ' . $userInput);
	}
}

$app = new MyCli;
$app->execute();
```

### Colors for CLI Applications

[](#colors-for-cli-applications)

It is possible to use colors on an ANSI enabled terminal.

```
use Joomla\Application\AbstractCliApplication;

class MyCli extends AbstractCliApplication
{
	protected function doExecute()
	{
		// Green text
		$this->out('foo');

		// Yellow text
		$this->out('foo');

		// Black text on a cyan background
		$this->out('foo');

		// White text on a red background
		$this->out('foo');
	}
}
```

You can also create your own styles.

```
use Joomla\Application\AbstractCliApplication;
use Joomla\Application\Cli\Colorstyle;

class MyCli extends AbstractCliApplication
{
	/**
	 * Override to initialise the colour styles.
	 *
	 * @return  void
	 *
	 * @since   1.0
	 */
	protected function initialise()
	{
		$style = new Colorstyle('yellow', 'red', array('bold', 'blink'));
		$this->getOutput()->addStyle('fire', $style);
	}

	protected function doExecute()
	{
		$this->out('foo');
	}
}
```

Available foreground and background colors are: black, red, green, yellow, blue, magenta, cyan and white.

And available options are: bold, underscore, blink and reverse.

You can also set these colors and options inside the tagname:

```
use Joomla\Application\AbstractCliApplication;

class MyCli extends AbstractCliApplication
{
	protected function doExecute()
	{
		// Green text
		$this->out('foo');

		// Black text on a cyan background
		$this->out('foo');

		// Bold text on a yellow background
		$this->out('foo');
	}
}
```

Installation via Composer
-------------------------

[](#installation-via-composer)

Add `"joomla/application": "~3.0"` to the require block in your composer.json and then run `composer install`.

```
{
	"require": {
		"joomla/application": "~3.0"
	}
}
```

Alternatively, you can simply run the following from the command line:

```
composer require joomla/application "~3.0"
```

If you want to include the test sources, use

```
composer require --prefer-source joomla/application "~3.0"
```

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance57

Moderate activity, may be stable

Popularity49

Moderate usage in the ecosystem

Community38

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 58.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~121 days

Recently: every ~138 days

Total

37

Last Release

299d ago

Major Versions

1.9.2 → 2.0.0-beta2020-06-05

1.9.3 → 2.0.22022-08-21

2.0.4 → 3.0.02023-10-05

3.0.4 → 4.0.02025-07-24

PHP version history (8 changes)1.0-alphaPHP &gt;=5.3.10

1.5.1PHP &gt;=5.3.10|&gt;=7.0

1.7.0PHP ^5.3.10|~7.0

2.0.0-betaPHP ^7.2.5

1.9.3PHP ^5.3.10|^7.0|^8.0

2.0.2PHP ^7.2.5|~8.0.0|~8.1.0

3.0.0PHP ^8.1.0

4.0.0PHP ^8.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/305a2164440014dcef9ac681c139fe5e8a1ce1d7a8c3b3cfb828497729a4c70e?d=identicon)[wilsonge](/maintainers/wilsonge)

---

Top Contributors

[![mbabker](https://avatars.githubusercontent.com/u/368545?v=4)](https://github.com/mbabker "mbabker (267 commits)")[![wilsonge](https://avatars.githubusercontent.com/u/1986000?v=4)](https://github.com/wilsonge "wilsonge (51 commits)")[![Hackwar](https://avatars.githubusercontent.com/u/313866?v=4)](https://github.com/Hackwar "Hackwar (23 commits)")[![dongilbert](https://avatars.githubusercontent.com/u/718028?v=4)](https://github.com/dongilbert "dongilbert (21 commits)")[![nibra](https://avatars.githubusercontent.com/u/827605?v=4)](https://github.com/nibra "nibra (15 commits)")[![photodude](https://avatars.githubusercontent.com/u/10253980?v=4)](https://github.com/photodude "photodude (13 commits)")[![ianmacl](https://avatars.githubusercontent.com/u/176534?v=4)](https://github.com/ianmacl "ianmacl (9 commits)")[![eddieajau](https://avatars.githubusercontent.com/u/700871?v=4)](https://github.com/eddieajau "eddieajau (8 commits)")[![piotr-cz](https://avatars.githubusercontent.com/u/612953?v=4)](https://github.com/piotr-cz "piotr-cz (6 commits)")[![heelc29](https://avatars.githubusercontent.com/u/66922325?v=4)](https://github.com/heelc29 "heelc29 (5 commits)")[![frostmakk](https://avatars.githubusercontent.com/u/25645600?v=4)](https://github.com/frostmakk "frostmakk (4 commits)")[![joomla-jenkins](https://avatars.githubusercontent.com/u/929228?v=4)](https://github.com/joomla-jenkins "joomla-jenkins (4 commits)")[![realityking](https://avatars.githubusercontent.com/u/628508?v=4)](https://github.com/realityking "realityking (3 commits)")[![810](https://avatars.githubusercontent.com/u/876623?v=4)](https://github.com/810 "810 (2 commits)")[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (2 commits)")[![brianteeman](https://avatars.githubusercontent.com/u/1296369?v=4)](https://github.com/brianteeman "brianteeman (2 commits)")[![conseilgouz](https://avatars.githubusercontent.com/u/19435246?v=4)](https://github.com/conseilgouz "conseilgouz (2 commits)")[![demis-palma](https://avatars.githubusercontent.com/u/1609992?v=4)](https://github.com/demis-palma "demis-palma (2 commits)")[![elkuku](https://avatars.githubusercontent.com/u/33978?v=4)](https://github.com/elkuku "elkuku (2 commits)")[![frankmayer](https://avatars.githubusercontent.com/u/825497?v=4)](https://github.com/frankmayer "frankmayer (2 commits)")

---

Tags

applicationjoomlajoomla-frameworkphpframeworkapplicationjoomlajoomla-package

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/joomla-application/health.svg)

```
[![Health](https://phpackages.com/badges/joomla-application/health.svg)](https://phpackages.com/packages/joomla-application)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.3k86.3M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[joomla/database

Joomla Database Package

30347.9k9](/packages/joomla-database)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
