| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * VisualPaginatorExtension.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:VisualPaginator! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @subpackage	DI | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @since		5.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @date		18.06.14 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | namespace IPub\VisualPaginator\DI; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Nette; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Nette\DI; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | class VisualPaginatorExtension extends DI\CompilerExtension | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 	 * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 	protected $defaults = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 		'templateFile'	=> NULL | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | 	]; | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 	public function loadConfiguration() | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 		$config = DI\Config\Helpers::merge($this->getConfig(), $this->defaults); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 		$builder = $this->getContainerBuilder(); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  | 		// Define components | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		$paginator = $builder->addFactoryDefinition($this->prefix('paginator')) | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 			->setImplement('IPub\VisualPaginator\Components\IControl') | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  | 			->addTag('cms.components') | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 			->getResultDefinition() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 			->setType('IPub\VisualPaginator\Components\Control') | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 			->setArguments([new Nette\PhpGenerator\PhpLiteral('$templateFile')]) | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 			->addTag(DI\Extensions\InjectExtension::TAG_INJECT); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 		if ($config['templateFile']) { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  | 			$paginator->addSetup('$service->setTemplateFile(?)', [$config['templateFile']]); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  | 	 * @param Nette\Configurator $config | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 	 * @param string $extensionName | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	public static function register(Nette\Configurator $config, $extensionName = 'visualPaginator') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		$config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler) use ($extensionName) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 			$compiler->addExtension($extensionName, new VisualPaginatorExtension()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		}; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 	/** | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  | 	 * Return array of directories, that contain resources for translator. | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  | 	 * | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  | 	 * @return string[] | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	function getTranslationResources() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 		return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			__DIR__ . '/../Translations' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  | 	} | 
            
                                                                        
                                                                
            
                                    
            
            
                | 70 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |  | 
            
                        
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.