PluginProbe
Image SEO – AI-Driven Image SEO Optimizer / trunk
Image SEO – AI-Driven Image SEO Optimizer vtrunk
3.2.16 3.2.15 3.2.13 3.2.14 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 trunk 2.0.9 3.0.0 3.0.1 3.0.2 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 All 71 releases
imageseo / src / Context.php

Context.php in Image SEO – AI-Driven Image SEO Optimizer trunk, at src/Context.php

76 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageSeoWP;
4
5 if (!defined('ABSPATH')) {
6 exit;
7 }
8
9 use ImageSeoWP\Bootstrap;
10
11 /**
12 * Only use for get one context
13 */
14 abstract class Context
15 {
16
17 /**
18 * @static
19 * @since 1.0
20 * @var Bootstrap|null
21 */
22 protected static $context;
23
24 /**
25 * Create context if not exist
26 *
27 * @static
28 * @since 1.0
29 */
30 public static function getContext()
31 {
32 if (null !== self::$context) {
33 return self::$context;
34 }
35
36 self::$context = new Bootstrap();
37
38 self::getClasses(__DIR__ . '/Services', 'services', 'Services\\');
39 self::getClasses(__DIR__ . '/Actions', 'actions', 'Actions\\');
40
41
42
43 return self::$context;
44 }
45
46 /**
47 * @static
48 * @param string $path
49 * @param string $type
50 * @param string $namespace
51 * @return void
52 */
53 public static function getClasses($path, $type, $namespace = '')
54 {
55 $files = array_diff(scandir($path), ['..', '.']);
56 foreach ($files as $filename) {
57 $pathCheck = $path . '/' . $filename;
58 if (is_dir($pathCheck)) {
59 self::getClasses($pathCheck, $type, $namespace . $filename . '\\');
60 continue;
61 }
62
63 $data = '\\ImageSeoWP\\' . $namespace . str_replace('.php', '', $filename);
64
65 switch ($type) {
66 case 'services':
67 self::$context->setService($data);
68 break;
69 case 'actions':
70 self::$context->setAction($data);
71 break;
72 }
73 }
74 }
75 }
76