PHP code example of jaxon-php / jaxon-annotations

1. Go to this page and download the library: Download jaxon-php/jaxon-annotations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jaxon-php / jaxon-annotations example snippets


jaxon()->setOption('core.annotations.enabled', true);

/**
 * @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.
    }
}

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.
    }
}

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

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

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

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

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

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

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

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

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

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

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++);
    }
}

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++);
    }
}

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);
    }
}

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);
    }
}

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);
    }
}

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));
    }
}

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));
    }
}
shell
composer