PHP Classes

File: src/Script/Call/AbstractJsCall.php

Recommend this page to a friend!
  Packages of Thierry Feuzeu   Jaxon   src/Script/Call/AbstractJsCall.php   Download  
File: src/Script/Call/AbstractJsCall.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: 4 months ago
Size: 1,711 bytes
 

Contents

Class file image Download
<?php

namespace Jaxon\Script\Call;

/**
 * AbstractJsCall
 *
 * Base class for js (not Jaxon) calls and selectors.
 *
 * @package jaxon-core
 * @author Thierry Feuzeu
 * @copyright 2024 Thierry Feuzeu <thierry.feuzeu@gmail.com>
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
 * @link https://github.com/jaxon-php/jaxon-core
 */

use Jaxon\Script\Action\Attr;
use
Jaxon\Script\Action\Selector;
use
Jaxon\Script\JsExpr;
use
Closure;

abstract class
AbstractJsCall extends AbstractCall
{
   
/**
     * The constructor.
     *
     * @param Closure|null $xExprCb
     */
   
protected function __construct(protected ?Closure $xExprCb)
    {}

   
/**
     * Get the call to add to the expression
     *
     * @return Attr|Selector
     */
   
abstract protected function _exprCall(): Attr|Selector;

   
/**
     * Get the json expression
     *
     * @return JsExpr
     */
   
protected function _expr(): JsExpr
   
{
       
$xJsExpr = new JsExpr($this->_exprCall());
       
// Apply the callback, if one was defined.
       
$this->xExprCb !== null && ($this->xExprCb)($xJsExpr);
        return
$xJsExpr;
    }

   
/**
     * Get the value of an attribute of the current object
     *
     * @param string $sAttribute
     *
     * @return JsExpr
     */
   
public function __get(string $sAttribute): JsExpr
   
{
        return
$this->_expr()->__get( $sAttribute);
    }

   
/**
     * Set the value of an attribute of the current object
     *
     * @param string $sAttribute
     * @param mixed $xValue
     *
     * @return void
     */
   
public function __set(string $sAttribute, $xValue)
    {
        return
$this->_expr()->__set($sAttribute, $xValue);
    }
}