mirror of
https://github.com/igorsimdyanov/php8.git
synced 2025-08-06 11:10:42 +00:00
Глава 36: переработка автозагрузки
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
namespace PHP8;
|
||||
|
||||
trait Tag
|
||||
trait Author
|
||||
{
|
||||
public function tags()
|
||||
public function authors()
|
||||
{
|
||||
// $query = 'SELECT * FROM authors WHERE id IN(:ids)'
|
||||
echo 'Tag::tags<br />';
|
||||
echo 'Author::authors()<br />';
|
||||
}
|
||||
}
|
@ -1,18 +1,14 @@
|
||||
<?php
|
||||
namespace PHP8;
|
||||
use \PHP8\Seo as Seo;
|
||||
use \PHP8\Tag as Tag;
|
||||
use \PHP8\Author as Author;
|
||||
|
||||
class Page
|
||||
{
|
||||
use Seo, Tag;
|
||||
use Seo, Author;
|
||||
|
||||
protected $title;
|
||||
protected $content;
|
||||
|
||||
public function __construct(string $title = '', string $content = '')
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->content = $content;
|
||||
}
|
||||
public function __construct(
|
||||
protected string $title = '',
|
||||
protected string $content = ''
|
||||
) {}
|
||||
}
|
||||
|
@ -3,10 +3,6 @@ namespace PHP8;
|
||||
|
||||
trait Seo
|
||||
{
|
||||
private $keyword;
|
||||
private $description;
|
||||
private $ogs;
|
||||
|
||||
public function keywords()
|
||||
{
|
||||
// $query = 'SELECT keywords FROM seo WHERE id = :id LIMIT 1'
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?php
|
||||
spl_autoload_register(function($classname){
|
||||
$path = strtolower($classname);
|
||||
require_once(__DIR__ . "/$path.php");
|
||||
spl_autoload_register(function(string $classname){
|
||||
$namespace = array_map(
|
||||
fn($class) => $class != 'PHP8' ? strtolower($class) : $class,
|
||||
explode('\\', $classname)
|
||||
);
|
||||
require_once(__DIR__ . '/' . implode('/', $namespace) . '.php');
|
||||
});
|
||||
|
||||
$page = new PHP8\Page('О нас', 'Содержимое страницы');
|
||||
$page->tags();
|
||||
$page->authors(); // Author::authors()
|
||||
|
@ -1,8 +0,0 @@
|
||||
<?php
|
||||
function __autoload($classname)
|
||||
{
|
||||
require_once(__DIR__ . "/$classname.php");
|
||||
}
|
||||
|
||||
$page = new PHP8\Page('О нас', 'Содержимое страницы');
|
||||
$page->tags();
|
@ -2,4 +2,4 @@
|
||||
spl_autoload_register();
|
||||
|
||||
$page = new PHP8\Page('О нас', 'Содержимое страницы');
|
||||
$page->tags(); // Tag::tags
|
||||
$page->authors(); // Author::authors()
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once(__DIR__ . '/PHP8/seo.php');
|
||||
require_once(__DIR__ . '/PHP8/tag.php');
|
||||
require_once(__DIR__ . '/PHP8/author.php');
|
||||
require_once(__DIR__ . '/PHP8/page.php');
|
||||
|
||||
$page = new PHP8\Page('О нас', 'Содержимое страницы');
|
||||
$page->tags(); // Tag::tags
|
||||
$page->authors(); // Author::authors()
|
||||
|
Reference in New Issue
Block a user