1: <?php
2:
3: /**
4: * Admin class that handle admin view rendering.
5: */
6: final class Papi_Admin_View {
7:
8: /**
9: * Path to view dir.
10: *
11: * @var string
12: */
13: private $path = '';
14:
15: /**
16: * The constructor.
17: *
18: * @param string $path
19: */
20: public function __construct( $path = '' ) {
21: $this->path = empty( $path ) ?
22: PAPI_PLUGIN_DIR . '/admin/views/' : $path;
23: }
24:
25: /**
26: * Check if file exists.
27: *
28: * @param string $file
29: *
30: * @return bool
31: */
32: public function exists( $file ) {
33: return file_exists( $this->file( $file ) );
34: }
35:
36: /**
37: * Render file.
38: *
39: * @param string $file
40: *
41: * @return string
42: */
43: public function render( $file ) {
44: if ( ! empty( $file ) && $this->exists( $file ) ) {
45: require $this->file( $file );
46: }
47: }
48:
49: /**
50: * Get full path to file with php exstention.
51: *
52: * @param string $file
53: *
54: * @return string
55: */
56: private function file( $file ) {
57: return $this->path . $file . '.php';
58: }
59: }
60: