I get a strange error in a class that implements an interface.
Error:
Fatal error allowed: argument 1 passed MyApp \ Library \ Cache :: __ construct () must be an instance of MyApp \ Contacts \ CacheInterface, an instance of MyApp \ Driver \ Cache \ File is given
File class:
namespace MyApp\Driver\Cache; use MyApp\Library\Config; use MyApp\Contracts\CacheInterface; class File implements CacheInterface { private $expire; public function __construct($expire, Config $config) { $this->expire = $expire; $this->config = $config; ... more code } }
Cache Class:
namespace MyApp\Library; use MyApp\Contacts\CacheInterface; final class Cache { private $cache; public function __construct(CacheInterface $cache) { $this->cache = $cache; } ... more methods }
Interface:
namespace MyApp\Contracts; interface CacheInterface { public function get($key); public function set($key, $value); public function delete($key); public function flush_cache(); }
Implemented as a service in a Pimple container:
$this->data['cache'] = function ($data) { switch ($data['config_cache_type_id']): case 'apc': $driver = new Apc($data['cache.time'], $data['config']); break; case 'mem': $driver = new Mem($data['cache.time'], $data['config']); $driver->connect(); break; case 'file': default: $driver = new File($data['cache.time'], $data['config']); break; endswitch; return new Cache($driver); };
Of course, 4 driver and cache classes are included in the use key before the container class.
I do not see what I am missing. I performed several other contracts in exactly the same procedure. Any ideas would be appreciated.
source share