Skip to content

Commit

Permalink
create HTML interface to show samples
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfs7 committed Aug 3, 2014
1 parent 30f6fe6 commit 931bc61
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
25 changes: 25 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "gabrielfs7/php-design-patterns",
"description": "Exemplos de Design Patterns em PHP",
"license": "MIT",
"authors": [
{
"name": "Gabriel Felipe Soares",
"email": "gabrielfs7@gmail.com"
}
],
"require": {
"php": ">=5.5"
},
"require-dev" : {
"phpunit/phpunit" : "4.0.x",
"squizlabs/php_codesniffer" : "*",
"phpmd/phpmd" : "*",
"symfony/http-foundation": "dev-master"
},
"autoload": {
"psr-0": {
"GSoares\\RAP\\": "src/"
}
}
}
116 changes: 116 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<!DOCTYPE html>
<html>
<head>
<title>Design Patterns - PHP</title>
<meta content="text/html" charset="UTF-8"/>
<style>
a {
color: #CCC;
text-decoration: none;
}

h1 {
font-size: 45px;
margin: 0 auto;
text-align: center;
}

h2 {
font-size: 25px;
}

body {
font-family: monospace;
font-size: 15px;
padding: 20px 20px 20px 20px;
background: rgba(36, 37, 35, 0.97);
color: #FFF;
}

.coll1 {
float: left;
margin-right: 5%;
width: 20%;
}

.coll1 ul {
padding: 15px;
background: #000;
list-style: none;
}

.coll1 ul li {
list-style: none;
}

.coll2 {
float: left; width: 75%;
}

.sample
{
border: 1px solid #CCC;
background: #EAEAEA;
padding: 20px;
background: #000;
font-size: 40px;
}
</style>
</head>
<body>
<?php
function handleDir($path)
{
$handle = opendir($path);

while (false !== ($file = readdir($handle))) {
if (!in_array($file, ["..", '.', 'cgi-bin', '.DS_Store', 'README.md'])) {
yield $file;
}
}

closedir($handle);
}

$dir = realpath(__DIR__ . '/../src/GSoares/DesignPatterns');
?>
<h1>PHP - Design Patters</h1>

<div class="coll1">
<h2>Menu</h2>
<?php
foreach (handleDir($dir) as $inDir) {
echo "<li>$inDir</li>";
echo "<ul>";

foreach (handleDir($dir . '/' . $inDir) as $inSubDir) {
echo "<li><a href=\"?pattern=$inSubDir&group=$inDir\">$inSubDir</a></li>";
}

echo "</ul>";
}
?>
</div>
<div class="coll2">
<h2>Sample</h2>
<div class="sample">
<?php
if (isset($_GET['pattern']) && isset($_GET['group'])) {
$function = 'GSoares\DesignPatterns\\' . $_GET['group'] . '\\' . $_GET['pattern'] . '\run' . $_GET['pattern'];

if (file_exists($sampleFile = $dir . '/' . $_GET['group'] . '/' . $_GET['pattern'] . '/Sample.php')) {
include $sampleFile;
}

if (function_exists($function)) {
$function();
} else {
echo 'Exemplo não implementado ainda... :( <br/><br/>';
echo 'Implemente a função <em>"' . $function . '()"</em> em:<br/><br/><em>"' . $sampleFile . '"</em>';
}
}
?>
</div>
</div>
</body>
</html>
12 changes: 12 additions & 0 deletions src/GSoares/DesignPatterns/Structural/Bridge/Sample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace GSoares\DesignPatterns\Structural\Bridge;

abstract class sdasdsadasdsdsa
{

}

function runBridge()
{
echo "Bridge Sample...";
}

0 comments on commit 931bc61

Please sign in to comment.