PHPackages                             jaxon-php/jaxon-attributes - 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-attributes

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

jaxon-php/jaxon-attributes
==========================

Attributes support for the Jaxon ajax PHP library

v1.1.0(6mo ago)02422BSD-3-ClausePHPPHP &gt;=8.0CI passing

Since Oct 20Pushed 6mo ago1 watchersCompare

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

READMEChangelog (5)Dependencies (4)Versions (6)Used By (2)

[![Build Status](https://github.com/jaxon-php/jaxon-attributes/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/jaxon-php/jaxon-attributes/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/996c9ba29f7928b35c8219430c3e8805afad786561b35c2328820eba1f57d206/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61786f6e2d7068702f6a61786f6e2d617474726962757465732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/jaxon-php/jaxon-attributes/?branch=main)[![codecov](https://camo.githubusercontent.com/685c9baa965dd7aedf5ec92002f689d10bfd1ecc572c32ef78cc8609e93d8d30/68747470733a2f2f636f6465636f762e696f2f67682f6a61786f6e2d7068702f6a61786f6e2d617474726962757465732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d71626b324c5870373856)](https://codecov.io/gh/jaxon-php/jaxon-attributes)

[![Latest Stable Version](https://camo.githubusercontent.com/b619d283f10d4c61903b491212b51d71a3984e88f44de69a420fcb27872ae9bb/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d617474726962757465732f762f737461626c65)](https://packagist.org/packages/jaxon-php/jaxon-attributes)[![Total Downloads](https://camo.githubusercontent.com/14c6c2dba268fb972f67226f58ee69c58f2d7fc1a15a4a86063fa7861859bce6/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d617474726962757465732f646f776e6c6f616473)](https://packagist.org/packages/jaxon-php/jaxon-attributes)[![License](https://camo.githubusercontent.com/a618f6749a1af34fd134bb3e1a1f7896cb367230ba3cd0a8436becf5a81150d4/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d617474726962757465732f6c6963656e7365)](https://packagist.org/packages/jaxon-php/jaxon-attributes)

Attributes for the Jaxon library
================================

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

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

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

[](#installation)

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

```
composer require jaxon-php/jaxon-attributes
```

Set the attribute config option.

```
jaxon()->setOption('core.metadata.format', 'attributes');
```

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

When deploying the application in production, the metadata can be cached, to avoid performance issues.

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

Usage
-----

[](#usage)

The following attributes are provided.

### \#\[Jaxon\\Attributes\\Attribute\\Exclude\]

[](#jaxonattributesattributeexclude)

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

```
use Jaxon\Attributes\Attribute\Exclude;

/**
 * #[Exclude(true)]
 */
class JaxonExample
{
// This class will not be exported to javascript.
}
```

```
use Jaxon\Attributes\Attribute\Exclude;

class JaxonExample
{
    /**
     * #[Exclude]
     */
    public function doNot()
    {
        // This method will not be exported to javascript.
    }
}
```

### \#\[Jaxon\\Attributes\\Attribute\\Upload\]

[](#jaxonattributesattributeupload)

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.

```
use Jaxon\Attributes\Attribute\Upload;

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

### \#\[Jaxon\\Attributes\\Attribute\\Before\]

[](#jaxonattributesattributebefore)

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.

```
use Jaxon\Attributes\Attribute\Before;

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()
    {
    }
}
```

### \#\[Jaxon\\Attributes\\Attribute\\After\]

[](#jaxonattributesattributeafter)

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.

```
use Jaxon\Attributes\Attribute\After;

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()
    {
    }
}
```

### \#\[Jaxon\\Attributes\\Attribute\\Callback\]

[](#jaxonattributesattributecallback)

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

It was added in version 2.2.0.

```
use Jaxon\Attributes\Attribute\Callback;

/**
 * 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()
    {
    }
}
```

### \#\[Jaxon\\Attributes\\Attribute\\Databag\]

[](#jaxonattributesattributedatabag)

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.

```
use Jaxon\Attributes\Attribute\Databag;

class JaxonExample extends \Jaxon\App\Component
{
    /**
     * #[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++);
    }
}
```

### \#\[Jaxon\\Attributes\\Attribute\\Inject\]

[](#jaxonattributesattributeinject)

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.

```
use Jaxon\Attributes\Attribute\Inject;

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

    /**
     * #[Inject(attr: 'translator', class: \App\Services\Translator::class)]
     */
    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` attribute.

```
use Jaxon\Attributes\Attribute\Inject;

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

    /**
     * #[Inject(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` attribute.

```
use Jaxon\Attributes\Attribute\Inject;

class JaxonExample extends \Jaxon\App\Component
{
    /**
     * #[Inject(class: \App\Services\Translator::class)]
     * @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);
    }
}
```

```
use Jaxon\Attributes\Attribute\Inject;

class JaxonExample extends \Jaxon\App\Component
{
    /**
     * #[Inject]
     * @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);
    }
}
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance67

Regular maintenance activity

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 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 ~2 days

Total

5

Last Release

200d ago

### 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 (39 commits)")

---

Tags

phpattributesajaxJaxon

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[psalm/attributes

A collection of PHP 8 Attributes that Psalm can understand

19120.0k2](/packages/psalm-attributes)[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)
