Exemple #1
0
 /**
  * Get View Path
  * @param string $name
  * @return bool
  */
 private function getViewPath($name)
 {
     $locations = [''];
     !isset(DfApp::app()->router->controller) ?: ($locations[] = DfApp::app()->router->controller);
     !isset(DfApp::app()->router->action) ?: ($locations[] = DfApp::app()->router->action);
     return $this->findView($locations, $name);
 }
Exemple #2
0
 private function start()
 {
     if (empty($config)) {
         $this->configWrite();
     }
     DfApp::start($this->config, 'test/data');
     $this->assertEquals(DfApp::getPath(), $this->config['app_path']);
     $this->assertEquals(DfApp::getPath(true), $this->config['app_path'] . "/");
 }
 /**
  * @depends DfAppTest::testSetupEx
  */
 public function testShowSources()
 {
     $path = DfApp::getRuntimePath(true) . 'app/controllers/MainController.php';
     $this->checkSources($this->sources($path, true));
     $this->checkSources($this->sources($path, false, 20));
     $this->checkSources($this->sources($path, false, 20, 5));
     $pathNotExist = DfApp::getRuntimePath(true) . 'app/controllers/MainController.php1';
     $this->assertTrue($this->sources($pathNotExist) == "<tbody><td><tr>File not exist</tr></td></tbody>");
 }
Exemple #4
0
 /**
  * Log
  * @param string $error
  * @param $location
  * @param string $type
  * @param string $level
  */
 public function log($error, $location, $type = DfLogger::TYPE_INFO, $level = DfLogger::LEVEL_LOG)
 {
     DfApp::app()->logger->log($this->componentName, $error, $location, $type, $level);
 }
Exemple #5
0
 /**
  * @depends DfAppTest::testSetupEx
  */
 public function testStop()
 {
     $this->assertEquals(true, is_numeric(DfApp::app()->timer->stop()));
     $this->assertEquals(true, is_numeric(DfApp::app()->timer->stop('1')));
 }
Exemple #6
0
            $this->scanStatus = true;
        }
        foreach (array_merge($this->frameworkDirectory, $this->applicationDirectory) as $directory) {
            $path = $directory . "/" . $class . ".php";
            if (file_exists($path)) {
                require $path;
            }
        }
    }
    /**
     * Make array of framework directory
     */
    private function scanFrameworkDirectory()
    {
        $this->scan($this->dir, 'frameworkDirectory');
    }
    private function scan($_directory, $variable)
    {
        foreach (scandir($_directory) as $directory) {
            $directory != "." && $directory != ".." && is_dir($_directory . "/" . $directory) ? array_push($this->{$variable}, realpath($_directory . '/' . $directory)) : "";
        }
    }
    private function scanApplicationDirectory()
    {
        $this->scan((!empty($this->runtimePath) ? $this->runtimePath : dirname($this->dir)) . '/' . 'app', 'applicationDirectory');
    }
}
$DfTestDir = class_exists('DfTests') ? DfTests::$dataDir : '';
$DfBase = new DfBase($DfTestDir);
DfApp::init(realpath(dirname(__FILE__)));
Exemple #7
0
 /**
  * Config Reading
  * @param $config
  */
 private static function configRead($config)
 {
     if (isset($config['app_path'])) {
         static::$appPath = trim($config['app_path'], '/');
     }
     if (isset($config['components'])) {
         if (isset($config['components']['db'])) {
             DfApp::app()->db = new DfDbConnection($config['components']['db']['link'], $config['components']['db']['user'], $config['components']['db']['password']);
         }
     }
     if (isset($config['logger']['path'])) {
         DfApp::app()->logger = new DfLogger($config['logger']['path']);
     } else {
         DfApp::app()->logger = new DfLogger();
     }
     if (isset($config['errors'])) {
         if (isset($config['errors']['display'])) {
             switch ($config['errors']['display']) {
                 case true:
                     ini_set('display_errors', 1);
                     ini_set('display_startup_errors', 1);
                     error_reporting(isset($config['errors']['level']) ? $config['errors']['level'] : -1);
                     break;
                 case false:
                 default:
                     ini_set('display_errors', 0);
                     ini_set('display_startup_errors', 0);
                     error_reporting(0);
                     break;
             }
         }
         if (isset($config['errors']['debug'])) {
             DfErrorHandler::$debug = $config['errors']['debug'];
         }
         if (isset($config['errors']['error_call'])) {
             DfErrorHandler::$errorCall = $config['errors']['error_call'];
         }
     }
     if (isset($config['router']['default'])) {
         if (isset($config['router']['default']['controller'])) {
             DfApp::app()->router->controller = $config['router']['default']['controller'];
         }
         if (isset($config['router']['default']['action'])) {
             DfApp::app()->router->action = $config['router']['default']['action'];
         }
         if (isset($config['router']['default']['id'])) {
             DfApp::app()->router->id = $config['router']['default']['id'];
         }
     }
 }
Exemple #8
0
<?php

/**
 * Daitel Framework
 * Basic Application
 *
 * @author Nikita Fedoseev <*****@*****.**>
 * @link https://github.com/daitel/framework
 * @since 0.2.1
 */
//include framework
if (file_exists("../../framework/DfBase.php")) {
    require_once "../../framework/DfBase.php";
} elseif (file_exists("framework/DfBase.php")) {
    require_once "framework/DfBase.php";
} else {
    die("Unable to include framework");
}
//include config
require_once "app/config/config.php";
//start application
DfApp::start($config);
Exemple #9
0
 /**
  * @depends testLog
  */
 public function testSave()
 {
     DfApp::app()->logger->path = DfTests::$testDir . 'log.txt';
     DfApp::app()->logger->save();
     $this->assertEquals(true, file_exists(DfTests::$testDir . 'log.txt'));
 }
Exemple #10
0
 /**
  * Get instance of DfDbConnection
  * For customization can be overloading in called classes
  * @return DfDbConnection
  */
 public static function getDb()
 {
     return DfApp::app()->db;
 }
Exemple #11
0
 /**
  * execute
  */
 private function execute()
 {
     if (empty(DfApp::app()->getRuntimePath())) {
         throw new DfSetupException("No defined RuntimePath");
     }
     $controllerName = ucwords($this->controller) . 'Controller';
     $actionName = 'action' . ucwords($this->action);
     if (!class_exists($controllerName)) {
         throw new DfNotFoundException("Unable to find controller: {$this->controller}");
     }
     $_controller = new $controllerName();
     if (!method_exists($_controller, $actionName)) {
         throw new DfNotFoundException("Unable to find action: {$this->controller}/{$this->action}");
     }
     call_user_func([$_controller, 'beforeAction']);
     if (!empty($this->id)) {
         call_user_func([$_controller, $actionName], $this->id);
     } else {
         call_user_func([$_controller, $actionName]);
     }
     call_user_func([$_controller, 'afterAction']);
 }
Exemple #12
0
 /**
  * Render Error Page
  * @param DfException $ex
  */
 private static function renderErrorPage($ex)
 {
     if (!empty(self::$errorCall)) {
         DfApp::app()->router->callByArray(self::$errorCall);
     } else {
         self::includePage($ex);
     }
 }
Exemple #13
0
?>
</div>
                                </h4>
                            </div>
                            <div class="panel-body">
                                <table class="table table-borderless table-condensed">
                                    <?php 
DfErrorHandler::showSources($ex->getFile(), false, $ex->getLine());
?>
                                </table>
                            </div>
                        </div>

                        <h3>Application dump</h3>
                        <?php 
var_dump(DfApp::app());
?>

                        <h3>Stack Trace</h3>

                        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                            <?php 
foreach ($ex->getTrace() as $id => $call) {
    ?>
                                <?php 
    if (isset($call['file'])) {
        ?>
                                    <div class="panel panel-default">
                                        <div class="panel-heading" role="tab" id="heading<?php 
        echo $id;
        ?>
Exemple #14
0
<?php

/**
 * Daitel Framework
 * Basic Application Config
 *
 * @author Nikita Fedoseev <*****@*****.**>
 * @link https://github.com/daitel/framework
 * @since 0.2.1
 */
$config = ['name' => 'basic', 'errors' => ['debug' => true, 'error_call' => ['controller' => 'error', 'action' => 'index', 'id' => '']], 'logger' => ['path' => DfApp::getRuntimePath(true) . "app/logs/log.txt"], 'router' => ['default' => ['controller' => 'hello']]];