PHP code example of danwe / helpers-gettersetteraccessor

1. Go to this page and download the library: Download danwe/helpers-gettersetteraccessor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

danwe / helpers-gettersetteraccessor example snippets




use Danwe\Helpers\GetterSetterAccessor;

class Options {
  protected $formatter;
  protected $name = 'Php';
  protected $length;

  public function formatter( Formatter $value = null ) {
    return $this->getterSetter( __FUNCTION__ )
      ->initially( function() {
        return new Formatter();
      } )
      ->getOrSet( $value );
  }

  public function name( $value = null ) {
    return $this->getterSetter( __FUNCTION__ )
      ->ofType( 'string' )
      ->getOrSet( $value );
  }

  public function length( $value = null ) {
    return $this->getterSetter( __FUNCTION__ )
      ->ofType( 'int' )
      ->initially( 42 ) // Equivalent to declaring "protected $length = 42" on top
      ->getOrSet( $value );
  }

  protected function getterSetter( $accessProperty ) {
    if( !$this->getterSetter ) {
      $this->getterSetter = new GetterSetterAccessor( $this );
    }
    return $this->getterSetter->property( $accessProperty );
  }
}

php vendor/bin/athletic -p benchmarks