@@ -67,32 +67,37 @@ class ResultIterator implements Result, \ArrayAccess, \JsonSerializable
67
67
68
68
private $ logger ;
69
69
70
+ private function __construct ()
71
+ {
72
+ }
73
+
70
74
/**
71
75
* @param mixed[] $parameters
72
76
*/
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
74
78
{
79
+ $ iterator = new self ();
75
80
if ($ mode !== TDBMService::MODE_CURSOR && $ mode !== TDBMService::MODE_ARRAY ) {
76
81
throw new TDBMException ("Unknown fetch mode: ' " .$ mode ."' " );
77
82
}
78
83
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 ;
91
93
}
92
94
93
95
public static function createEmpyIterator (): self
94
96
{
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 ;
96
101
}
97
102
98
103
protected function executeCountQuery (): void
@@ -158,11 +163,11 @@ public function getIterator()
158
163
{
159
164
if ($ this ->innerResultIterator === null ) {
160
165
if ($ this ->totalCount === 0 ) {
161
- $ this ->innerResultIterator = new InnerResultArray ( null , null , null , null , null , null , null , null , null , null );
166
+ $ this ->innerResultIterator = InnerResultArray:: createEmpyIterator ( );
162
167
} 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 );
164
169
} 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 );
166
171
}
167
172
}
168
173
@@ -178,9 +183,9 @@ public function getIterator()
178
183
public function take ($ offset , $ limit )
179
184
{
180
185
if ($ this ->totalCount === 0 ) {
181
- return new PageIterator ($ this , null , [], null , null , null , null , null , null , null , null , null );
186
+ return PageIterator:: createEmpyIterator ($ this );
182
187
}
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 );
184
189
}
185
190
186
191
/**
0 commit comments