Element

class Element

Class Element

Wrapper class for stdClass that helps make accessing arbitrary properties safer

Properties

protected stdClass $_data

Methods

public __construct(stdClass $data) Element constructor.
public bool __isset(string $name) No description
public mixed __get(string $name) No description
protected mixed _wrap(mixed $elem) No description

Details

at line 24

__construct()

public __construct(stdClass $data)

Element constructor.

Parameters

stdClass $data
at line 33

__isset()

public bool __isset(string $name)

Parameters

string $name

Return Value

bool
at line 42

__get()

public mixed __get(string $name)

Parameters

string $name

Return Value

mixed
at line 54

_wrap()

protected mixed _wrap(mixed $elem)

Parameters

mixed $elem

Return Value

mixed

Source code

<?php

namespace SFClient;

/**
 * Class Element
 *
 * Wrapper class for stdClass that helps make accessing arbitrary
 * properties safer
 *
 * @package SalesForce
 */
class Element {

  /**
   * @var \stdClass
   */
  protected $_data;

  /**
   * Element constructor.
   * @param \stdClass $data
   */
  public function __construct(\stdClass $data) {
    $this->_data = $data;
  }

  /**
   * @param string $name
   * @return bool
   * @internal
   */
  public function __isset($name) {
    return isset($this->_data) && isset($this->_data->{$name});
  }

  /**
   * @param string $name
   * @return mixed
   * @internal
   */
  public function __get($name) {
    if (isset($this->{$name})) {
      return $this->_wrap($this->_data->$name);
    }

    return null;
  }

  /**
   * @param mixed $elem
   * @return mixed
   */
  protected function _wrap($elem) {
    if ($elem instanceof \stdClass) {
      return new Element($elem);
    } elseif (is_array($elem)) {
      return array_map(
        function ($e) { return $this->_wrap($e); },
        $elem
      );
    }

    return $elem;
  }
}