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
<?php
/**
* Admin class that handle admin view rendering.
*/
final class Papi_Admin_View {
/**
* Path to view dir.
*
* @var string
*/
private $path = '';
/**
* The constructor.
*
* @param string $path
*/
public function __construct( $path = '' ) {
$this->path = empty( $path ) ? PAPI_PLUGIN_DIR . '/admin/views/' : $path;
}
/**
* Check if file exists.
*
* @param string $file
*
* @return bool
*/
public function exists( $file ) {
return file_exists( $this->file( $file ) );
}
/**
* Render file.
*
* @param string $file
*
* @return string
*/
public function render( $file ) {
if ( ! empty( $file ) && $this->exists( $file ) ) {
require $this->file( $file );
}
}
/**
* Get full path to file with php exstention.
*
* @param string $file
*
* @return string
*/
private function file( $file ) {
return $this->path . $file . '.php';
}
}