Skip to content

Commit

Permalink
Merge pull request #192 from kivudesign/app_view_module
Browse files Browse the repository at this point in the history
App view module
  • Loading branch information
bim-g authored Sep 2, 2024
2 parents 8ca4506 + e4ee9d0 commit f4e3e2f
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 87 deletions.
2 changes: 1 addition & 1 deletion router/route.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Wepesi\Controller\indexController;
use Wepesi\Core\View;
use Wepesi\Core\Views\View;
use Wepesi\Middleware\Validation\exampleValidation;

$router = $app->router();
Expand Down
7 changes: 5 additions & 2 deletions src/Core/Controller.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?php
/*
* Copyright (c) 2023. wepesi dev framework
* Copyright (c) 2023-2024. Wepesi Dev Framework
*/

namespace Wepesi\Core;

use Wepesi\Core\Views\Provider\Contract\ViewsContract;
use Wepesi\Core\Views\View;

/**
*
*/
Expand All @@ -13,7 +16,7 @@ abstract class Controller
/**
* @var View
*/
protected View $view;
protected ViewsContract $view;

/**
*
Expand Down
11 changes: 0 additions & 11 deletions src/Core/CoreException/RoutingException.php

This file was deleted.

9 changes: 2 additions & 7 deletions src/Core/Escape.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ public static function randomString(int $length = 8): string
* @param string $link
* @return string
*/
public static function addSlaches(string $link): string
public static function addSlashes(string $link): string
{
$sub_string = substr($link, 0, 1);
$new_link = substr($link, 1);
if ($sub_string == '/') {
$link = substr(self::addSlaches($new_link), 1);
}
return $link == '' ? $link : '/' . $link;
return "/" . trim($link,"/");
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/Core/Exceptions/RoutingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/*
* Copyright (c) 2023. wepesi dev framework
*/

namespace Wepesi\Core\Exceptions;

/**
*
*/
class RoutingException extends WepesiException
{

}
11 changes: 11 additions & 0 deletions src/Core/Exceptions/WepesiException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/*
* Copyright (c) 2024. Wepesi Dev Framework
*/

namespace Wepesi\Core\Exceptions;

class WepesiException extends \Exception
{

}
2 changes: 1 addition & 1 deletion src/Core/Http/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static function to($location = null)
exit();
} else {
$webroot = substr(WEB_ROOT, 0, -1);
$link = Escape::addSlaches($location);
$link = Escape::addSlashes($location);
$location = $link == '' ? WEB_ROOT : $webroot . $link;
header('Location:' . $location);
exit();
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Wepesi\Core\Routing;

use Wepesi\Core\Application;
use Wepesi\Core\CoreException\RoutingException;
use Wepesi\Core\Exceptions\RoutingException;
use Wepesi\Core\Http\Response;
use Wepesi\Core\Routing\Traits\routeBuilder;

Expand Down
40 changes: 40 additions & 0 deletions src/Core/Views/Provider/Contract/ViewsContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/*
* Copyright (c) 2024. Wepesi Dev Framework
*/

namespace Wepesi\Core\Views\Provider\Contract;

use Wepesi\Core\MetaData;

/**
*
*/
interface ViewsContract
{
/**
* Setup new folder location for layout template
* @param string $folder_name
* @return mixed
*/
public function setFolder(string $folder_name);

/**
* render html content
* @param string $view
* @return mixed
*/
public function display(string $view);

/**
* @param string $variable
* @param mixed $value
* @return mixed
*/
public function assign(string $variable, $value);

/**
* @return array
*/
public function getAssignData(): array;
}
55 changes: 55 additions & 0 deletions src/Core/Views/Provider/ViewBuilderProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
* Copyright (c) 2024. Wepesi Dev Framework
*/

namespace Wepesi\Core\Views\Provider;

use Wepesi\Core\Escape;

class ViewBuilderProvider implements Contract\ViewsContract
{
protected array $data = [];

/**
* @var string
*/
protected string $folder_name = '';

/**
* @param string $folder_name
* @return void
*/
public function setFolder(string $folder_name)
{
$this->folder_name = Escape::addSlashes($folder_name);
}

/**
* @inheritDoc
*/
public function display(string $view)
{
// TODO: Implement display() method.
}

/**
* assign variables data to be displayed on file_page
*
* @param string $variable
* @param $value
*/
public function assign(string $variable, $value)
{
$this->data[$variable] = $value;
}

/**
* List all data assigned before being displayed
* @return array
*/
public function getAssignData(): array
{
return $this->data;
}
}
Loading

0 comments on commit f4e3e2f

Please sign in to comment.