# DirectoryContext.class.php

Go to the documentation of this file.

    00001 <?php
    00002 /***************************************************************************
    00003  *   Copyright (C) 2009 by Ivan Y. Khvostishkov                            *
    00004  *                                                                         *
    00005  *   This program is free software; you can redistribute it and/or modify  *
    00006  *   it under the terms of the GNU Lesser General Public License as        *
    00007  *   published by the Free Software Foundation; either version 3 of the    *
    00008  *   License, or (at your option) any later version.                       *
    00009  *                                                                         *
    00010  ***************************************************************************/
    00011
    00012     final class DirectoryContext
    00013     {
    00014         private $map = array();
    00015         private $reverseMap = array();
    00016
    00017         public function bind($name, $object)
    00018         {
    00019             if (!is_dir($name))
    00020                 throw new WrongArgumentException(
    00021                     'directory '.$name.' does not exists'
    00022                 );
    00023
    00024             if (
    00025                 isset($this->map[$name])
    00026                 && $this->map[$name] !== $object
    00027             )
    00028                 throw new WrongArgumentException('consider using rebind()');
    00029
    00030             return $this->rebind($name, $object);
    00031         }
    00032
    00033         public function rebind($name, $object)
    00034         {
    00035             Assert::isNotNull($object);
    00036
    00037             $this->map[$name] = $object;
    00038             $this->reverseMap[spl_object_hash($object)] = $name;
    00039
    00040             return $this;
    00041         }
    00042
    00043         public function lookup($name)
    00044         {
    00045             if (!isset($this->map[$name]))
    00046                 return null;
    00047
    00048             return $this->map[$name];
    00049         }
    00050
    00051         public function reverseLookup($object)
    00052         {
    00053             if (!isset($this->reverseMap[spl_object_hash($object)]))
    00054                 return null;
    00055
    00056             return $this->reverseMap[spl_object_hash($object)];
    00057         }
    00058     }
    00059 ?>