Completed
Push — master ( fc40f2...fd0e92 )
by Neomerx
06:29
created

SessionFunctions::getCreateIdCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Limoncello\Application\Session;
2
3
/**
4
 * Copyright 2015-2017 [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
     * @var callable
164
     */
165
    private $cacheExpireCallable;
166
167
    /**
168
     * Constructor.
169
     */
170
    public function __construct()
171
    {
172
        $this
173 3
            ->setRetrieveCallable(function (string $key) {
174 1
                return $_SESSION[$key];
175 3
            })
176 3
            ->setPutCallable(function (string $key, $serializable): void {
177 1
                $_SESSION[$key] = $serializable;
178 3
            })
179 3
            ->setHasCallable(function (string $key): bool {
180 1
                return array_key_exists($key, $_SESSION);
181 3
            })
182 3
            ->setDeleteCallable(function (string $key): void {
183 1
                unset($_SESSION[$key]);
184 3
            })
185 3
            ->setIteratorCallable(function (): Iterator {
186 1
                return new ArrayIterator($_SESSION);
187 3
            })
188 3
            ->setAbortCallable('\session_abort')
189 3
            ->setCacheLimiterCallable('\session_cache_limiter')
190 3
            ->setCreateIdCallable('\session_create_id')
191 3
            ->setWriteCloseCallable('\session_write_close')
192 3
            ->setUnsetCallable('\session_unset')
193 3
            ->setStatusCallable('\session_status')
194 3
            ->setStartCallable('\session_start')
195 3
            ->setSetSaveHandlerCallable('\session_set_save_handler')
196 3
            ->setSetCookieParamsCallable('\session_set_cookie_params')
197 3
            ->setSavePathCallable('\session_save_path')
198 3
            ->setResetCallable('\session_reset')
199 3
            ->setRegisterShutdownCallable('\session_register_shutdown')
200 3
            ->setRegenerateIdCallable('\session_regenerate_id')
201 3
            ->setNameCallable('\session_name')
202 3
            ->setModuleNameCallable('\session_module_name')
203 3
            ->setDecodeCallable('\session_decode')
204 3
            ->setDestroyCallable('\session_destroy')
205 3
            ->setEncodeCallable('\session_encode')
206 3
            ->setGcCallable('\session_gc')
207 3
            ->setGetCookieParamsCallable('\session_get_cookie_params')
208 3
            ->setIdCallable('\session_id')
209 3
            ->setCacheExpireCallable('\session_cache_expire');
210
    }
211
212
    /**
213
     * @inheritdoc
214
     */
215 1
    public function getRetrieveCallable(): callable
216
    {
217 1
        return $this->retrieveCallable;
218
    }
219
220
    /**
221
     * @inheritdoc
222
     */
223 3
    public function setRetrieveCallable(callable $callable): SessionFunctionsInterface
224
    {
225 3
        $this->retrieveCallable = $callable;
226
227 3
        return $this;
228
    }
229
230
    /**
231
     * @inheritdoc
232
     */
233 1
    public function getPutCallable(): callable
234
    {
235 1
        return $this->putCallable;
236
    }
237
238
    /**
239
     * @inheritdoc
240
     */
241 3
    public function setPutCallable(callable $callable): SessionFunctionsInterface
242
    {
243 3
        $this->putCallable = $callable;
244
245 3
        return $this;
246
    }
247
248
    /**
249
     * @inheritdoc
250
     */
251 1
    public function getHasCallable(): callable
252
    {
253 1
        return $this->hasCallable;
254
    }
255
256
    /**
257
     * @inheritdoc
258
     */
259 3
    public function setHasCallable(callable $callable): SessionFunctionsInterface
260
    {
261 3
        $this->hasCallable = $callable;
262
263 3
        return $this;
264
    }
265
266
    /**
267
     * @inheritdoc
268
     */
269 1
    public function getDeleteCallable(): callable
270
    {
271 1
        return $this->deleteCallable;
272
    }
273
274
    /**
275
     * @inheritdoc
276
     */
277 3
    public function setDeleteCallable(callable $callable): SessionFunctionsInterface
278
    {
279 3
        $this->deleteCallable = $callable;
280
281 3
        return $this;
282
    }
283
284
    /**
285
     * @inheritdoc
286
     */
287 1
    public function getIteratorCallable(): callable
288
    {
289 1
        return $this->iteratorCallable;
290
    }
291
292
    /**
293
     * @inheritdoc
294
     */
295 3
    public function setIteratorCallable(callable $callable): SessionFunctionsInterface
296
    {
297 3
        $this->iteratorCallable = $callable;
298
299 3
        return $this;
300
    }
301
302
    /**
303
     * @inheritdoc
304
     */
305 1
    public function getAbortCallable(): callable
306
    {
307 1
        return $this->abortCallable;
308
    }
309
310
    /**
311
     * @inheritdoc
312
     */
313 3
    public function setAbortCallable(callable $callable): SessionFunctionsInterface
314
    {
315 3
        $this->abortCallable = $callable;
316
317 3
        return $this;
318
    }
319
320
    /**
321
     * @inheritdoc
322
     */
323 1
    public function getCacheExpireCallable(): callable
324
    {
325 1
        return $this->cacheExpireCallable;
326
    }
327
328
    /**
329
     * @inheritdoc
330
     */
331 3
    public function setCacheExpireCallable(callable $callable): SessionFunctionsInterface
332
    {
333 3
        $this->cacheExpireCallable = $callable;
334
335 3
        return $this;
336
    }
337
338
    /**
339
     * @inheritdoc
340
     */
341 1
    public function getCacheLimiterCallable(): callable
342
    {
343 1
        return $this->cacheLimiterCallable;
344
    }
345
346
    /**
347
     * @inheritdoc
348
     */
349 3
    public function setCacheLimiterCallable(callable $callable): SessionFunctionsInterface
350
    {
351 3
        $this->cacheLimiterCallable = $callable;
352
353 3
        return $this;
354
    }
355
356
    /**
357
     * @inheritdoc
358
     */
359 1
    public function getCreateIdCallable(): callable
360
    {
361 1
        return $this->createIdCallable;
362
    }
363
364
    /**
365
     * @inheritdoc
366
     */
367 3
    public function setCreateIdCallable(callable $callable): SessionFunctionsInterface
368
    {
369 3
        $this->createIdCallable = $callable;
370
371 3
        return $this;
372
    }
373
374
    /**
375
     * @inheritdoc
376
     */
377 1
    public function getDecodeCallable(): callable
378
    {
379 1
        return $this->decodeCallable;
380
    }
381
382
    /**
383
     * @inheritdoc
384
     */
385 3
    public function setDecodeCallable(callable $callable): SessionFunctionsInterface
386
    {
387 3
        $this->decodeCallable = $callable;
388
389 3
        return $this;
390
    }
391
392
    /**
393
     * @inheritdoc
394
     */
395 1
    public function getDestroyCallable(): callable
396
    {
397 1
        return $this->destroyCallable;
398
    }
399
400
    /**
401
     * @inheritdoc
402
     */
403 3
    public function setDestroyCallable(callable $callable): SessionFunctionsInterface
404
    {
405 3
        $this->destroyCallable = $callable;
406
407 3
        return $this;
408
    }
409
410
    /**
411
     * @inheritdoc
412
     */
413 1
    public function getEncodeCallable(): callable
414
    {
415 1
        return $this->encodeCallable;
416
    }
417
418
    /**
419
     * @inheritdoc
420
     */
421 3
    public function setEncodeCallable(callable $callable): SessionFunctionsInterface
422
    {
423 3
        $this->encodeCallable = $callable;
424
425 3
        return $this;
426
    }
427
428
    /**
429
     * @inheritdoc
430
     */
431 1
    public function getGcCallable(): callable
432
    {
433 1
        return $this->gcCallable;
434
    }
435
436
    /**
437
     * @inheritdoc
438
     */
439 3
    public function setGcCallable(callable $callable): SessionFunctionsInterface
440
    {
441 3
        $this->gcCallable = $callable;
442
443 3
        return $this;
444
    }
445
446
    /**
447
     * @inheritdoc
448
     */
449 1
    public function getGetCookieParamsCallable(): callable
450
    {
451 1
        return $this->getCookieParamsCallable;
452
    }
453
454
    /**
455
     * @inheritdoc
456
     */
457 3
    public function setGetCookieParamsCallable(callable $callable): SessionFunctionsInterface
458
    {
459 3
        $this->getCookieParamsCallable = $callable;
460
461 3
        return $this;
462
    }
463
464
    /**
465
     * @inheritdoc
466
     */
467 1
    public function getIdCallable(): callable
468
    {
469 1
        return $this->idCallable;
470
    }
471
472
    /**
473
     * @inheritdoc
474
     */
475 3
    public function setIdCallable(callable $callable): SessionFunctionsInterface
476
    {
477 3
        $this->idCallable = $callable;
478
479 3
        return $this;
480
    }
481
482
    /**
483
     * @inheritdoc
484
     */
485 1
    public function getModuleNameCallable(): callable
486
    {
487 1
        return $this->moduleNameCallable;
488
    }
489
490
    /**
491
     * @inheritdoc
492
     */
493 3
    public function setModuleNameCallable(callable $callable): SessionFunctionsInterface
494
    {
495 3
        $this->moduleNameCallable = $callable;
496
497 3
        return $this;
498
    }
499
500
    /**
501
     * @inheritdoc
502
     */
503 1
    public function getNameCallable(): callable
504
    {
505 1
        return $this->nameCallable;
506
    }
507
508
    /**
509
     * @inheritdoc
510
     */
511 3
    public function setNameCallable(callable $callable): SessionFunctionsInterface
512
    {
513 3
        $this->nameCallable = $callable;
514
515 3
        return $this;
516
    }
517
518
    /**
519
     * @inheritdoc
520
     */
521 1
    public function getRegenerateIdCallable(): callable
522
    {
523 1
        return $this->regenerateIdCallable;
524
    }
525
526
    /**
527
     * @inheritdoc
528
     */
529 3
    public function setRegenerateIdCallable(callable $callable): SessionFunctionsInterface
530
    {
531 3
        $this->regenerateIdCallable = $callable;
532
533 3
        return $this;
534
    }
535
536
    /**
537
     * @inheritdoc
538
     */
539 1
    public function getRegisterShutdownCallable(): callable
540
    {
541 1
        return $this->registerShutdownCallable;
542
    }
543
544
    /**
545
     * @inheritdoc
546
     */
547 3
    public function setRegisterShutdownCallable(callable $callable): SessionFunctionsInterface
548
    {
549 3
        $this->registerShutdownCallable = $callable;
550
551 3
        return $this;
552
    }
553
554
    /**
555
     * @inheritdoc
556
     */
557 1
    public function getResetCallable(): callable
558
    {
559 1
        return $this->resetCallable;
560
    }
561
562
    /**
563
     * @inheritdoc
564
     */
565 3
    public function setResetCallable(callable $callable): SessionFunctionsInterface
566
    {
567 3
        $this->resetCallable = $callable;
568
569 3
        return $this;
570
    }
571
572
    /**
573
     * @inheritdoc
574
     */
575 1
    public function getSavePathCallable(): callable
576
    {
577 1
        return $this->savePathCallable;
578
    }
579
580
    /**
581
     * @inheritdoc
582
     */
583 3
    public function setSavePathCallable(callable $callable): SessionFunctionsInterface
584
    {
585 3
        $this->savePathCallable = $callable;
586
587 3
        return $this;
588
    }
589
590
    /**
591
     * @inheritdoc
592
     */
593 1
    public function getSetCookieParamsCallable(): callable
594
    {
595 1
        return $this->setCookieParamsCallable;
596
    }
597
598
    /**
599
     * @inheritdoc
600
     */
601 3
    public function setSetCookieParamsCallable(callable $callable): SessionFunctionsInterface
602
    {
603 3
        $this->setCookieParamsCallable = $callable;
604
605 3
        return $this;
606
    }
607
608
    /**
609
     * @inheritdoc
610
     */
611 1
    public function getSetSaveHandlerCallable(): callable
612
    {
613 1
        return $this->setSaveHandlerCallable;
614
    }
615
616
    /**
617
     * @inheritdoc
618
     */
619 3
    public function setSetSaveHandlerCallable(callable $callable): SessionFunctionsInterface
620
    {
621 3
        $this->setSaveHandlerCallable = $callable;
622
623 3
        return $this;
624
    }
625
626
    /**
627
     * @inheritdoc
628
     */
629 2
    public function getStartCallable(): callable
630
    {
631 2
        return $this->startCallable;
632
    }
633
634
    /**
635
     * @inheritdoc
636
     */
637 3
    public function setStartCallable(callable $callable): SessionFunctionsInterface
638
    {
639 3
        $this->startCallable = $callable;
640
641 3
        return $this;
642
    }
643
644
    /**
645
     * @inheritdoc
646
     */
647 1
    public function getStatusCallable(): callable
648
    {
649 1
        return $this->statusCallable;
650
    }
651
652
    /**
653
     * @inheritdoc
654
     */
655 3
    public function setStatusCallable(callable $callable): SessionFunctionsInterface
656
    {
657 3
        $this->statusCallable = $callable;
658
659 3
        return $this;
660
    }
661
662
    /**
663
     * @inheritdoc
664
     */
665 1
    public function getUnsetCallable(): callable
666
    {
667 1
        return $this->unsetCallable;
668
    }
669
670
    /**
671
     * @inheritdoc
672
     */
673 3
    public function setUnsetCallable(callable $callable): SessionFunctionsInterface
674
    {
675 3
        $this->unsetCallable = $callable;
676
677 3
        return $this;
678
    }
679
680
    /**
681
     * @inheritdoc
682
     */
683 2
    public function getWriteCloseCallable(): callable
684
    {
685 2
        return $this->writeCloseCallable;
686
    }
687
688
    /**
689
     * @inheritdoc
690
     */
691 3
    public function setWriteCloseCallable(callable $callable): SessionFunctionsInterface
692
    {
693 3
        $this->writeCloseCallable = $callable;
694
695 3
        return $this;
696
    }
697
}
698