-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAutoloader.php
89 lines (80 loc) · 2.91 KB
/
Autoloader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Amarkal;
/**
* Autoloads Amarkal classes
*
* To use the autolaoder, simply require this file as a part of your
* bootstrap process.
*/
class Autoloader
{
/**
* Initiate the autoloader
*/
public static function init()
{
Autoloader::register_classes();
\add_action( 'admin_enqueue_scripts', array( __CLASS__, 'register_assets' ) );
}
/**
* Register the class autoloader for Amarkal classes
*/
private static function register_classes()
{
spl_autoload_register(array(__CLASS__, 'autoload'));
}
/**
* Loads the given class or interface
*
* @param string $class The name of the class
* @return null|boolean True/false if class was loaded
*/
public static function autoload( $class )
{
// Verify that the base namespace is Amarkal
if (0 !== strpos($class, __NAMESPACE__)) {
return;
}
// UI classes
if( strpos( $class, "Amarkal\UI\Components" ) === 0 )
{
$class .= "\controller";
}
// Widget UI classes
if( strpos( $class, "Amarkal\Extensions\WordPress\Widget\UI" ) === 0 )
{
$class .= "\controller";
}
// Options UI classes
if( strpos( $class, "Amarkal\Extensions\WordPress\Options\UI" ) === 0 )
{
$class .= "\controller";
}
$fileName = dirname(__FILE__).str_replace(array(__NAMESPACE__, '\\'), array('',DIRECTORY_SEPARATOR), $class).'.php';
if ( is_file( $fileName ) ) {
require $fileName;
return true;
}
else return false;
}
/**
* Register Amarkal Scripts and Stylesheets
*/
static function register_assets()
{
\wp_enqueue_script( 'jquery' );
\wp_enqueue_script( 'jquery-ui' );
\wp_enqueue_script( 'jquery-ui-datepicker' );
\wp_enqueue_script( 'jquery-ui-spinner' );
\wp_enqueue_script( 'jquery-ui-slider' );
\wp_enqueue_script( 'jquery-ui-resizable' );
\wp_enqueue_script( 'wp-color-picker' );
\wp_enqueue_script( 'amarkal', AMARKAL_ASSETS_URL.'js/amarkal.min.js', array('jquery'), AMARKAL_VERSION, true );
\wp_enqueue_script( 'select2', AMARKAL_ASSETS_URL.'js/select2.min.js', array('jquery'), '4.0.3', true );
\wp_enqueue_script( 'ace-editor', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js', array(), '1.2.6', true );
\wp_enqueue_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', array(), '4.7.0' );
\wp_enqueue_style( 'amarkal', AMARKAL_ASSETS_URL.'css/amarkal.min.css', array('wp-color-picker'), AMARKAL_VERSION );
\wp_enqueue_style( 'select2', AMARKAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.3' );
}
}
Autoloader::init();