| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This software package is licensed under AGPL or Commercial license. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @package maslosoft/mangan | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @licence AGPL or Commercial | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @copyright Copyright (c) Piotr Masełkowski <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @copyright Copyright (c) Maslosoft | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright Copyright (c) Others as mentioned in code | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @link https://maslosoft.com/mangan/ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | namespace Maslosoft\Mangan\Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Maslosoft\Addendum\Interfaces\AnnotatedInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Maslosoft\Mangan\Exceptions\ManganException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Maslosoft\Mangan\Finder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Maslosoft\Mangan\Interfaces\EntityManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Maslosoft\Mangan\Interfaces\FinderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Maslosoft\Mangan\Mangan; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * Finder variant which returns raw arrays. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * For internal or special cases use. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @author Piotr Maselkowski <pmaselkowski at gmail.com> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | class RawFinder extends Finder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 | 5 |  | 	public function __construct($model, $em = null, $mangan = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 34 | 5 |  | 		parent::__construct($model, $em, $mangan); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		// Cannot use cursors in raw finder, as it will clash with PkManager | 
            
                                                                        
                            
            
                                    
            
            
                | 36 | 5 |  | 		$this->withCursor(false); | 
            
                                                                        
                            
            
                                    
            
            
                | 37 | 5 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * Create raw finder instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 * @param AnnotatedInterface $model | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	 * @param EntityManagerInterface $em | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * @param Mangan $mangan | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * @return FinderInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	public static function create(AnnotatedInterface $model, $em = null, Mangan $mangan = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		return new static($model, $em, $mangan); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 5 |  | 	protected function populateRecord($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 5 |  | 		return $this->createModel($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 5 |  | 	protected function createModel($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 5 |  | 		if (!empty($data['$err'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			throw new ManganException(sprintf("There is an error in query: %s", $data['$err'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 5 |  | 		return $data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |  |