Автозагрузка классов
Класс находиться по пути: App/FabricMethod>Posts.php
namespace Posts;
/**
* Класс почта
* @package Posts
*/
abstract class Posts
{
abstract public function getPostDelivery(): Delivery;
public function dispatch ($content): void
{
$work = $this->getPostDelivery();
$work->recd();
$work->delivered();
}
}
class AirPost extends Posts
{
private int $weight;
private string $to;
private string $from;
/**
* @param $from
* @param $to
* @param $weight
*/
public function __construct(string $from, string $to, int $weight)
{
$this->from = $from;
$this->to = $to;
$this->weight = $weight;
}
public function getPostDelivery(): Delivery
{
return new PlaneDelivery($this->from, $this->to, $this->weight);
}
}
abstract class EarthPost extends Posts
{
protected int $weight;
protected string $to;
protected string $from;
/**
* @param $from
* @param $to
* @param $weight
*/
public function __construct(string $from, string $to, int $weight)
{
$this->from = $from;
$this->to = $to;
$this->weight = $weight;
}
abstract public function getPostDelivery(): Delivery;
}
class TrainPost extends EarthPost
{
public function __construct(string $from, string $to, int $weight)
{
parent::__construct($from, $to, $weight);
}
public function getPostDelivery(): Delivery
{
return new TrainDelivery($this->from, $this->to, $this->weight);
}
}
class TruckPost extends EarthPost
{
public function __construct(string $from, string $to, int $weight)
{
parent::__construct($from, $to, $weight);
}
public function getPostDelivery(): Delivery
{
return new TruckDelivery($this->from, $this->to, $this->weight);
}
}
interface Delivery
{
public function recd();
public function delivered();
}
class PlaneDelivery implements Delivery
{
private int $weight;
private string $to;
private string $from;
private float $cost = 0;
public function __construct(string $from, string $to, float $weight)
{
$this->from = $from;
$this->to = $to;
$this->weight = $weight;
$this->cost = $weight * 12;
}
public function recd()
{
echo "{$this->from} - посылка принято. Сумма доставки {$this->cost}! Доставка на самолете!";
}
public function delivered()
{
echo "{$this->to} - доставлено!";
}
}
class TrainDelivery implements Delivery
{
private int $weight;
private string $to;
private string $from;
private float $cost = 0;
public function __construct(string $from, string $to, float $weight)
{
$this->from = $from;
$this->to = $to;
$this->weight = $weight;
$this->cost = $weight * 5;
}
public function recd()
{
echo "{$this->from} - посылка принято. Сумма доставки {$this->cost}! Доставка на самолете!";
}
public function delivered()
{
echo "{$this->to} - доставлено!";
}
}
class TruckDelivery implements Delivery
{
private int $weight;
private string $to;
private string $from;
private int $cost = 0;
public function __construct(string $from, string $to, int $weight)
{
$this->from = $from;
$this->to = $to;
$this->weight = $weight;
$this->cost = $weight * 7;
}
public function recd()
{
echo "{$this->from} - посылка принято. Сумма доставки {$this->cost}! Доставка на самолете!";
}
public function delivered()
{
echo "{$this->to} - доставлено! <br>";
}
}
сделал для нее автозагрзузчик
{
"autoload": {
"psr-4": {
"Posts\\": "App/FabricMethod/"
}
}
}
на index.php обращаюсь к классу
require "vendor/autoload.php";
use Posts\Posts;
use Posts\TrainPost;
//require 'App/FabricMethod/Posts.php';
function clientCode(Posts $creator)
{
$creator->dispatch("Hello world!");
}
echo "Testing ConcreteCreator1: <br>";
clientCode(new TrainPost('Moscow', 'Volgograd', 1));
получаю Fatal error: Uncaught Error: Class 'Posts\TrainPost' not found in /opt/lampp/htdocs/site.loc/index.php
уже 2 дня не понимаю как это сделать. я новичок, помогите пожалуйста! Когда пишу "use"ы phpstorm видит классы и дает подсказки
