/**
* @param \Nette\DI\Container $dic
* @throws MemberAccessException
* @throws MissingServiceException
* @throws InvalidStateException
* @throws UnexpectedValueException
*/
public function injectProperties(Nette\DI\Container $dic)
{
if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) {
throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.');
}
$this->autowirePropertiesLocator = $dic;
$storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage');
$cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireProperties');
$containerFileName = ClassType::from($this->autowirePropertiesLocator)->getFileName();
$cacheKey = [$presenterClass = get_class($this), $containerFileName];
if (is_array($this->autowireProperties = $cache->load($cacheKey))) {
foreach ($this->autowireProperties as $propName => $tmp) {
unset($this->{$propName});
}
return;
}
$this->autowireProperties = [];
$ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter'];
$rc = new ClassType($this);
foreach ($rc->getProperties() as $prop) {
if (!$this->validateProperty($prop, $ignore)) {
continue;
}
$this->resolveProperty($prop);
}
$files = array_map(function ($class) {
return ClassType::from($class)->getFileName();
}, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));
$files[] = $containerFileName;
$cache->save($cacheKey, $this->autowireProperties, [$cache::FILES => $files]);
}