| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * ConfirmationDialogExtension.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @copyright      More in license.md | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @license        http://www.ipublikuj.eu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author         Adam Kadlec http://www.ipublikuj.eu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @package        iPublikuj:ConfirmationDialog! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @subpackage     DI | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @since          1.0.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @date           08.06.14 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | declare(strict_types = 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | namespace IPub\ConfirmationDialog\DI; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Nette; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Nette\DI; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Nette\PhpGenerator as Code; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use IPub; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use IPub\ConfirmationDialog; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use IPub\ConfirmationDialog\Components; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use IPub\ConfirmationDialog\Storage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * Confirmation dialog extension container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @package        iPublikuj:ConfirmationDialog! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @subpackage     DI | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * @author         Adam Kadlec <[email protected]> | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 35 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 1 |  | final class ConfirmationDialogExtension extends DI\CompilerExtension | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 	 * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 	private $defaults = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  | 		'layoutFile'   => NULL, | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 		'templateFile' => NULL | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 	]; | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	public function loadConfiguration() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 1 |  | 		$config = $this->getConfig($this->defaults); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  | 		$builder = $this->getContainerBuilder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		// Session storage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  | 		$builder->addDefinition($this->prefix('storage')) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  | 			->setClass(Storage\Session::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  | 		$confirmerFactory = $builder->addDefinition($this->prefix('confirmer')) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1 |  | 			->setClass(Components\Confirmer::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  | 			->setImplement(Components\IConfirmer::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  | 			->setArguments([new Code\PhpLiteral('$templateFile')]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  | 			->setAutowired(FALSE) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  | 			->setInject(TRUE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		// Define components factories | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  | 		$dialogFactory = $builder->addDefinition($this->prefix('dialog')) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 1 |  | 			->setClass(Components\Control::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  | 			->setImplement(Components\IControl::class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 1 |  | 			->setArguments([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 1 |  | 				new Code\PhpLiteral('$layoutFile'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 1 |  | 				new Code\PhpLiteral('$templateFile'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  | 				$confirmerFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 			]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  | 			->setInject(TRUE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  | 		if ($config['layoutFile']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			$dialogFactory->addSetup('$service->setLayoutFile(?)', [$config['layoutFile']]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  | 		if ($config['templateFile']) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			$dialogFactory->addSetup('$service->setTemplateFile(?)', [$config['templateFile']]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 | 1 |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  | 	 * @param Nette\Configurator $config | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 	 * @param string $extensionName | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	public static function register(Nette\Configurator $config, $extensionName = 'confirmationDialog') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 1 |  | 		$config->onCompile[] = function (Nette\Configurator $config, DI\Compiler $compiler) use ($extensionName) : void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 1 |  | 			$compiler->addExtension($extensionName, new ConfirmationDialogExtension()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 1 |  | 		}; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 | 1 |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  | 	 * Return array of directories, that contain resources for translator. | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 	 * @return string[] | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	public function getTranslationResources() : array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Translations' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 103 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 104 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 105 |  |  |  | 
            
                        
This method has been deprecated.