seotils/has-parent

The trait allows set and get parent class of instance.

0.0.3 2016-09-06 20:30 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:18:35 UTC


README

Description

This trait assigns parent to a class.

License

HasParent is open-sourced software licensed under the [GPL-3.0] (https://www.gnu.org/licenses/gpl-3.0.en.html).

Requirements

Package depends on deferred-exceptions package.

  1. GitHub:

  2. Composer (packagist.org):

  3. PHPClasses:

Install

composer require seotils/has-parent

Usage

<?php

namespace My;

use Seotils\Traits\HasParent;

/**
 * Parent class
 */
class A {
  public function time(){
    return date('Y-m-d H:i:s');
  }
}

/**
 * Class with HasParent trait
 */
class B {
  use HasParent;
}

// Usage

$a = new A();
$b = new B();

// Assign and use parent class
echo $b->parentClass( $a )->time();

// Or step by step

// Assign parent class
$b->parentClass( $a );

// Use parent class
echo $b->parentClass()->time();

That`s all!