Skip to content

Commit

Permalink
Rename Template class to Embed
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Canga committed Nov 25, 2018
1 parent 0ade53e commit bd5c650
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
14 changes: 5 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@
require(_APP_ . '/src/Cache.php');
require(_APP_ . '/src/UrlParser.php');
require(_APP_ . '/src/RequestFile.php');
require(_APP_ . '/src/Template.php');
require(_APP_ . '/src/Embed.php');
require(_APP_ . '/src/View.php');

$request_file = UrlParser::fromCurrentUrl()->getRequestFile();

$cache = Cache::fromRequestFIle($request_file);

if (! $cache->exists()) {
$template = new Template($request_file);
$template = new Embed($request_file);

$view = new View('embed', $template);

$content = $view->parse();

$cache->save($content);
$embed = $template->get();
} else {
$content = $cache->get();
$embed = $cache->get();
}

echo $content;
echo $embed;
8 changes: 7 additions & 1 deletion src/Template.php → src/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace gist_it_php;

class Template
class Embed
{

/**
Expand Down Expand Up @@ -32,6 +32,12 @@ public function getMeta():string
return $view->parse();
}

public function get(): string {
$view = new View('embed', $this);

return $view->parse();
}

public function getSource():string
{

Expand Down
9 changes: 5 additions & 4 deletions src/UrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
class UrlParser
{

private const TEST_DOMAIN = 'https://trasweb.net';

/**
Expand Down Expand Up @@ -41,21 +42,21 @@ public function __construct(string $url)

private function sanitizeUrl(string $url):string
{

$url = \parse_url($url, PHP_URL_PATH);
$url = \strip_tags($url);


$is_valid_url = filter_var(self::TEST_DOMAIN. $url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED);
if (!$is_valid_url) {
$is_valid_url = filter_var(self::TEST_DOMAIN . $url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED);
if (! $is_valid_url) {
$this->urlIsNotValid();
}


return $url;
}

private function urlIsNotValid()
{

throw new \Exception("Url is not valid");
}

Expand Down
4 changes: 2 additions & 2 deletions src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class View
private $content;

/**
* @var Template
* @var Embed
*/
private $template;

public function __construct(string $view_name, Template $template)
public function __construct(string $view_name, Embed $template)
{

$this->template = $template;
Expand Down

0 comments on commit bd5c650

Please sign in to comment.