PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / props-dic / scripts / example-pimple.php

example-pimple.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/mrclay/props-dic/scripts/example-pimple.php

76 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Example of Props\Pimple based on official Pimple docs
4 */
5
6 namespace {
7 require __DIR__ . '/../vendor/autoload.php';
8 }
9
10 namespace PropsExample {
11
12 class SessionStorage {
13 public function __construct($cookieName) { $this->cookieName = $cookieName; }
14 }
15 class Session {
16 public function __construct($storage) { $this->storage = $storage; }
17 }
18 class Zend_Mail {
19 public function setFrom($from) { $this->from = $from; }
20 }
21
22 /**
23 * @property-read string $cookie_name
24 * @property-read string $session_storage_class
25 * @property-read Session $session
26 * @property-read \Closure $random
27 * @property-read Zend_Mail $mail
28 */
29 class MyContainer2 extends \Props\Pimple {
30 public function __construct() {
31 parent::__construct();
32
33 $this->cookie_name = 'SESSION_ID';
34
35 $this->session_storage_class = 'PropsExample\\SessionStorage';
36
37 $this->session_storage = function (MyContainer2 $c) {
38 $class = $c->session_storage_class;
39 return new $class($c->cookie_name);
40 };
41
42 $this->session = $this->factory(function (MyContainer2 $c) {
43 return new Session($c->session_storage);
44 });
45
46 $this->random = $this->protect(function () { return rand(); });
47
48 $this->mail = function (MyContainer2 $c) {
49 return new Zend_Mail();
50 };
51
52 $this->{'mail.default_from'} = '[email protected]';
53
54 $this->extend('mail', function($mail, MyContainer2 $c) {
55 $mail->setFrom($c->{'mail.default_from'});
56 return $mail;
57 });
58 }
59 }
60
61 $c = new MyContainer2;
62
63 $r1 = $c->random;
64 $r2 = $c->random;
65
66 echo (int)($r1 === $r2) . "<br>";
67
68 echo $r1() . "<br>";
69
70 echo get_class($c->raw('session')) . '<br>';
71
72 echo var_export($c->session, true) . '<br>';
73
74 echo var_export($c->mail, true) . '<br>';
75 }
76