public function handle()
 {
     $view = View::make(Config::get('app.errorsPages.404', '404'))->with('pageTitle', 'Not found');
     $response = new Response();
     $response->setStatusCode(404);
     $response->setContent($view->render());
     return $response;
 }
Exemplo n.º 2
0
 /**
  *
  * The Constructor sets the dbConfigs and inits the DataBase
  *
  * @return void
  */
 public function __construct()
 {
     //set probertyVariables
     $host = Config::dbConfig()['host'];
     $username = Config::dbConfig()['username'];
     $password = Config::dbConfig()['password'];
     $databases = Config::dbConfig()['databases'];
     //init the DataBase
     self::init($host, $username, $password, $databases);
 }
Exemplo n.º 3
0
 /**
  *
  * The generateFunction generates an Controller in srcFolder
  *
  * @return void
  */
 public static function generate()
 {
     //get the Name of the SourceFolder
     echo "First you need to give the name of the SourceFolder you want to generate.\n";
     echo "The SourceFolder name: ";
     $line = trim(fgets(STDIN));
     $dir = 'src/' . $line;
     //controll when the Folder already exist
     while (is_dir($dir)) {
         echo "This SourceFolder already exist! Do you want to overwrite this File?\npress y for yes and another for no:";
         $answer = trim(fgets(STDIN));
         if ($answer === 'y') {
             Folder::delete($dir);
             break;
         } else {
             echo "The SourceFolder name: ";
             $line = trim(fgets(STDIN));
             $dir = 'src/' . $line;
         }
     }
     //create dirs
     mkdir($dir);
     mkdir($dir . '/Controller');
     mkdir($dir . '/Entity');
     mkdir($dir . '/Resources');
     mkdir($dir . '/Resources/views');
     //set controllerValue
     $controllerValue = "<?php \n\n";
     $controllerValue .= 'namespace ' . $line . "\\Controller;\n\n";
     $controllerValue .= 'use Kernel\\Controller;' . "\n\n";
     $controllerValue .= 'class ' . $line . "Controller extends Controller\n{\n";
     $controllerValue .= '	public function ' . $line . '()' . "\n";
     $controllerValue .= "\t{\n";
     $controllerValue .= '		return $this->render("' . $line . ':default.html");' . "\n";
     $controllerValue .= "\t}\n";
     $controllerValue .= "}\n";
     //generate Controller
     $controller = fopen($dir . '/Controller/' . $line . 'Controller.php', "w") or die("Unable to open file!\n");
     fwrite($controller, '');
     fwrite($controller, trim($controllerValue));
     fclose($controller);
     //generate template
     $templateValue = "<div>hello</div>";
     $template = fopen($dir . '/Resources/views/default.html', "w") or die("Unable to open file!\n");
     fwrite($template, '');
     fwrite($template, trim($templateValue));
     fclose($template);
     //amend srcInit
     if (!array_key_exists($line, Config::srcInit())) {
         $content = $line . ': ' . $line;
         file_put_contents('Config/SrcInit.yml', "\n" . $content, FILE_APPEND);
     }
 }
Exemplo n.º 4
0
 /**
  *
  * The loginMethod check if logged or login when the datas are right
  * 
  * @return boolean
  */
 public function login()
 {
     $request = new Request();
     $em = new EntityManager();
     $securityConfig = Config::securityConfig();
     $identificator = $securityConfig['identificator'];
     $passwordKey = $securityConfig['passwordKey'];
     $entityShortcut = $securityConfig['entityShortcut'];
     //get the dbConnection
     $em->getConnection();
     $entity = $em->getEntity($entityShortcut);
     //if the authentificationSession is empty then check then loginRequest
     if (empty($request->session['userid'])) {
         //check if the authentificationPostParameters aren't empty then check if the datas are valid then return
         if (!empty($request->post[$identificator]) && !empty($request->post[$passwordKey])) {
             //set the identificatorValue and the passwordValue
             $identificatorValue = $request->post[$identificator];
             $passwordValue = $request->post[$passwordKey];
             //salt and hash the password
             $salt1 = "74930slei93kdie9i3kdie93kdie9kdie93kdie93kdie93kdie9kei309ioögeut3fhsoöiutusü0emiß+m0gü8wvtpomuv,ß+,xiü.uim vüiri3mß";
             $salt2 = "dsajkflsafis543908530ljfksld4sdf34453ß0klsdjflkdslkjflksjflkdsjflkjdslkfjdslkfjlkdsjflkdsjfldsjlfdslkflsdjflkdsjlfdslkjfldskjflkjdslfjdslklsl";
             $password = hash('sha512', $salt1 . $passwordValue . $salt2);
             //get identificatorValue
             $em->find($identificator, $identificatorValue);
             $identificatorValue = call_user_func(array($entity, 'get' . ucfirst($identificator)));
             //if identificatorValue isn't empty and if the password is right return true else set an error number
             if (!empty($identificatorValue) && $entity->getPassword() === $password) {
                 $this->userObject = $entity;
                 $request->setSession('userid', $entity->getID());
                 return true;
             } else {
                 //the identificatior is empty or password
                 $this->errorNumber = 1;
             }
         } else {
             //one of the postParameters is/are empty
             $this->errorNumber = 2;
         }
     } else {
         //set the userObject
         $this->userObject = $entity;
         $em->find('id', $request->session['userid']);
         return true;
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  *
  * The handleRouting function reads the routingPattern and handles the routingVariables, 
  * checks if required that the User is logged in
  *
  * @param string $uri
  *
  * @return Controller, string
  */
 public function handleRouting($uri)
 {
     $routing = Config::routing();
     $specialRouting = array('404');
     //check if uri fits in a routing pattern
     foreach ($routing as $key => $value) {
         if (!in_array($key, $specialRouting)) {
             //check if the srcFolder from the Routing is initialized
             if (array_key_exists($value['srcFolder'], Config::SrcInit())) {
                 //check if the pattern equals the requested URI
                 $srcFolder = Config::SrcInit()[$value['srcFolder']];
                 $dir = ltrim($srcFolder, '/');
                 if (is_dir('../src/' . $srcFolder)) {
                     if ($value['pattern'] === $uri) {
                         return $this->callController($dir, $value);
                     } else {
                         //remove the first and last '/' in pattern and uri
                         $pattern = trim($value['pattern'], '/');
                         $uri = trim($uri, '/');
                         //explode pattern and uri by '/'
                         $patternParts = explode('/', $pattern);
                         $uriParts = explode('/', $uri);
                         //count the array to check if they have the same size
                         $patternPartsCount = count($patternParts);
                         $uriPartsCount = count($uriParts);
                         //check if the patternParts equals the uriParts
                         if ($patternPartsCount === $uriPartsCount) {
                             //handle the patternParts
                             for ($i = 0; $i < $patternPartsCount; $i++) {
                                 //identify patternVariables an store in Pattern Array
                                 $this->handlePatternVariables($value, $uri);
                                 //at the last continuous call the Controller
                                 if ($i === $patternPartsCount - 1) {
                                     if ($patternParts[0] === $uriParts[0]) {
                                         if ($ajax) {
                                         }
                                         if (isset($value['ajax'])) {
                                             if ($value['ajax']) {
                                                 if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
                                                     return $this->callController($dir, $value);
                                                 }
                                             }
                                         } else {
                                             return $this->callController($dir, $value);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ('/' . $uri === $_SERVER['PHP_SELF'] || $uri === '') {
         return "root";
     } else {
         if (isset($routing['404'])) {
             if (isset($routing['404']['template'])) {
                 $file = $routing['404']['template'];
                 $exist = file_exists($file);
                 if ($exist) {
                     ob_start();
                     include $file;
                     $output = ob_get_contents();
                     ob_end_clean();
                     return $output;
                 } else {
                     //throw Exception
                     return $file . ' not found';
                 }
             } else {
                 $srcFolder = Config::SrcInit()[$routing['404']['srcFolder']];
                 $dir = ltrim($srcFolder, '/');
                 if (is_dir('../src/' . $srcFolder)) {
                     $dir = ltrim($srcFolder, '/');
                     return $this->callController($dir, $routing['404']);
                 }
             }
         }
         return "Page not found!";
     }
 }
Exemplo n.º 6
0
 /**
  * @param User $user
  * @return null|string
  */
 private static function produceFullUserCategoryDir(User $user)
 {
     $directory = Config::get('app.userUploadDir');
     return !empty($directory) ? $directory . self::produceUserCategoryDir($user) : null;
 }
Exemplo n.º 7
0
 /**
  *
  * The syncMethod syncs the DatabaseTables with the Entitys in srcFolder
  *
  * @return void
  */
 public static function sync()
 {
     //init db
     $db = new db();
     $affected = 0;
     //init variables
     $entityFieldsData = array();
     $dbFieldsData = array();
     $changes = array();
     $new = array();
     $mysqlDataTypeHash = array(1 => 'tinyint', 2 => 'smallint', 3 => 'int', 4 => 'float', 5 => 'double', 7 => 'timestamp', 8 => 'bigint', 9 => 'mediumint', 10 => 'date', 11 => 'time', 12 => 'datetime', 13 => 'year', 16 => 'bit', 252 => 'varchar', 253 => 'varchar', 254 => 'char', 246 => 'decimal');
     //read entitys from initialized srcFolders
     foreach (Config::srcInit() as $srcFolder) {
         //check if there an entityFolder exists in the srcFolder
         if (file_exists('src/' . $srcFolder . '/Entity')) {
             //read all files
             $handle = opendir('src/' . $srcFolder . '/Entity');
             while (false !== ($entityFileName = readdir($handle))) {
                 if ($entityFileName != "." && $entityFileName != "..") {
                     //call entity Object
                     $entityName = rtrim($entityFileName, '.php');
                     $entityObjectNS = '\\src\\' . $srcFolder . '\\Entity\\' . $entityName;
                     $entityObject = new $entityObjectNS();
                     $entityObjectClean = self::getEntityObjectArray($entityObject);
                     //check the validity
                     self::checkEntityValidity($entityObjectClean, $entityObject);
                     //get DatabaseFields Data
                     $entityFieldsData[$entityName] = self::getEntityFieldsData($entityObjectClean, $entityObjectNS);
                     if (self::tableExist($db, $entityName)) {
                         //get EntityFields Data
                         $dbFieldsData[$entityName] = self::getDbFieldsData($db, $entityName, $mysqlDataTypeHash);
                         //add changes
                         $changes[$entityName] = self::getChanges($entityFieldsData[$entityName], $dbFieldsData[$entityName]);
                     } else {
                         $new[$entityName] = $entityFieldsData[$entityName];
                     }
                 }
             }
             closedir($handle);
         }
     }
     $newFields = 0;
     $probertys = 0;
     $deleteFields = 0;
     $newTable = count($new);
     foreach ($changes as $entity) {
         foreach ($entity as $type => $fields) {
             switch ($type) {
                 case 'new':
                     $newFields = $newFields + count($fields);
                     break;
                 case 'proberty':
                     $probertys = $probertys + count($fields);
                     break;
                 case 'delete':
                     $deleteFields = $deleteFields + count($fields);
                     break;
             }
         }
     }
     $affected = $newFields + $probertys + $deleteFields + $newTable;
     self::takeChanges($changes, $new, $db);
     //echo the endMessage
     if ($affected !== 0) {
         echo "The Database was updated successfull with {$affected} affected!\n";
         echo "{$newFields} new Columns!\n";
         echo "{$probertys} changed probertys in Columns!\n";
         echo "{$deleteFields} Columns delete!\n";
         echo "{$newTable} new Tables!\n";
     } else {
         echo "The Database is already up to date!\n";
     }
 }