Completed
Push — master ( 072b77...4ad977 )
by Neomerx
05:47
created

SessionFunctions::getCreateIdCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php namespace Limoncello\Application\Session;
2
3
/**
4
 * Copyright 2015-2018 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use ArrayIterator;
20
use Iterator;
21
use Limoncello\Application\Contracts\Session\SessionFunctionsInterface;
22
23
/**
24
 * @package Limoncello\Application
25
 *
26
 * @SuppressWarnings(PHPMD.Superglobals)
27
 * @SuppressWarnings(PHPMD.TooManyFields)
28
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
29
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
30
 */
31
class SessionFunctions implements SessionFunctionsInterface
32
{
33
    /**
34
     * @var callable
35
     */
36
    private $retrieveCallable;
37
38
    /**
39
     * @var callable
40
     */
41
    private $putCallable;
42
43
    /**
44
     * @var callable
45
     */
46
    private $hasCallable;
47
48
    /**
49
     * @var callable
50
     */
51
    private $deleteCallable;
52
53
    /**
54
     * @var callable
55
     */
56
    private $iteratorCallable;
57
58
    /**
59
     * @var callable
60
     */
61
    private $abortCallable;
62
63
    /**
64
     * @var callable
65
     */
66
    private $cacheLimiterCallable;
67
68
    /**
69
     * @var callable
70
     */
71
    private $createIdCallable;
72
73
    /**
74
     * @var callable
75
     */
76
    private $writeCloseCallable;
77
78
    /**
79
     * @var callable
80
     */
81
    private $unsetCallable;
82
83
    /**
84
     * @var callable
85
     */
86
    private $statusCallable;
87
88
    /**
89
     * @var callable
90
     */
91
    private $startCallable;
92
93
    /**
94
     * @var callable
95
     */
96
    private $setSaveHandlerCallable;
97
98
    /**
99
     * @var callable
100
     */
101
    private $setCookieParamsCallable;
102
103
    /**
104
     * @var callable
105
     */
106
    private $savePathCallable;
107
108
    /**
109
     * @var callable
110
     */
111
    private $resetCallable;
112
113
    /**
114
     * @var callable
115
     */
116
    private $registerShutdownCallable;
117
118
    /**
119
     * @var callable
120
     */
121
    private $regenerateIdCallable;
122
123
    /**
124
     * @var callable
125
     */
126
    private $nameCallable;
127
128
    /**
129
     * @var callable
130
     */
131
    private $moduleNameCallable;
132
133
    /**
134
     * @var callable
135
     */
136
    private $decodeCallable;
137
138
    /**
139
     * @var callable
140
     */
141
    private $destroyCallable;
142
143
    /**
144
     * @var callable
145
     */
146
    private $encodeCallable;
147
148
    /**
149
     * @var callable
150
     */
151
    private $gcCallable;
152
153
    /**
154
     * @var callable
155
     */
156
    private $getCookieParamsCallable;
157
158
    /**
159
     * @var callable
160
     */
161
    private $idCallable;
162
163
    /**
164
     * @var callable
165
     */
166
    private $cacheExpireCallable;
167
168
    /**
169
     * @var callable
170
     */
171
    private $couldBeStartedCallable;
172
173
    /**
174
     * Constructor.
175
     */
176 3
    public function __construct()
177
    {
178
        $this
179
            ->setRetrieveCallable(function (string $key) {
180 1
                return $_SESSION[$key];
181 3
            })
182
            ->setPutCallable(function (string $key, $serializable): void {
183 1
                $_SESSION[$key] = $serializable;
184 3
            })
185
            ->setHasCallable(function (string $key): bool {
186 1
                return array_key_exists($key, $_SESSION);
187 3
            })
188
            ->setDeleteCallable(function (string $key): void {
189 1
                unset($_SESSION[$key]);
190 3
            })
191
            ->setIteratorCallable(function (): Iterator {
192 1
                return new ArrayIterator($_SESSION);
193 3
            })
194
            ->setCouldBeStartedCallable(function (): bool {
195 1
                return session_status() === PHP_SESSION_NONE;
196 3
            })
197 3
            ->setAbortCallable('\session_abort')
198 3
            ->setCacheLimiterCallable('\session_cache_limiter')
199 3
            ->setCreateIdCallable('\session_create_id')
200 3
            ->setWriteCloseCallable('\session_write_close')
201 3
            ->setUnsetCallable('\session_unset')
202 3
            ->setStatusCallable('\session_status')
203 3
            ->setStartCallable('\session_start')
204 3
            ->setSetSaveHandlerCallable('\session_set_save_handler')
205 3
            ->setSetCookieParamsCallable('\session_set_cookie_params')
206 3
            ->setSavePathCallable('\session_save_path')
207 3
            ->setResetCallable('\session_reset')
208 3
            ->setRegisterShutdownCallable('\session_register_shutdown')
209 3
            ->setRegenerateIdCallable('\session_regenerate_id')
210 3
            ->setNameCallable('\session_name')
211 3
            ->setModuleNameCallable('\session_module_name')
212 3
            ->setDecodeCallable('\session_decode')
213 3
            ->setDestroyCallable('\session_destroy')
214 3
            ->setEncodeCallable('\session_encode')
215 3
            ->setGcCallable('\session_gc')
216 3
            ->setGetCookieParamsCallable('\session_get_cookie_params')
217 3
            ->setIdCallable('\session_id')
218 3
            ->setCacheExpireCallable('\session_cache_expire');
219
    }
220
221
    /**
222
     * @inheritdoc
223
     */
224 1
    public function getRetrieveCallable(): callable
225
    {
226 1
        return $this->retrieveCallable;
227
    }
228
229
    /**
230
     * @inheritdoc
231
     */
232 3
    public function setRetrieveCallable(callable $callable): SessionFunctionsInterface
233
    {
234 3
        $this->retrieveCallable = $callable;
235
236 3
        return $this;
237
    }
238
239
    /**
240
     * @inheritdoc
241
     */
242 1
    public function getPutCallable(): callable
243
    {
244 1
        return $this->putCallable;
245
    }
246
247
    /**
248
     * @inheritdoc
249
     */
250 3
    public function setPutCallable(callable $callable): SessionFunctionsInterface
251
    {
252 3
        $this->putCallable = $callable;
253
254 3
        return $this;
255
    }
256
257
    /**
258
     * @inheritdoc
259
     */
260 1
    public function getHasCallable(): callable
261
    {
262 1
        return $this->hasCallable;
263
    }
264
265
    /**
266
     * @inheritdoc
267
     */
268 3
    public function setHasCallable(callable $callable): SessionFunctionsInterface
269
    {
270 3
        $this->hasCallable = $callable;
271
272 3
        return $this;
273
    }
274
275
    /**
276
     * @inheritdoc
277
     */
278 1
    public function getDeleteCallable(): callable
279
    {
280 1
        return $this->deleteCallable;
281
    }
282
283
    /**
284
     * @inheritdoc
285
     */
286 3
    public function setDeleteCallable(callable $callable): SessionFunctionsInterface
287
    {
288 3
        $this->deleteCallable = $callable;
289
290 3
        return $this;
291
    }
292
293
    /**
294
     * @inheritdoc
295
     */
296 1
    public function getIteratorCallable(): callable
297
    {
298 1
        return $this->iteratorCallable;
299
    }
300
301
    /**
302
     * @inheritdoc
303
     */
304 3
    public function setIteratorCallable(callable $callable): SessionFunctionsInterface
305
    {
306 3
        $this->iteratorCallable = $callable;
307
308 3
        return $this;
309
    }
310
311
    /**
312
     * @inheritdoc
313
     */
314 1
    public function getAbortCallable(): callable
315
    {
316 1
        return $this->abortCallable;
317
    }
318
319
    /**
320
     * @inheritdoc
321
     */
322 3
    public function setAbortCallable(callable $callable): SessionFunctionsInterface
323
    {
324 3
        $this->abortCallable = $callable;
325
326 3
        return $this;
327
    }
328
329
    /**
330
     * @inheritdoc
331
     */
332 1
    public function getCacheExpireCallable(): callable
333
    {
334 1
        return $this->cacheExpireCallable;
335
    }
336
337
    /**
338
     * @inheritdoc
339
     */
340 3
    public function setCacheExpireCallable(callable $callable): SessionFunctionsInterface
341
    {
342 3
        $this->cacheExpireCallable = $callable;
343
344 3
        return $this;
345
    }
346
347
    /**
348
     * @inheritdoc
349
     */
350 1
    public function getCacheLimiterCallable(): callable
351
    {
352 1
        return $this->cacheLimiterCallable;
353
    }
354
355
    /**
356
     * @inheritdoc
357
     */
358 3
    public function setCacheLimiterCallable(callable $callable): SessionFunctionsInterface
359
    {
360 3
        $this->cacheLimiterCallable = $callable;
361
362 3
        return $this;
363
    }
364
365
    /**
366
     * @inheritdoc
367
     */
368 1
    public function getCreateIdCallable(): callable
369
    {
370 1
        return $this->createIdCallable;
371
    }
372
373
    /**
374
     * @inheritdoc
375
     */
376 3
    public function setCreateIdCallable(callable $callable): SessionFunctionsInterface
377
    {
378 3
        $this->createIdCallable = $callable;
379
380 3
        return $this;
381
    }
382
383
    /**
384
     * @inheritdoc
385
     */
386 1
    public function getDecodeCallable(): callable
387
    {
388 1
        return $this->decodeCallable;
389
    }
390
391
    /**
392
     * @inheritdoc
393
     */
394 3
    public function setDecodeCallable(callable $callable): SessionFunctionsInterface
395
    {
396 3
        $this->decodeCallable = $callable;
397
398 3
        return $this;
399
    }
400
401
    /**
402
     * @inheritdoc
403
     */
404 1
    public function getDestroyCallable(): callable
405
    {
406 1
        return $this->destroyCallable;
407
    }
408
409
    /**
410
     * @inheritdoc
411
     */
412 3
    public function setDestroyCallable(callable $callable): SessionFunctionsInterface
413
    {
414 3
        $this->destroyCallable = $callable;
415
416 3
        return $this;
417
    }
418
419
    /**
420
     * @inheritdoc
421
     */
422 1
    public function getEncodeCallable(): callable
423
    {
424 1
        return $this->encodeCallable;
425
    }
426
427
    /**
428
     * @inheritdoc
429
     */
430 3
    public function setEncodeCallable(callable $callable): SessionFunctionsInterface
431
    {
432 3
        $this->encodeCallable = $callable;
433
434 3
        return $this;
435
    }
436
437
    /**
438
     * @inheritdoc
439
     */
440 1
    public function getGcCallable(): callable
441
    {
442 1
        return $this->gcCallable;
443
    }
444
445
    /**
446
     * @inheritdoc
447
     */
448 3
    public function setGcCallable(callable $callable): SessionFunctionsInterface
449
    {
450 3
        $this->gcCallable = $callable;
451
452 3
        return $this;
453
    }
454
455
    /**
456
     * @inheritdoc
457
     */
458 1
    public function getGetCookieParamsCallable(): callable
459
    {
460 1
        return $this->getCookieParamsCallable;
461
    }
462
463
    /**
464
     * @inheritdoc
465
     */
466 3
    public function setGetCookieParamsCallable(callable $callable): SessionFunctionsInterface
467
    {
468 3
        $this->getCookieParamsCallable = $callable;
469
470 3
        return $this;
471
    }
472
473
    /**
474
     * @inheritdoc
475
     */
476 1
    public function getIdCallable(): callable
477
    {
478 1
        return $this->idCallable;
479
    }
480
481
    /**
482
     * @inheritdoc
483
     */
484 3
    public function setIdCallable(callable $callable): SessionFunctionsInterface
485
    {
486 3
        $this->idCallable = $callable;
487
488 3
        return $this;
489
    }
490
491
    /**
492
     * @inheritdoc
493
     */
494 1
    public function getModuleNameCallable(): callable
495
    {
496 1
        return $this->moduleNameCallable;
497
    }
498
499
    /**
500
     * @inheritdoc
501
     */
502 3
    public function setModuleNameCallable(callable $callable): SessionFunctionsInterface
503
    {
504 3
        $this->moduleNameCallable = $callable;
505
506 3
        return $this;
507
    }
508
509
    /**
510
     * @inheritdoc
511
     */
512 1
    public function getNameCallable(): callable
513
    {
514 1
        return $this->nameCallable;
515
    }
516
517
    /**
518
     * @inheritdoc
519
     */
520 3
    public function setNameCallable(callable $callable): SessionFunctionsInterface
521
    {
522 3
        $this->nameCallable = $callable;
523
524 3
        return $this;
525
    }
526
527
    /**
528
     * @inheritdoc
529
     */
530 1
    public function getRegenerateIdCallable(): callable
531
    {
532 1
        return $this->regenerateIdCallable;
533
    }
534
535
    /**
536
     * @inheritdoc
537
     */
538 3
    public function setRegenerateIdCallable(callable $callable): SessionFunctionsInterface
539
    {
540 3
        $this->regenerateIdCallable = $callable;
541
542 3
        return $this;
543
    }
544
545
    /**
546
     * @inheritdoc
547
     */
548 1
    public function getRegisterShutdownCallable(): callable
549
    {
550 1
        return $this->registerShutdownCallable;
551
    }
552
553
    /**
554
     * @inheritdoc
555
     */
556 3
    public function setRegisterShutdownCallable(callable $callable): SessionFunctionsInterface
557
    {
558 3
        $this->registerShutdownCallable = $callable;
559
560 3
        return $this;
561
    }
562
563
    /**
564
     * @inheritdoc
565
     */
566 1
    public function getResetCallable(): callable
567
    {
568 1
        return $this->resetCallable;
569
    }
570
571
    /**
572
     * @inheritdoc
573
     */
574 3
    public function setResetCallable(callable $callable): SessionFunctionsInterface
575
    {
576 3
        $this->resetCallable = $callable;
577
578 3
        return $this;
579
    }
580
581
    /**
582
     * @inheritdoc
583
     */
584 1
    public function getSavePathCallable(): callable
585
    {
586 1
        return $this->savePathCallable;
587
    }
588
589
    /**
590
     * @inheritdoc
591
     */
592 3
    public function setSavePathCallable(callable $callable): SessionFunctionsInterface
593
    {
594 3
        $this->savePathCallable = $callable;
595
596 3
        return $this;
597
    }
598
599
    /**
600
     * @inheritdoc
601
     */
602 1
    public function getSetCookieParamsCallable(): callable
603
    {
604 1
        return $this->setCookieParamsCallable;
605
    }
606
607
    /**
608
     * @inheritdoc
609
     */
610 3
    public function setSetCookieParamsCallable(callable $callable): SessionFunctionsInterface
611
    {
612 3
        $this->setCookieParamsCallable = $callable;
613
614 3
        return $this;
615
    }
616
617
    /**
618
     * @inheritdoc
619
     */
620 1
    public function getSetSaveHandlerCallable(): callable
621
    {
622 1
        return $this->setSaveHandlerCallable;
623
    }
624
625
    /**
626
     * @inheritdoc
627
     */
628 3
    public function setSetSaveHandlerCallable(callable $callable): SessionFunctionsInterface
629
    {
630 3
        $this->setSaveHandlerCallable = $callable;
631
632 3
        return $this;
633
    }
634
635
    /**
636
     * @inheritdoc
637
     */
638 2
    public function getStartCallable(): callable
639
    {
640 2
        return $this->startCallable;
641
    }
642
643
    /**
644
     * @inheritdoc
645
     */
646 3
    public function setStartCallable(callable $callable): SessionFunctionsInterface
647
    {
648 3
        $this->startCallable = $callable;
649
650 3
        return $this;
651
    }
652
653
    /**
654
     * @inheritdoc
655
     */
656 1
    public function getStatusCallable(): callable
657
    {
658 1
        return $this->statusCallable;
659
    }
660
661
    /**
662
     * @inheritdoc
663
     */
664 3
    public function setStatusCallable(callable $callable): SessionFunctionsInterface
665
    {
666 3
        $this->statusCallable = $callable;
667
668 3
        return $this;
669
    }
670
671
    /**
672
     * @inheritdoc
673
     */
674 1
    public function getUnsetCallable(): callable
675
    {
676 1
        return $this->unsetCallable;
677
    }
678
679
    /**
680
     * @inheritdoc
681
     */
682 3
    public function setUnsetCallable(callable $callable): SessionFunctionsInterface
683
    {
684 3
        $this->unsetCallable = $callable;
685
686 3
        return $this;
687
    }
688
689
    /**
690
     * @inheritdoc
691
     */
692 2
    public function getWriteCloseCallable(): callable
693
    {
694 2
        return $this->writeCloseCallable;
695
    }
696
697
    /**
698
     * @inheritdoc
699
     */
700 3
    public function setWriteCloseCallable(callable $callable): SessionFunctionsInterface
701
    {
702 3
        $this->writeCloseCallable = $callable;
703
704 3
        return $this;
705
    }
706
707
    /**
708
     * @inheritdoc
709
     */
710 1
    public function getCouldBeStartedCallable(): callable
711
    {
712 1
        return $this->couldBeStartedCallable;
713
    }
714
715
    /**
716
     * @inheritdoc
717
     */
718 3
    public function setCouldBeStartedCallable(callable $callable): SessionFunctionsInterface
719
    {
720 3
        $this->couldBeStartedCallable = $callable;
721
722 3
        return $this;
723
    }
724
}
725