Overview

Namespaces

  • Avisota
    • Event
    • Message
    • Queue
    • Recipient
    • RecipientSource
    • Renderer
    • Templating
    • Test
      • Database
      • Imap
      • Message
      • Queue
      • Renderer
      • Transport
    • Transport

Classes

  • CSVFile
  • Dummy

Interfaces

  • RecipientSourceInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: /**
  4:  * Avisota newsletter and mailing system
  5:  *
  6:  * PHP Version 5.3
  7:  *
  8:  * @copyright  bit3 UG 2013
  9:  * @author     Tristan Lins <tristan.lins@bit3.de>
 10:  * @package    avisota-core
 11:  * @license    LGPL-3.0+
 12:  * @link       http://avisota.org
 13:  */
 14: 
 15: namespace Avisota\RecipientSource;
 16: 
 17: use Avisota\Recipient\MutableRecipient;
 18: 
 19: /**
 20:  * A recipient source that read the recipients from a csv file.
 21:  *
 22:  * @package avisota-core
 23:  */
 24: class Dummy implements RecipientSourceInterface
 25: {
 26:     /**
 27:      * @var int
 28:      */
 29:     protected $minCount;
 30: 
 31:     /**
 32:      * @var int
 33:      */
 34:     protected $maxCount;
 35: 
 36:     /**
 37:      * @var array
 38:      */
 39:     protected $set;
 40: 
 41:     /**
 42:      * @param string $fileData
 43:      */
 44:     public function __construct($minCount, $maxCount)
 45:     {
 46:         $this->minCount = (int) $minCount;
 47:         $this->maxCount = (int) $maxCount;
 48:     }
 49: 
 50:     /**
 51:      * Count the recipients.
 52:      *
 53:      * @return int
 54:      */
 55:     public function countRecipients()
 56:     {
 57:         return count($this->getRecipients());
 58:     }
 59: 
 60:     /**
 61:      * {@inheritdoc}
 62:      */
 63:     public function getRecipients($limit = null, $offset = null)
 64:     {
 65:         if (empty($this->set)) {
 66:             $this->set = array();
 67: 
 68:             $count = rand($this->minCount, $this->maxCount);
 69:             for ($i = 0; $i < $count; $i++) {
 70:                 list($forename, $surname, $name, $domain) = $this->createName();
 71: 
 72:                 $recipient = new MutableRecipient($name . '@' . $domain);
 73:                 $recipient->set('forename', $forename);
 74:                 $recipient->set('surname', $surname);
 75:                 $this->set[] = $recipient;
 76:             }
 77:         }
 78: 
 79:         $set = $this->set;
 80: 
 81:         if ($offset > 0) {
 82:             $set = array_slice($set, $offset);
 83:         }
 84:         if ($limit > 0 && $limit < count($set)) {
 85:             $set = array_slice($set, 0, $limit);
 86:         }
 87: 
 88:         return $set;
 89:     }
 90: 
 91:     /**
 92:      * @param int $minCount
 93:      */
 94:     public function setMinCount($minCount)
 95:     {
 96:         $this->minCount = (int) $minCount;
 97:         return $this;
 98:     }
 99: 
100:     /**
101:      * @return int
102:      */
103:     public function getMinCount()
104:     {
105:         return $this->minCount;
106:     }
107: 
108:     /**
109:      * @param int $maxCount
110:      */
111:     public function setMaxCount($maxCount)
112:     {
113:         $this->maxCount = (int) $maxCount;
114:         return $this;
115:     }
116: 
117:     /**
118:      * @return int
119:      */
120:     public function getMaxCount()
121:     {
122:         return $this->maxCount;
123:     }
124: 
125:     /**
126:      * @param array $forenames
127:      */
128:     public function setForenames($forenames)
129:     {
130:         $this->forenames = $forenames;
131:         return $this;
132:     }
133: 
134:     /**
135:      * @return array
136:      */
137:     public function getForenames()
138:     {
139:         return $this->forenames;
140:     }
141: 
142:     /**
143:      * @param array $surnames
144:      */
145:     public function setSurnames($surnames)
146:     {
147:         $this->surnames = $surnames;
148:         return $this;
149:     }
150: 
151:     /**
152:      * @return array
153:      */
154:     public function getSurnames()
155:     {
156:         return $this->surnames;
157:     }
158: 
159:     /**
160:      * @param array $domains
161:      */
162:     public function setDomains($domains)
163:     {
164:         $this->domains = $domains;
165:         return $this;
166:     }
167: 
168:     /**
169:      * @return array
170:      */
171:     public function getDomains()
172:     {
173:         return $this->domains;
174:     }
175: 
176:     /**
177:      * Create a new random name.
178:      *
179:      * @return array An array contains forename, surname, name and domain.
180:      */
181:     protected function createName()
182:     {
183:         $index    = rand(0, count($this->forenames) - 1);
184:         $forename = $this->forenames[$index];
185: 
186:         $index   = rand(0, count($this->surnames) - 1);
187:         $surname = $this->surnames[$index];
188: 
189:         $index  = rand(0, count($this->domains) - 1);
190:         $domain = $this->domains[$index];
191: 
192:         switch (rand(1, 8)) {
193:             case 1:
194:                 $name = $forename;
195:                 break;
196:             case 2:
197:                 $name = $surname;
198:                 break;
199:             case 3:
200:                 $name = $forename . '.' . $surname;
201:                 break;
202:             case 4:
203:                 $name = $forename . '-' . $surname;
204:                 break;
205:             case 5:
206:                 $length  = mb_strlen($forename);
207:                 $length2 = floor($length / 2);
208:                 $name    = mb_substr($forename, 0, rand($length2, $length - 1)) . rand(80, 10);
209:                 break;
210:             case 6:
211:                 $length  = mb_strlen($surname);
212:                 $length2 = floor($length / 2);
213:                 $name    = mb_substr($surname, 0, rand($length2, $length - 1)) . rand(80, 10);
214:                 break;
215:             case 7:
216:                 $length          = mb_strlen($forename);
217:                 $length2         = floor($length / 2);
218:                 $forenameShorten = mb_substr($forename, 0, rand($length2, $length - 1));
219:                 $length          = mb_strlen($surname);
220:                 $length2         = floor($length / 2);
221:                 $surnameShorten  = mb_substr($surname, 0, rand($length2, $length - 1));
222:                 $name            = $forenameShorten . '.' . $surnameShorten . rand(80, 10);
223:                 break;
224:             case 8:
225:                 $length          = mb_strlen($forename);
226:                 $length2         = floor($length / 2);
227:                 $forenameShorten = mb_substr($forename, 0, rand($length2, $length - 1));
228:                 $length          = mb_strlen($surname);
229:                 $length2         = floor($length / 2);
230:                 $surnameShorten  = mb_substr($surname, 0, rand($length2, $length - 1));
231:                 $name            = $forenameShorten . '-' . $surnameShorten . rand(80, 10);
232:                 break;
233:             default:
234:                 continue;
235:         }
236: 
237:         return array($forename, $surname, $name, $domain);
238:     }
239: 
240:     protected $forenames = array(
241:         'Adelheid',
242:         'Andreas',
243:         'Anni',
244:         'Arite',
245:         'Bernhilde',
246:         'Bertin',
247:         'Burchard',
248:         'Burghild',
249:         'Catarina',
250:         'Christamaria',
251:         'Christophorus',
252:         'Conny',
253:         'Dankfried',
254:         'Dieter',
255:         'Dietmar',
256:         'Dorlies',
257:         'Ekhard',
258:         'Emmy',
259:         'Erni',
260:         'Ernstfried',
261:         'Felix',
262:         'Freiwald',
263:         'Friedegund',
264:         'Fraenzi',
265:         'Gerdt',
266:         'Gerwin',
267:         'Gitti',
268:         'Gundel',
269:         'Hardi',
270:         'Hartmann',
271:         'Helma',
272:         'Helwart',
273:         'Ingolde',
274:         'Isabelle',
275:         'Iselore',
276:         'Ishild',
277:         'Jana',
278:         'Janfried',
279:         'Jannick',
280:         'Josepha',
281:         'Kai',
282:         'Karina',
283:         'Katharina',
284:         'Kathrinchen',
285:         'Landolf',
286:         'Lenz',
287:         'Liane',
288:         'Loremarie',
289:         'Marei',
290:         'Marianne',
291:         'Mayk',
292:         'Melitta',
293:         'Neidhard',
294:         'Nick',
295:         'Nordfried',
296:         'Notburga',
297:         'Ole',
298:         'Oslinde',
299:         'Ottobert',
300:         'Ottokar',
301:         'Petra',
302:         'Philip',
303:         'Phillippus',
304:         'Pirmin',
305:         'Quintus',
306:         'Quirin',
307:         'Reinfriede',
308:         'Roselies',
309:         'Rudolfina',
310:         'Rupprecht',
311:         'Sibyl',
312:         'Sieglind',
313:         'Steff',
314:         'Sylke',
315:         'Therese',
316:         'Torben',
317:         'Traudl',
318:         'Trautlinde',
319:         'Udo',
320:         'Uli',
321:         'Ulrich',
322:         'Urban',
323:         'Viola',
324:         'Vitus',
325:         'Volkwart',
326:         'Vreni',
327:         'Wendel',
328:         'Wendeline',
329:         'Wilgard',
330:         'Wilhard',
331:         'Xaver',
332:         'Xaverius',
333:         'Yannick',
334:         'Yannik',
335:         'Yasmin',
336:         'Yvonne',
337:         'Zacharias',
338:         'Zenzi',
339:         'Zilli',
340:         'Zita',
341:     );
342: 
343:     protected $surnames = array(
344:         'Mueller',
345:         'Schmidt',
346:         'Schneider',
347:         'Fischer',
348:         'Weber',
349:         'Meyer',
350:         'Wagner',
351:         'Becker',
352:         'Schulz',
353:         'Hoffmann',
354:         'Schaefer',
355:         'Koch',
356:         'Bauer',
357:         'Richter',
358:         'Klein',
359:         'Wolf',
360:         'Schroeder',
361:         'Schneider',
362:         'Neumann',
363:         'Schwarz',
364:         'Zimmermann',
365:         'Braun',
366:         'Krueger',
367:         'Hofmann',
368:         'Hartmann',
369:         'Lange',
370:         'Schmitt',
371:         'Werner',
372:         'Schmitz',
373:         'Krause',
374:         'Meier',
375:         'Lehmann',
376:         'Schmid',
377:         'Schulze',
378:         'Maier',
379:         'Koehler',
380:         'Herrmann',
381:         'Koenig',
382:         'Walter',
383:         'Mayer',
384:         'Huber',
385:         'Kaiser',
386:         'Fuchs',
387:         'Peters',
388:         'Lang',
389:         'Scholz',
390:         'Moeller',
391:         'Weiss',
392:         'Jung',
393:         'Hahn',
394:         'Schubert',
395:         'Vogel',
396:         'Friedrich',
397:         'Keller',
398:         'Guenther',
399:         'Frank',
400:         'Berger',
401:         'Winkler',
402:         'Roth',
403:         'Beck',
404:         'Lorenz',
405:         'Baumann',
406:         'Franke',
407:         'Albrecht',
408:         'Schuster',
409:         'Simon',
410:         'Ludwig',
411:         'Boehm',
412:         'Winter',
413:         'Kraus',
414:         'Martin',
415:         'Schumacher',
416:         'Kraemer',
417:         'Vogt',
418:         'Stein',
419:         'Jaeger',
420:         'Otto',
421:         'Sommer',
422:         'Gross',
423:         'Seidel',
424:         'Heinrich',
425:         'Brandt',
426:         'Haas',
427:         'Schreiber',
428:         'Graf',
429:         'Schulte',
430:         'Dietrich',
431:         'Ziegler',
432:         'Kuhn',
433:         'Kuehn',
434:         'Pohl',
435:         'Engel',
436:         'Horn',
437:         'Busch',
438:         'Bergmann',
439:         'Thomas',
440:         'Voigt',
441:         'Sauer',
442:         'Arnold',
443:         'Wolff',
444:         'Pfeiffer',
445:     );
446: 
447:     protected $domains = array(
448:         'gmail.com',
449:         'zoho.com',
450:         'aol.com',
451:         'shortmail.me',
452:         'outlook.com',
453:         'yahoo.com',
454:         'mail.com',
455:         'gmx.com',
456:         'facebook.com',
457:         'inbox.com',
458:     );
459: }
460: 
avisota/core API documentation generated by ApiGen 2.8.0