Commit 61c1d491 authored by lucasdc's avatar lucasdc

Nuevos archivos con autoload

parent 63718270
FROM php:5.6.31-apache
RUN apt-get update && apt-get install -y php5-mysql vim libmcrypt-dev && docker-php-ext-install mysqli pdo pdo_mysql mcrypt
FROM php:7.2-apache
WORKDIR /var/www/html/
COPY composer.* ./
RUN apt-get update && apt-get install -y vim libmcrypt-dev git zip && \
docker-php-ext-install pdo pdo_mysql && \
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
php composer.phar install
\ No newline at end of file
Ejemplo de MVC con PHP y TWIG.
# Ejemplo de MVC con PHP y TWIG
* Clonar.
* Levantar con docker: docker-compose up .
......
<?php
<?php namespace App\Controller;
use App\Model\UserRepository;
use App\View\HomeView;
use App\View\UserView;
class UserController
{
......
<?php
<?php namespace App\Model;
abstract class BaseRepository
{
......@@ -8,7 +8,7 @@ abstract class BaseRepository
$password = getenv('DB_PASSWORD')?: "pass";
$host = getenv('DB_HOST')?: "db";
$db = getenv('DB_NAME')?: "base";
$connection = new PDO("mysql:dbname=$db;host=$host", $username, $password);
$connection = new \PDO("mysql:dbname=$db;host=$host", $username, $password);
return $connection;
}
......
<?php
<?php namespace App\Model;
class User
{
......
<?php
<?php namespace App\Model;
class UserRepository extends BaseRepository
{
public function all()
{
$stmt = $this->execute("select * from usuarios where estado = ?;", ['Confirmado']);
return $stmt->fetchAll(PDO::FETCH_CLASS, "User");
return $stmt->fetchAll(\PDO::FETCH_CLASS, "\App\Model\User");
}
}
<?php
<?php namespace App\View;
class HomeView extends TwigView
{
......
<?php
require_once './lib/twig/twig/lib/Twig/Autoloader.php';
<?php namespace App\View;
abstract class TwigView
{
......@@ -10,9 +8,9 @@ abstract class TwigView
{
if (!isset(self::$twig)) {
Twig_Autoloader::register();
$loader = new Twig_Loader_Filesystem('./templates');
self::$twig = new Twig_Environment($loader);
//Twig_Autoloader::register();
$loader = new \Twig_Loader_Filesystem('./app/templates');
self::$twig = new \Twig_Environment($loader);
// With enabled cache
// self::$twig = new Twig_Environment($loader, array('cache' => '/tmp'));
}
......
<?php
<?php namespace App\View;
class UserView extends TwigView
{
......
{
"name": "Docker-MVC",
"description": "Uso basico de mvc con composert autoload y twig",
"require": {
"twig/twig": "^2.0"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "843b04df5fdfe76251025001d66e0fd2",
"packages": [
{
"name": "symfony/polyfill-ctype",
"version": "v1.9.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "e3d826245268269cd66f8326bd8bc066687b4a19"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19",
"reference": "e3d826245268269cd66f8326bd8bc066687b4a19",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-ctype": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
},
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"time": "2018-08-06T14:22:27+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.9.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8",
"reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
},
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"time": "2018-08-06T14:22:27+00:00"
},
{
"name": "twig/twig",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "6a5f676b77a90823c2d4eaf76137b771adf31323"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/6a5f676b77a90823c2d4eaf76137b771adf31323",
"reference": "6a5f676b77a90823c2d4eaf76137b771adf31323",
"shasum": ""
},
"require": {
"php": "^7.0",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
"psr/container": "^1.0",
"symfony/debug": "^2.7",
"symfony/phpunit-bridge": "^3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"autoload": {
"psr-0": {
"Twig_": "lib/"
},
"psr-4": {
"Twig\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com",
"homepage": "http://fabien.potencier.org",
"role": "Lead Developer"
},
{
"name": "Armin Ronacher",
"email": "armin.ronacher@active-4.com",
"role": "Project Founder"
},
{
"name": "Twig Team",
"homepage": "https://twig.symfony.com/contributors",
"role": "Contributors"
}
],
"description": "Twig, the flexible, fast, and secure template language for PHP",
"homepage": "https://twig.symfony.com",
"keywords": [
"templating"
],
"time": "2018-07-13T07:18:09+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": []
}
......@@ -10,14 +10,14 @@ services:
ports:
- '3306:3306'
volumes:
- ./db/:/var/lib/mysql/
- ./log/:/var/log/mysql/
#- ./db/:/var/lib/mysql/
#- ./log/:/var/log/mysql/
- ./sql/:/docker-entrypoint-initdb.d/
web:
build: .
ports:
- '80:80'
volumes:
- ./app/:/var/www/html/
- ./:/var/www/html/
depends_on:
- db
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
require_once('controller/UserController.class.php');
require_once('model/BaseRepository.class.php');
require_once('model/UserRepository.class.php');
require_once('model/User.class.php');
require_once('view/TwigView.class.php');
require_once('view/UserView.class.php');
require_once('view/HomeView.class.php');
require __DIR__ . '/vendor/autoload.php';
use App\Controller\UserController;
if (isset($_GET["action"]) && $_GET["action"] == 'users') {
(new UserController)->index();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment