This commit is contained in:
kali 2024-03-25 18:07:54 +03:00
parent 5ecf87df75
commit e91e44ded9
49 changed files with 2197 additions and 24 deletions

5
.env Normal file
View File

@ -0,0 +1,5 @@
DB_DRIVER=mysql
DB_HOST="127.0.0.1"
DB_NAME=forms
DB_USER=root
DB_PASSWORD=kali

0
.gitignore vendored Normal file → Executable file
View File

19
bootstrap/db.php Normal file
View File

@ -0,0 +1,19 @@
<?php
require "vendor/autoload.php";
use Dotenv\Dotenv;
use Illuminate\Database\Capsule\Manager as Capsule;
$dotenv = Dotenv::createImmutable(ROOT_PATH);
$dotenv->load();
$capsule = new Capsule;
$capsule->addConnection([
"driver" => "mysql",
"host" =>"127.0.0.1",
"database" => "forms",
"username" => "root",
"password" => "kali"
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();

0
checkPOST.php Normal file → Executable file
View File

View File

@ -0,0 +1,96 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* main/index.html.twig */
class __TwigTemplate_09ccf709a9c7f01a6f9c635608c9f350 extends Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->blocks = [
'title' => [$this, 'block_title'],
'content' => [$this, 'block_content'],
];
}
protected function doGetParent(array $context)
{
// line 1
return "layouts/simple.html.twig";
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
$this->parent = $this->loadTemplate("layouts/simple.html.twig", "main/index.html.twig", 1);
$this->parent->display($context, array_merge($this->blocks, $blocks));
}
// line 3
public function block_title($context, array $blocks = [])
{
$macros = $this->macros;
echo twig_escape_filter($this->env, ($context["title"] ?? null), "html", null, true);
}
// line 5
public function block_content($context, array $blocks = [])
{
$macros = $this->macros;
// line 6
echo " ";
echo twig_escape_filter($this->env, $this->env->getFunction('create_form')->getCallable()(), "html", null, true);
echo "
";
// line 7
echo twig_escape_filter($this->env, ($context["content"] ?? null), "html", null, true);
echo "
";
}
/**
* @codeCoverageIgnore
*/
public function getTemplateName()
{
return "main/index.html.twig";
}
/**
* @codeCoverageIgnore
*/
public function isTraitable()
{
return false;
}
/**
* @codeCoverageIgnore
*/
public function getDebugInfo()
{
return array ( 63 => 7, 58 => 6, 54 => 5, 47 => 3, 36 => 1,);
}
public function getSourceContext()
{
return new Source("", "main/index.html.twig", "/home/kali/php/untitled/views/main/index.html.twig");
}
}

View File

@ -0,0 +1,101 @@
<?php
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Extension\SandboxExtension;
use Twig\Markup;
use Twig\Sandbox\SecurityError;
use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
/* layouts/simple.html.twig */
class __TwigTemplate_e48551b2ca758109aa7de7556ee07a2e extends Template
{
private $source;
private $macros = [];
public function __construct(Environment $env)
{
parent::__construct($env);
$this->source = $this->getSourceContext();
$this->parent = false;
$this->blocks = [
'title' => [$this, 'block_title'],
'content' => [$this, 'block_content'],
];
}
protected function doDisplay(array $context, array $blocks = [])
{
$macros = $this->macros;
// line 1
echo "<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<title>";
// line 5
$this->displayBlock('title', $context, $blocks);
echo " </title>
<link rel=\"stylesheet\" href=\"vendor/twbs/bootstrap/dist/css/bootstrap.css\">
<link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\"
integrity=\"sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN\" crossorigin=\"anonymous\" />
</head>
<body>
<div class=\"container\">
<div class=\"row\">
<div class=\"col-12\">
";
// line 15
$this->displayBlock('content', $context, $blocks);
// line 16
echo " </div>
</div>
</div>
</body>
</html>";
}
// line 5
public function block_title($context, array $blocks = [])
{
$macros = $this->macros;
}
// line 15
public function block_content($context, array $blocks = [])
{
$macros = $this->macros;
}
/**
* @codeCoverageIgnore
*/
public function getTemplateName()
{
return "layouts/simple.html.twig";
}
/**
* @codeCoverageIgnore
*/
public function getDebugInfo()
{
return array ( 76 => 15, 70 => 5, 60 => 16, 58 => 15, 45 => 5, 39 => 1,);
}
public function getSourceContext()
{
return new Source("", "layouts/simple.html.twig", "/home/kali/php/untitled/views/layouts/simple.html.twig");
}
}

5
composer.json Normal file → Executable file
View File

@ -14,6 +14,9 @@
"require": {
"twbs/bootstrap": "5.0.2",
"itguild/php-cg-select-v2": "^0.1.0",
"craft-group/phroute": "^2.1"
"craft-group/phroute": "^2.1",
"twig/twig": "^3.0",
"illuminate/database": "^11.0",
"vlucas/phpdotenv": "^5.6"
}
}

1797
composer.lock generated Normal file → Executable file

File diff suppressed because it is too large Load Diff

11
console.php Normal file
View File

@ -0,0 +1,11 @@
<?php
use itguild\forms\migrations\UserMigration;
const ROOT_PATH = __DIR__;
require_once "vendor/autoload.php";
require_once "bootstrap/db.php";
UserMigration::up();

0
example.php Normal file → Executable file
View File

0
example_json.php Normal file → Executable file
View File

0
form.json Normal file → Executable file
View File

14
index.php Normal file → Executable file
View File

@ -2,18 +2,26 @@
ini_set("display_errors", 1);
error_reporting(-1);
const ROOT_PATH = __DIR__;
const VIEW_PATH = __DIR__ . "/views";
const VIEW_CACHE_PATH = __DIR__ . "/compilation_cache";
require_once "vendor/autoload.php";
require_once "bootstrap/db.php";
use Phroute\Phroute\RouteCollector;
$router = new RouteCollector();
$router->get('/', [\itguild\forms\app\controllers\Main::class, 'indexAction']);
$router->get('/example', [\itguild\forms\app\controllers\Main::class, 'exampleAction']);
$router->get('/', [\itguild\forms\app\controllers\MainController::class, 'indexAction']);
$router->get('/example', [\itguild\forms\app\controllers\MainController::class, 'exampleAction']);
$router->get('/create-user', [\itguild\forms\app\controllers\UserController::class, 'createUserAction']);
$router->get('/get-user/{id}', [\itguild\forms\app\controllers\UserController::class, 'getUserAction']);
$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
// Print out the value returned from the dispatched function
echo $response;

0
old_index.php Normal file → Executable file
View File

2
routing.php Normal file → Executable file
View File

@ -8,4 +8,4 @@ use Phroute\Phroute\RouteCollector;
$router = new RouteCollector();
$router->get('/', [\itguild\forms\app\controllers\Main::class, 'indexAction']);
$router->get('/', [\itguild\forms\app\controllers\MainController::class, 'indexAction']);

0
src/ActiveForm.php Normal file → Executable file
View File

0
src/Form.php Normal file → Executable file
View File

5
src/JsonForm.php Normal file → Executable file
View File

@ -66,4 +66,9 @@ class JsonForm
echo $this->html;
}
public function fetch(): string
{
return $this->html;
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace itguild\forms\app\controllers;
class Main
{
public function indexAction(): void
{
echo 123;
}
public function exampleAction()
{
echo "example";
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\debug\Debug;
use itguild\forms\JsonForm;
use Twig\TwigFunction;
class MainController extends BaseController
{
private $html;
public function indexAction(): void
{
$this->view->addFunction(new TwigFunction("create_form", function (){
$form = new JsonForm(file_get_contents("form.json"));
$form->convertHTML();
$form->render();
}));
echo $this->view->render('main/index.html.twig', ['title' => 'Заголовок', 'content' => ""]);
}
public function exampleAction()
{
echo "example";
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace itguild\forms\app\controllers;
use itguild\forms\app\core\BaseController;
use itguild\forms\app\models\User;
use itguild\forms\debug\Debug;
class UserController extends BaseController
{
public function createUserAction()
{
$user = User::Create([ 'name' => "Ahmed Khan", 'email' => "ahmed.khan@lbs.com", 'password' => password_hash("ahmedkhan",PASSWORD_BCRYPT), ]);
}
public function getUserAction($id)
{
Debug::prn(User::find(1)->first()->email);
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace itguild\forms\app\core;
class BaseController
{
protected $view;
public function __construct()
{
$loader = new \Twig\Loader\FilesystemLoader(VIEW_PATH);
$this->view = new \Twig\Environment($loader, [
'cache' => VIEW_CACHE_PATH,
]);
}
}

19
src/app/models/User.php Normal file
View File

@ -0,0 +1,19 @@
<?php
namespace itguild\forms\app\models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = "user";
protected $fillable = [
'name', 'email', 'password','userimage'
];
protected $hidden = [
'password', 'remember_token',
];
}

0
src/builders/Builder.php Normal file → Executable file
View File

0
src/builders/ButtonBuilder.php Normal file → Executable file
View File

0
src/builders/CheckBoxBuilder.php Normal file → Executable file
View File

0
src/builders/LabelBuilder.php Normal file → Executable file
View File

0
src/builders/RadioButtonBuilder.php Normal file → Executable file
View File

0
src/builders/SelectBuilder.php Normal file → Executable file
View File

0
src/builders/TextAreaBuilder.php Normal file → Executable file
View File

0
src/builders/TextInputBuilder.php Normal file → Executable file
View File

0
src/debug/Debug.php Normal file → Executable file
View File

0
src/inputs/BaseInput.php Normal file → Executable file
View File

0
src/inputs/Button.php Normal file → Executable file
View File

0
src/inputs/Checkbox.php Normal file → Executable file
View File

0
src/inputs/Label.php Normal file → Executable file
View File

0
src/inputs/RadioButton.php Normal file → Executable file
View File

0
src/inputs/Select.php Normal file → Executable file
View File

0
src/inputs/TextArea.php Normal file → Executable file
View File

0
src/inputs/TextInput.php Normal file → Executable file
View File

0
src/mappers/JsonInputMapper.php Normal file → Executable file
View File

View File

@ -0,0 +1,30 @@
<?php
namespace itguild\forms\migrations;
use Illuminate;
class UserMigration
{
public static function up(): void
{
Illuminate\Database\Capsule\Manager::schema()->create("user", function ($table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('userimage')->nullable();
$table->string('api_key')->nullable()->unique();
$table->rememberToken();
$table->timestamps();
});
}
public static function down(): void
{
Illuminate\Database\Capsule\Manager::schema()->drop("user");
}
}

0
src/templates/Simple/SimpleTemplate.php Normal file → Executable file
View File

0
src/templates/Template.php Normal file → Executable file
View File

0
src/templates/bootstrap5/Bootstrap5Template.php Normal file → Executable file
View File

0
src/traits/CreateOption.php Normal file → Executable file
View File

0
src/traits/CreateParams.php Normal file → Executable file
View File

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %} </title>
<link rel="stylesheet" href="vendor/twbs/bootstrap/dist/css/bootstrap.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12">
{% block content %}{% endblock %}
</div>
</div>
</div>
</body>
</html>

8
views/main/index.html.twig Executable file
View File

@ -0,0 +1,8 @@
{% extends "layouts/simple.html.twig" %}
{% block title %}{{ title }}{% endblock %}
{% block content %}
{{ create_form() }}
{{ content }}
{% endblock %}