1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8/**
9 * Factory used in test cases to test fallbacks.
10 */
11class Perms_ResolverFactory_TestFactory implements Perms_ResolverFactory
12{
13	private $known;
14	private $resolvers;
15
16	function __construct(array $known, array $resolvers)
17	{
18		$this->known = $known;
19		$this->resolvers = $resolvers;
20	}
21
22	function bulk(array $baseContext, $bulkKey, array $values)
23	{
24		return [];
25	}
26
27	function getHash(array $context)
28	{
29		$parts = [];
30
31		foreach ($this->known as $key) {
32			if (isset($context[$key])) {
33				$parts[] = $context[$key];
34			}
35		}
36
37		return 'test:' . implode(':', $parts);
38	}
39
40	function getResolver(array $context)
41	{
42		$hash = $this->getHash($context);
43
44		if (isset($this->resolvers[$hash])) {
45			return $this->resolvers[$hash];
46		}
47	}
48}
49