<?php
namespace shop;
class Producer implements \ArrayAccess
{
  public function __construct( int $producer_id )
  {
    global $mdb;

    $repo = new \Domain\Producer\ProducerRepository( $mdb );
    $data = $repo->find( $producer_id );

    foreach ( $data as $key => $val )
      $this->$key = $val;
  }

  static public function producer_products( $producer_id, $lang_id, $bs )
  {
    global $mdb;

    $repo = new \Domain\Producer\ProducerRepository( $mdb );
    return $repo->producerProducts( (int) $producer_id, 12, (int) $bs );
  }

  public function __get( $variable )
  {
    if ( array_key_exists( $variable, $this -> data ) )
      return $this -> $variable;
  }

  public function __set( $variable, $value )
  {
    $this -> $variable = $value;
  }

  public function offsetExists( $offset )
  {
    return isset( $this -> $offset );
  }

  public function offsetGet( $offset )
  {
    return $this -> $offset;
  }

  public function offsetSet( $offset, $value )
  {
    $this -> $offset = $value;
  }

  public function offsetUnset( $offset )
  {
    unset( $this -> $offset );
  }
}