PHP Classes

File: src/Script/Action/Attr.php

Recommend this page to a friend!
  Packages of Thierry Feuzeu   Jaxon   src/Script/Action/Attr.php   Download  
File: src/Script/Action/Attr.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,353 bytes
 

Contents

Class file image Download
<?php

namespace Jaxon\Script\Action;

class
Attr extends TypedValue
{
   
/**
     * The constructor
     *
     * @param array $aValue
     */
   
public function __construct(private array $aValue)
    {}

   
/**
     * @inheritDoc
     */
   
public function getType(): string
   
{
        return
$this->aValue['_type'] ?? '_';
    }

   
/**
     * Create an abject to get the value of an attribute
     *
     * @param string $sAttrName The attribute name
     *
     * @return Attr
     */
   
public static function get(string $sAttrName): Attr
   
{
        return new
Attr([
           
'_type' => 'attr',
           
'_name' => $sAttrName,
        ]);
    }

   
/**
     * Create an abject to set the value of an attribute
     *
     * @param string $sAttrName The attribute name
     * @param mixed $xAttrValue The attribute value
     *
     * @return Attr
     */
   
public static function set(string $sAttrName, $xAttrValue): Attr
   
{
        return new
Attr([
           
'_type' => 'attr',
           
'_name' => $sAttrName,
           
'value' => TypedValue::make($xAttrValue)->jsonSerialize(),
        ]);
    }

   
/**
     * Convert this call to array, when converting the response into json.
     *
     * @return array
     */
   
public function jsonSerialize(): array
    {
        return
$this->aValue;
    }
}