| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace T4web\Authentication\Adapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Zend\ServiceManager\FactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Zend\ServiceManager\ServiceLocatorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Zend\Authentication\Adapter\DbTable\CallbackCheckAdapter as AuthenticationAdapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Zend\Db\Adapter\Adapter as DbAdapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use T4web\Authentication\Exception\RuntimeException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use T4webInfrastructure\Config; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class TableFactory implements FactoryInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public function createService(ServiceLocatorInterface $serviceLocator) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         /** @var DbAdapter $dbAdapter */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $dbAdapter = $serviceLocator->get(DbAdapter::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         /** @var Config $userInfrastructureConfig */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $config = $serviceLocator->get('config'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         if (!isset($config['auth']) || !isset($config['auth']['table-adapter'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             throw new RuntimeException('For authentication with table adapter, you must describe config[auth][table-adapter]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         if (!isset($config['auth']['table-adapter']['table-name']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             || !isset($config['auth']['table-adapter']['identity-column']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             || !isset($config['auth']['table-adapter']['credential-column'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             throw new RuntimeException('For authentication with table adapter, you must describe table-name, ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 . 'identity-column and credential-column keys in config[auth][table-adapter]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $tableName = $config['auth']['table-adapter']['table-name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $identityColumn = $config['auth']['table-adapter']['identity-column']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $credentialColumn = $config['auth']['table-adapter']['credential-column']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $credentialCallback = function ($passwordInDatabase, $passwordProvided) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             return password_verify($passwordProvided, $passwordInDatabase); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         return new AuthenticationAdapter($dbAdapter, $tableName, $identityColumn, $credentialColumn, $credentialCallback); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 42 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |  |