PHP without a framework: Difference between revisions

From Rixort Wiki
Jump to navigation Jump to search
Line 21: Line 21:
  <?php
  <?php
   
   
  declare(strict_types=1);
  declare(strict_types = 1);
   
   
  require_once __DIR__ . '/../vendor/autoload.php';
  require_once __DIR__ . '/../vendor/autoload.php';
Create <code>HelloWorld</code> class in <code>src/HelloWorld.php</code>:
<?php
declare(strict_types = 1);
namespace MyApp;
class HelloWorld
{
  public function hello()
  {
    echo 'Hello World';
  }
}

Revision as of 12:42, 6 March 2021

Instructions

Initialise composer project:

composer init

Create skeleton directory structure:

mkdir public src

Add dependencies:

 composer require php-di/php-di

Run composer to install dependencies and create vendor:

composer install

Create skeleton front controller at public/index.php

<?php

declare(strict_types = 1);

require_once __DIR__ . '/../vendor/autoload.php';

Create HelloWorld class in src/HelloWorld.php:

<?php

declare(strict_types = 1);

namespace MyApp;
class HelloWorld
{
  public function hello()
  {
    echo 'Hello World';
  }
}