File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,22 @@ public function checkRequirements($element)
106106	}
107107
108108
109+ 	/** 
110+ 	 * Component factory. Delegates the creation of components to a createComponent<Name> method. 
111+ 	 * @param string $name 
112+ 	 * @return Nette\ComponentModel\IComponent the created component (optionally) 
113+ 	 */ 
114+ 	protected  function  createComponent ($ name
115+ 	{
116+ 		$ method'createComponent '  . ucfirst ($ name
117+ 		if  (method_exists ($ this $ method
118+ 			$ this checkRequirements ($ this getReflection ()->getMethod ($ method
119+ 		}
120+ 
121+ 		return  parent ::createComponent ($ name
122+ 	}
123+ 
124+ 
109125	/** 
110126	 * Access to reflection. 
111127	 * @return ComponentReflection 
Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ /** 
4+  * Test: Nette\Application\UI\Component::createComponent() 
5+  */ 
6+ 
7+ use  Nette \Application ;
8+ use  Tester \Assert ;
9+ 
10+ require  __DIR__  . '/../bootstrap.php ' ;
11+ 
12+ 
13+ class  TestSubComponent extends  Application \UI \Component
14+ {
15+ }
16+ 
17+ class  TestComponent extends  Application \UI \Component
18+ {
19+ 	public  $ calledWith
20+ 
21+ 	public  function  checkRequirements ($ element
22+ 	{
23+ 		$ this calledWith  = $ element
24+ 	}
25+ 
26+ 	public  function  createComponentTest ()
27+ 	{
28+ 		return  new  TestSubComponent ;
29+ 	}
30+ }
31+ 
32+ $ componentnew  TestComponent ;
33+ Assert::true ($ componentgetComponent ('test ' ) instanceof  TestSubComponent);
34+ Assert::true ($ componentcalledWith  instanceof  ReflectionMethod);
35+ Assert::same ('createComponentTest ' , $ componentcalledWith ->getName ());
36+ Assert::same (TestComponent::class, $ componentcalledWith ->getDeclaringClass ()->getName ());
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments