PHP Classes

File: src/Script/Action/Event.php

Recommend this page to a friend!
  Packages of Thierry Feuzeu   Jaxon   src/Script/Action/Event.php   Download  
File: src/Script/Action/Event.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Jaxon
Call PHP classes from JavaScript using AJAX
Author: By
Last change:
Date: 1 year ago
Size: 818 bytes
 

Contents

Class file image Download
<?php

namespace Jaxon\Script\Action;

use Jaxon\Script\JsExpr;
use JsonSerializable;

class Event implements JsonSerializable
{
    /**
     * The constructor.
     *
     * @param string $sMode    The event mode: 'jq' or 'js'
     * @param string $sName    The event name
     * @param JsExpr $xHandler   The event handler
     */
    public function __construct(private string $sMode,
        private string $sName, private JsExpr $xHandler)
    {}

    /**
     * Convert this call to array, when converting the response into json.
     *
     * @return array
     */
    public function jsonSerialize(): array
    {
        return [
            '_type' => 'event',
            '_name' => $this->sName,
            'mode' => $this->sMode,
            'func' => $this->xHandler->jsonSerialize(),
        ];
    }
}