On Jan 31, 2008 11:11 PM, Akash Xavier <[EMAIL PROTECTED]> wrote:

> Kevin,
> Can u explain what is a dependency injection and how its used in shindig
> (with respect to php... I saw that php too has dome DI conatiners...) ?


Dependency injection is simply the concept of 'injecting' dependencies into
a piece of code (typically achieved by using  interfaces or callbacks). Try
this link: http://en.wikipedia.org/wiki/Dependency_Injection


> And also how to implement a gadgetSigner in php? (just tell the basic
> logic
> on how this is done....)


In PHP the logical thing would probably be to generate tokens by serializing
a php array with the appropriate data (viewer / owner id or other such
information) and encrypting it using one of the standard encryption
extensions (I believe the openssl extension can handle RSA, so that's
probably what you want).

Something like this:

<?php

class MySigner implements GadgetSigner {
  private $crypter;
  private $viewerId;
  private $ownerId;
  // Getters for all of these fields...
  // OpenSSL class assumed to be similar to the one found in the comments on
http://us.php.net/openssl
  public function __construct(OpenSSL $crypter, $viewerId, $ownerId) {
    $this->crypter = $crypter;
    $this->viewerId = $viewerId;
    $this->ownerId = $ownerId;
  }
  public function createToken($gadget) {
    if ($gadget instanceof Gadget) {
      return new MyToken($this, $gadget->getId()->getUrl(), $viewerId,
$ownerId);
    } else /* assume a string */ {
      $data = unserialize($this->crypter->decrypt($gadget));
      // assert that it's correct...
     return new MyToken($this, $data['url'], $data['viewer'],
$data['owner']);
    }
  }

  public function encrypt($viewerId, $ownerId, $gadgetUrl) {
    return
$this->crypter->encrypt(serialize(array('viewer'=>$viewerId,'owner'=>$ownerId,'url'=>$gadgetUrl)));
  }
}

class MyToken implements GadgetToken {
  private MySigner $signer;
  private $gadgetUrl;
  private $viewerId;
  private $ownerId;

  public function __construct(MySigner $signer, $gadgetUrl, $viewerId,
$ownerId) {
    $this->signer = $signer;
    $this->gadget = $gadget;
  }
  public function toSerialForm() {
    return $this->signer->encrypt($this->gadgetUrl, $this->viewerId,
$this->ownerId);
  }
}

Reply via email to