PHPackages                             jaxon-php/jaxon-annotations - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. jaxon-php/jaxon-annotations

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jaxon-php/jaxon-annotations
===========================

Annotations support for the Jaxon ajax PHP library

v3.1.0(6mo ago)01.7kBSD-3-ClausePHPPHP &gt;=8.0CI passing

Since Apr 15Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/jaxon-php/jaxon-annotations)[ Packagist](https://packagist.org/packages/jaxon-php/jaxon-annotations)[ Docs](https://www.jaxon-php.org)[ RSS](/packages/jaxon-php-jaxon-annotations/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (21)Used By (0)

[![Build Status](https://github.com/jaxon-php/jaxon-annotations/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/jaxon-php/jaxon-annotations/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/963bd98f010768a0c069fea62e5ed3e247471f4120aa2f4687f5b18fd55b8bf9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61786f6e2d7068702f6a61786f6e2d616e6e6f746174696f6e732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/jaxon-php/jaxon-annotations/?branch=main)[![codecov](https://camo.githubusercontent.com/00eedbe8723a3bd81c4a79d60765b55736c52b11b5b0bb2054398feac1ab3ec1/68747470733a2f2f636f6465636f762e696f2f67682f6a61786f6e2d7068702f6a61786f6e2d616e6e6f746174696f6e732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d4845524b433630434331)](https://codecov.io/gh/jaxon-php/jaxon-annotations)

[![Latest Stable Version](https://camo.githubusercontent.com/241df2d1467dee211ebb1cd184618cd54bdb4694c4d80d3020f4975556271e25/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d616e6e6f746174696f6e732f762f737461626c65)](https://packagist.org/packages/jaxon-php/jaxon-annotations)[![Total Downloads](https://camo.githubusercontent.com/79bed1f6ea97384eebcbcc67e0c0f4ae05f8138701b16f51c006ed5bfb18d6e1/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d616e6e6f746174696f6e732f646f776e6c6f616473)](https://packagist.org/packages/jaxon-php/jaxon-annotations)[![License](https://camo.githubusercontent.com/df8995f47ed2c8ba2068350c429af1b8a225754b4e97cdf1bda353efa314af2e/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d616e6e6f746174696f6e732f6c6963656e7365)](https://packagist.org/packages/jaxon-php/jaxon-annotations)

Annotations for the Jaxon library
=================================

[](#annotations-for-the-jaxon-library)

This package provides annotation support for the Jaxon library. The configuration options that are related to Jaxon classes can be set directly in the class files using annotations.

Two different syntax are allowed for annotations: the default array-like syntax, and an alternative docblock-like syntax, available since version `1.4`.

Installation
------------

[](#installation)

Install this package with `composer`. It requires `jaxon-php/jaxon-core` v4 or higher.

```
composer require jaxon-php/jaxon-annotations
```

Set the annotation config option.

```
// In version 3.0.*.
jaxon()->setOption('core.metadata', 'annotations');
```

```
// Starting from version 3.1.
jaxon()->setOption('core.metadata.format', 'annotations');
```

> Note: The option must be set for a package if it defines classes with annotations.

Starting from version 3.1, when deploying the application in production, the metadata can be cached, to avoid performance issues.

```
jaxon()->setOptions([
    'format' => 'annotations',
    'cache' => [
        'enabled' => true,
        'dir' => '/path/to/the/cache/dir',
    ],
], 'core.metadata');
```

Usage
-----

[](#usage)

The following annotations are provided.

### @exclude

[](#exclude)

It prevents a method or a class from being exported to javascript. It takes an optional boolean parameter.

```
/**
 * @exclude(true)
 */
class JaxonExample
{
// This class will not be exported to javascript.
}
```

```
class JaxonExample
{
    /**
     * @exclude
     */
    public function doNot()
    {
        // This method will not be exported to javascript.
    }
}
```

The PHP-DOC syntax can also be used.

```
class JaxonExample
{
    /**
     * @exclude false
     */
    public function do()
    {
        // This method will be exported to javascript.
    }

    /**
     * @exclude true
     */
    public function doNot()
    {
        // This method will not be exported to javascript.
    }
}
```

### @upload

[](#upload)

It adds file upload to an ajax request. It takes the id of the HTML field as a mandatory option. It applies only to methods.

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @upload('field' => 'div-user-file')
     */
    public function saveFile()
    {
        // Get the uploaded files.
        $files = $this->upload()->files();
    }
}
```

The PHP-DOC syntax can also be used.

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @upload div-user-file
     */
    public function saveFile()
    {
        // Get the uploaded files.
        $files = $this->upload()->files();
    }
}
```

### @before

[](#before)

It defines a method of the class as a callback to be called before processing the request. It takes the name of the method as a mandatory parameter, and an array as optional parameters to be passed to the callback. It applies to methods and classes.

```
class JaxonExample
{
    protected function funcBefore1()
    {
        // Do something
    }

    protected function funcBefore2($param1, $param2)
    {
        // Do something with parameters
    }

    /**
     * @before('call' => 'funcBefore1')
     * @before('call' => 'funcBefore2', 'with' => ['value1', 'value2'])
     */
    public function action()
    {
    }
}
```

The PHP-DOC syntax can also be used.

```
class JaxonExample
{
    protected function funcBefore1()
    {
        // Do something
    }

    protected function funcBefore2($param1, $param2)
    {
        // Do something with parameters
    }

    /**
     * @before funcBefore1
     * @before funcBefore2 ["value1", "value2"]
     */
    public function action()
    {
    }
}
```

### @after

[](#after)

It defines a method of the class as a callback to be called after processing the request. It takes the name of the method as a mandatory parameter, and an array as optional parameters to be passed to the callback. It applies to methods and classes.

```
class JaxonExample
{
    protected function funcAfter1()
    {
        // Do something
    }

    protected function funcAfter2($param)
    {
        // Do something with parameter
    }

    /**
     * @after('call' => 'funcAfter1')
     * @after('call' => 'funcAfter2', 'with' => ['value'])
     */
    public function action()
    {
    }
}
```

The PHP-DOC syntax can also be used.

```
class JaxonExample
{
    protected function funcAfter1()
    {
        // Do something
    }

    protected function funcAfter2($param)
    {
        // Do something with parameter
    }

    /**
     * @after funcAfter1
     * @after funcAfter2 ["value"]
     */
    public function action()
    {
    }
}
```

### @callback

[](#callback)

It defines a javascript object to be used as callback when processing the ajax request.

It was added in version 2.2.0.

```
/**
 * Default callback for all the requests to the class.
 *
 * @callback('name' => 'jaxon.ajax.callback.example')
 */
class JaxonExample
{
    /**
     * Specific callback for this method. It is added to the default class callback.
     *
     * @callback('name' => 'jaxon.ajax.callback.action')
     */
    public function action()
    {
    }
}
```

The PHP-DOC syntax can also be used.

```
/**
 * Default callback for all the requests to the class.
 *
 * @callback jaxon.ajax.callback.example
 */
class JaxonExample
{
    /**
     * Specific callback for this method. It replaces the default class callback.
     *
     * @callback jaxon.ajax.callback.action
     */
    public function action()
    {
    }
}
```

### @databag

[](#databag)

It defines a data bag to be appended to ajax requests to a method. It takes the name of the data bag as a mandatory parameter. It applies to methods and classes.

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @databag('name' => 'user')
     */
    public function action()
    {
        // Update a value in the data bag.
        $count = $this->bag('user')->get('count', 0);
        $this->bag('user')->set('count', $count++);
    }
}
```

The PHP-DOC syntax can also be used.

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @databag user
     */
    public function action()
    {
        // Update a value in the data bag.
        $count = $this->bag('user')->get('count', 0);
        $this->bag('user')->set('count', $count++);
    }
}
```

### @di

[](#di)

It defines an attribute that will be injected in a class.

When applied on methods and classes, it takes the name and the class of the attribute as parameters.

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @var \App\Services\Translator
     */
     protected $translator;

    /**
     * @di('attr' => 'translator', class => '\App\Services\Translator')
     */
    public function translate(string $phrase)
    {
        // The $translator property is set from the DI container when this method is called.
        $phrase = $this->translator->translate($phrase);
    }
}
```

The class parameter is optional, and can be omitted if it is already specified by a `@var` annotation.

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @var \App\Services\Translator
     */
     protected $translator;

    /**
     * @di('attr' => 'translator')
     */
    public function translate(string $phrase)
    {
        // The $translator property is set from the DI container when this method is called.
        $phrase = $this->translator->translate($phrase);
    }
}
```

When applied on attributes, it takes the class of the attribute as only parameter, which can be omitted if it is already specified by a `@var` annotation.

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @di(class => '\App\Services\Translator')
     * @var \App\Services\Translator
     */
     protected $translator;

    public function translate(string $phrase)
    {
        // The $translator property is set from the DI container when this method is called.
        $phrase = $this->translator->translate($phrase);
    }
}
```

```
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @di
     * @var \App\Services\Translator
     */
     protected $translator;

    public function translate(string $phrase)
    {
        // The $translator property is set from the DI container when this method is called.
        $phrase = $this->translator->translate($phrase);
    }
}
```

If the class name does not start with a `"\"`, then the corresponding fully qualified name (FQN) will be set using either the `use` instructions or the `namespace` in its source file.

```
namespace App\Ajax;

use App\Services\Translator;

class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @var Translator
     */
     protected $translator;

    /**
     * @var Formatter
     */
     protected $formatter;

    /**
     * @di('attr' => 'translator', class => 'Translator')
     * @di('attr' => 'formatter', class => 'Formatter')
     */
    public function translate(string $phrase)
    {
        // The Translator FQN is defined by the use instruction => App\Services\Translator.
        // The Formatter FQN is defined by the current namespace => App\Ajax\Formatter.
        $phrase = $this->formatter->format($this->translator->translate($phrase));
    }
}
```

The PHP-DOC syntax can also be used.

```
namespace App\Ajax;

use App\Services\Translator;

class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @var Translator
     */
     protected $translator;

    /**
     * @var Formatter
     */
     protected $formatter;

    /**
     * @di $translator   Translator
     * @di $formatter    Formatter
     */
    public function translate(string $phrase)
    {
        // The Translator FQN is defined by the use instruction => App\Services\Translator.
        // The Formatter FQN is defined by the current namespace => App\Ajax\Formatter.
        $phrase = $this->formatter->format($this->translator->translate($phrase));
    }
}
```

```
namespace App\Ajax;

use App\Services\Translator;

/**
 * @di $translator   Translator
 * @di $formatter    Formatter
 */
class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @var Translator
     */
     protected $translator;

    /**
     * @var Formatter
     */
     protected $formatter;

    public function translate(string $phrase)
    {
        // The Translator FQN is defined by the use instruction => App\Services\Translator.
        // The Formatter FQN is defined by the current namespace => App\Ajax\Formatter.
        $phrase = $this->formatter->format($this->translator->translate($phrase));
    }
}
```

```
namespace App\Ajax;

use App\Services\Translator;

class JaxonExample extends \Jaxon\App\CallableClass
{
    /**
     * @di  Translator
     * @var Translator
     */
     protected $translator;

    /**
     * @di  Formatter
     * @var Formatter
     */
     protected $formatter;

    public function translate(string $phrase)
    {
        // The Translator FQN is defined by the use instruction => App\Services\Translator.
        // The Formatter FQN is defined by the current namespace => App\Ajax\Formatter.
        $phrase = $this->formatter->format($this->translator->translate($phrase));
    }
}
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance67

Regular maintenance activity

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~71 days

Recently: every ~89 days

Total

19

Last Release

201d ago

Major Versions

v1.4.0 → v2.0.02022-05-10

v2.2.1 → v3.0.02025-06-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebb668d7515d81741c86e42cf3194f5623636fbb15dd5412e26ea8320865d229?d=identicon)[lagdo](/maintainers/lagdo)

---

Top Contributors

[![feuzeu](https://avatars.githubusercontent.com/u/15174329?v=4)](https://github.com/feuzeu "feuzeu (33 commits)")

---

Tags

phpannotationsajaxJaxon

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jaxon-php-jaxon-annotations/health.svg)

```
[![Health](https://phpackages.com/badges/jaxon-php-jaxon-annotations/health.svg)](https://phpackages.com/packages/jaxon-php-jaxon-annotations)
```

###  Alternatives

[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[minime/annotations

The KISS PHP annotations library

229378.6k37](/packages/minime-annotations)[marcin-orlowski/lombok-php

Never write boilerplate code for your data class again!

3118.6k1](/packages/marcin-orlowski-lombok-php)[jaxon-php/jaxon-laravel

Jaxon library integration for the Laravel framework

101.8k4](/packages/jaxon-php-jaxon-laravel)

PHPackages © 2026

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