Browse Source

Add autoloader

표준에 맞추기 위해 노력 중...
master
Hakase 1 year ago
parent
commit
97ce6c1b03
4 changed files with 51 additions and 11 deletions
  1. 1
    1
      .gitignore
  2. 44
    0
      class/osutournament/autoloader.php
  3. 4
    8
      include.php
  4. 2
    2
      test.php

+ 1
- 1
.gitignore View File

@@ -1 +1 @@
1
-.vscode
1
+.vscode

+ 44
- 0
class/osutournament/autoloader.php View File

@@ -0,0 +1,44 @@
1
+<?php
2
+/**
3
+ * @file class/osutournament/autoloader.php
4
+ * @author Hakase (contact@hakase.kr)
5
+ */
6
+    namespace OsuTournament;
7
+    class Autoloader
8
+    {
9
+        /**
10
+         * register Add autoloader class
11
+         */
12
+        public function register()
13
+        {
14
+            spl_autoload_register(array($this, 'load'));
15
+        }
16
+        /**
17
+         * load Load class php file
18
+         * @param  string $class Class name
19
+         * @return bool          True / False
20
+         */
21
+        public function load($class)
22
+        {
23
+            $basedir = dirname(dirname(__DIR__));
24
+            $file = $basedir.'/class/'.strtolower(str_replace("\\", "/", $class)).'.php';
25
+            if ($this->requireFile($basedir.'/class/'.strtolower(str_replace("\\", "/", $class)).'.php'))
26
+                return true;
27
+            else
28
+                return false;
29
+        }
30
+        /**
31
+         * requireFile Require php file
32
+         * @param  string $file File name
33
+         * @return bool         True / False
34
+         */
35
+        protected function requireFile($file)
36
+        {
37
+            if (file_exists($file))
38
+            {
39
+                require $file;
40
+                return true;
41
+            }
42
+            return false;
43
+        }
44
+    }

+ 4
- 8
include.php View File

@@ -3,11 +3,7 @@
3 3
  * @file include.php
4 4
  * @author Hakase (contact@hakase.kr)
5 5
  */
6
-    spl_autoload_register(
7
-        function($classname)
8
-        {
9
-            $file = __DIR__.'/class/'.strtolower(str_replace("\\", "/", $classname)).'.php';
10
-            if (file_exists($file))
11
-                require_once(__DIR__.'/class/'.strtolower(str_replace("\\", "/", $classname)).'.php');
12
-        }
13
-    );
6
+    require_once 'class/osutournament/autoloader.php';
7
+
8
+    $Autoloader = new OsuTournament\Autoloader();
9
+    $Autoloader->register();

+ 2
- 2
test.php View File

@@ -64,6 +64,6 @@
64 64
 
65 65
     $Check->CheckUser('3318', 0, 2, 'https://test.hoto.us/ripple');
66 66
     GetDataTest();
67
-	
67
+
68 68
     $Check->CheckUser('3318', 0, 2);
69
-    GetDataTest();
69
+    GetDataTest();

Loading…
Cancel
Save