Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
.idea/
vendor/
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /src/mvc/index.php?route=$1 [L,QSA]
1 change: 1 addition & 0 deletions app/views/article.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ method|upper }} Article with "{{ articleId }}" id action
1 change: 1 addition & 0 deletions app/views/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world!
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"autoload": {
"psr-0": {"mvc": "src/"}
},
"require": {
"symfony/http-foundation": "2.5.6",
"twig/twig": "1.16.2",
"phroute/phroute": "1.4.1"
}
}
174 changes: 174 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

require_once 'vendor/autoload.php';

use mvc\Controllers;
use mvc\tim\Barcelona;
use mvc\tim\RealMadrid;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use mvc\Controller\ArticleController;
use mvc\Controller\IndexController;

use Phroute\RouteCollector;
use Phroute\Dispatcher;

$request = Request::createFromGlobals();

$loader = new Twig_Loader_Filesystem(__DIR__.'/app/views');
$twig = new Twig_Environment($loader);


$articleController = new ArticleController($twig);
$indexController = new IndexController($twig);

$router = new RouteCollector();

$router->get('/', [$indexController,'indexAction']);

$router->get('/articles/{id}', [$articleController,'getArticleAction']);
$router->put('/articles/{id}', [$articleController,'getArticleAction']);
$router->post('/articles/{id}', [$articleController,'getArticleAction']);
$router->delete('/articles/{id}', [$articleController,'getArticleAction']);
$router->get('/articles', [$articleController,'getArticlesAction']);

$dispatcher = new Dispatcher($router);
$response = $dispatcher->dispatch($request->getMethod(), parse_url($request->getPathInfo(), PHP_URL_PATH));

$response->send();



54 changes: 54 additions & 0 deletions src/mvc/Controller/ArticleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace mvc\Controller;

use Symfony\Component\HttpFoundation\Response;

class ArticleController
{
/** @var \Twig_Environment */
protected $twig;
public function __construct(\Twig_Environment $twig)
{
$this->twig = $twig;
}
/**
* @return Response
*/
public function getArticlesAction()
{
return new Response('So many articles here');
}
/**
* @param string $id
* @return Response
*/
public function getArticleAction($id)
{
return new Response($this->twig->render('article.html.twig', ['method' => 'Get', 'articleId' => $id]));
}
/**
* @param string $id
* @return Response
*/
public function putArticleAction($id)
{
return new Response($this->twig->render('article.html.twig', ['method' => 'Put', 'articleId' => $id]));
}
/**
* @param string $id
* @return Response
*/
public function postArticleAction($id)
{
return new Response($this->twig->render('article.html.twig', ['method' => 'Post', 'articleId' => $id]));
}
/**
* @param string $id
* @return Response
*/
public function deleteArticleAction($id)
{
return new Response($this->twig->render('article.html.twig', ['method' => 'Delete', 'articleId' => $id]));
}
}
16 changes: 16 additions & 0 deletions src/mvc/Controller/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace mvc\Controller;

use Symfony\Component\HttpFoundation\Response;

class IndexController
{
/**
* @return Response
*/
public function indexAction()
{
return new Response('Hello World!');
}
}
45 changes: 45 additions & 0 deletions src/mvc/Controllers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Created by PhpStorm.
* User: ivan
* Date: 30.10.14
* Time: 22:32
*/
namespace mvc;

use mvc\Model;
use Symfony\Component\HttpFoundation\Response;

class Controllers
{
public function barcelonaAction()
{

$b = Model::getBarcelonaParametrs();

require 'Views/barcelonaView.php';


$response = new Response();

return $response;

}

public function realAction()
{

$r = Model::getRealParametrs();

require 'Views/realView.php';


$response = new Response();

return $response;

}



}
31 changes: 31 additions & 0 deletions src/mvc/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Created by PhpStorm.
* User: ivan
* Date: 30.10.14
* Time: 22:37
*/
namespace mvc;

use mvc\tim\Barcelona;
use mvc\tim\RealMadrid;

class Model
{
public function getBarcelonaParametrs()
{
$Barcelona = new Barcelona('Luis Enrique', 'Camp Nou', 'Xavier ');

$b['show'] = $Barcelona->show();
return $b;

}
public function getRealParametrs()
{
$Real = new RealMadrid('Carlo Ancelotti','Santiago Bernabeu','Casillas');

$r['show'] = $Real->show();
return $r;

}
}
Loading