@@ -67,32 +67,37 @@ class ResultIterator implements Result, \ArrayAccess, \JsonSerializable
6767
6868 private $ logger ;
6969
70+ private function __construct ()
71+ {
72+ }
73+
7074 /**
7175 * @param mixed[] $parameters
7276 */
73- public function __construct (? QueryFactory $ queryFactory , ? array $ parameters , ? ObjectStorageInterface $ objectStorage , ?string $ className , ? TDBMService $ tdbmService , ? MagicQuery $ magicQuery , int $ mode , ? LoggerInterface $ logger )
77+ public static function createResultIterator ( QueryFactory $ queryFactory , array $ parameters , ObjectStorageInterface $ objectStorage , ?string $ className , TDBMService $ tdbmService , MagicQuery $ magicQuery , int $ mode , LoggerInterface $ logger ): self
7478 {
79+ $ iterator = new self ();
7580 if ($ mode !== TDBMService::MODE_CURSOR && $ mode !== TDBMService::MODE_ARRAY ) {
7681 throw new TDBMException ("Unknown fetch mode: ' " .$ mode ."' " );
7782 }
7883
79- if (!$ queryFactory ) {
80- $ this ->totalCount = 0 ;
81- } else {
82- $ this ->queryFactory = $ queryFactory ;
83- $ this ->objectStorage = $ objectStorage ;
84- $ this ->className = $ className ;
85- $ this ->tdbmService = $ tdbmService ;
86- $ this ->parameters = $ parameters ;
87- $ this ->magicQuery = $ magicQuery ;
88- $ this ->mode = $ mode ;
89- }
90- $ this ->logger = $ logger ?? new NullLogger ();
84+ $ iterator ->queryFactory = $ queryFactory ;
85+ $ iterator ->objectStorage = $ objectStorage ;
86+ $ iterator ->className = $ className ;
87+ $ iterator ->tdbmService = $ tdbmService ;
88+ $ iterator ->parameters = $ parameters ;
89+ $ iterator ->magicQuery = $ magicQuery ;
90+ $ iterator ->mode = $ mode ;
91+ $ iterator ->logger = $ logger ;
92+ return $ iterator ;
9193 }
9294
9395 public static function createEmpyIterator (): self
9496 {
95- return new self (null , null , null , null , null , null , TDBMService::MODE_ARRAY , null );
97+ $ iterator = new self ();
98+ $ iterator ->totalCount = 0 ;
99+ $ iterator ->logger = new NullLogger ();
100+ return $ iterator ;
96101 }
97102
98103 protected function executeCountQuery (): void
@@ -158,11 +163,11 @@ public function getIterator()
158163 {
159164 if ($ this ->innerResultIterator === null ) {
160165 if ($ this ->totalCount === 0 ) {
161- $ this ->innerResultIterator = new InnerResultArray ( null , null , null , null , null , null , null , null , null , null );
166+ $ this ->innerResultIterator = InnerResultArray:: createEmpyIterator ( );
162167 } elseif ($ this ->mode === TDBMService::MODE_CURSOR ) {
163- $ this ->innerResultIterator = new InnerResultIterator ($ this ->queryFactory ->getMagicSql (), $ this ->parameters , null , null , $ this ->queryFactory ->getColumnDescriptors (), $ this ->objectStorage , $ this ->className , $ this ->tdbmService , $ this ->magicQuery , $ this ->logger );
168+ $ this ->innerResultIterator = InnerResultIterator:: createInnerResultIterator ($ this ->queryFactory ->getMagicSql (), $ this ->parameters , null , null , $ this ->queryFactory ->getColumnDescriptors (), $ this ->objectStorage , $ this ->className , $ this ->tdbmService , $ this ->magicQuery , $ this ->logger );
164169 } else {
165- $ this ->innerResultIterator = new InnerResultArray ($ this ->queryFactory ->getMagicSql (), $ this ->parameters , null , null , $ this ->queryFactory ->getColumnDescriptors (), $ this ->objectStorage , $ this ->className , $ this ->tdbmService , $ this ->magicQuery , $ this ->logger );
170+ $ this ->innerResultIterator = InnerResultArray:: createInnerResultIterator ($ this ->queryFactory ->getMagicSql (), $ this ->parameters , null , null , $ this ->queryFactory ->getColumnDescriptors (), $ this ->objectStorage , $ this ->className , $ this ->tdbmService , $ this ->magicQuery , $ this ->logger );
166171 }
167172 }
168173
@@ -178,9 +183,9 @@ public function getIterator()
178183 public function take ($ offset , $ limit )
179184 {
180185 if ($ this ->totalCount === 0 ) {
181- return new PageIterator ($ this , null , [], null , null , null , null , null , null , null , null , null );
186+ return PageIterator:: createEmpyIterator ($ this );
182187 }
183- return new PageIterator ($ this , $ this ->queryFactory ->getMagicSql (), $ this ->parameters , $ limit , $ offset , $ this ->queryFactory ->getColumnDescriptors (), $ this ->objectStorage , $ this ->className , $ this ->tdbmService , $ this ->magicQuery , $ this ->mode , $ this ->logger );
188+ return PageIterator:: createResultIterator ($ this , $ this ->queryFactory ->getMagicSql (), $ this ->parameters , $ limit , $ offset , $ this ->queryFactory ->getColumnDescriptors (), $ this ->objectStorage , $ this ->className , $ this ->tdbmService , $ this ->magicQuery , $ this ->mode , $ this ->logger );
184189 }
185190
186191 /**
0 commit comments