PHP Classes

How to Setup a PHP MVC Application Routes Extracted from Route Class Comments using Potato Service: Framework that extracts route details from classes

Recommend this page to a friend!
  Info   View files Documentation   View files View files (147)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2022-10-15 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 35 This week: 2All time: 10,566 This week: 349Up
Version License PHP version Categories
potatoservice 1.0GNU General Publi...8.1Libraries, Design Patterns, PHP 8
Description Author

This package provides a framework that extracts route details from classes.

It implements the Command Query Responsibility Segregation pattern (CQRS) by parsing the routing information to route HTTP requests that match route pattern parameters defined in comments of the application route classes.

This framework uses PHP reflection to parse the application route classes comments and extract route details like the route:

- HTTP request type

- Name of the controller class and function name that will handle the routed request

- Required request headers

- Etc.

The framework can also validate the request parameters according to rules that applications define in map request classes.

Innovation Award
PHP Programming Innovation award nominee
September 2022
Number 5
PHP 8 implements the possibility to extract attributes defined in comments of PHP classes using PHP reflection support.

This package uses this possibility to implement an MVC framework that developers can use to configure HTTP request routes using route classes that comment attributes that define the details of the routing of HTTP requests to controller classes.

This way, developers can define the PHP application HTTP request routing configuration in the same class file that implements the routing code.

This possibility makes it easier to maintain complex PHP applications because it avoids the need to define routing PHP code in a separate file from the routing configuration.

Manuel Lemos
Picture of Maicon gonšalez
  Performance   Level  
Name: Maicon gonšalez <contact>
Classes: 5 packages by
Country: Brazil Brazil
Age: 28
All time rank: 2484172 in Brazil Brazil
Week rank: 201 Up15 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Details

PotatoService

New version of PotatoFramework

About it

PotatoService try implement the CQRS pattern, but it is still in first steps.

  • PHP Version Requirement: 8.1 or higher
  • Status: Alpha Release
  • Version: 0.1

Potato Service Structure

  1. Aplication Layer
  2. Domain Layer
  3. Infrastructure Layer

About Settings

  1. All your project settings can be done by changing the .env file [infrastructure/.env -> $_ENV]
  2. All dependencies can be configured by composer [infrastructure/composer.json]

Resources

All requests can be mapped by resource and and initialized by the runner, if you created a new Resource file, just go on application/runner/Main.php and put the class in loadResource();

Routes::registerResources([
    DemoQueryResource::class
]);

On your resource file, you just use Attribute #[Route] to mapping your routes [see: application/resource/DemoQueryResource].

#[Route(route: 'Home', code: StatusCode::OK, type: HttpRequest::GET, headers: [ ContentType::CONTENT_JS ])]  
public function exampleRouting(DemoResquest $demoResquest){  
	$this->testeService->execute();  
} 

You can map the request input data (Post, Get, etc), just create a class and extend it to MapRequest, after, just set this in yout method. With this you can use attributes to validate all you need.

class DemoResquest extends MapRequest {  
  #[MinLength(5)]  
  public ?string $nome;  

  #[NotBlank]  
  public ?string $sobrenome;  
}

Services

Create a services to mantain your business rules in domain layer and use it in your application layer

class TesteService extends Services {  
    #[Autowired(class: TesteRepository::class)]  
	public TesteRepository $testeRepository;

	public function execute(){}
}

Exception

We have a BusinessException and ServerException, when any exception is called the system output a json with this error, BussinessException use code 400 and ServerException use 500.

You can create your exceptions and use it to show a more detailed info about the error.

Repositories

We use a Eloquent ORM and try simulate a small Repository with it. When you create a Model, you just extend it with EntityModel and use attribute in class #[Entity(tableName: 'teste', properties: ['timestamps' => false])]

In model you can map your columns table and validate it, ex:

#[Entity(tableName: 'teste', properties: ['timestamps' => false])]
class Teste extends EntityModel {

    #[Column(name: "id", primaryKey: true)]
    public $id;

    #[NotBlank]
    #[Column(name: "nome")]
    public $nome;
}

After, you create a new Repository class and extend it on Repository:

#[SetRepository(entity: Teste::class)]  
class TesteRepository extends Repository {  
}

You can use atribte Autowired to load it your application layer or in your services, example:

#[Autowired(class: TesteRepository::class)]  
public TesteRepository $testeRepository;

Attributes

We have same attributes

#[Route] Can only be used on Resources. Used to mapping your routes

#[Transactional] Can only be used on Resources with routes and any exeception make a rollback in your database [Tested with MySQL]

#[Cache] Can only be used on Resources to create a cache for your output response

#[Autowired] Can used by Resources and Services and is related to dependency injection

You can create a validation attribute, just create a class and implement a iValidation interface

By default we have same validations attributes and all can be used in EntityModel and MapQuest

#[AssertFalse] #[AssertTrue] #[Decimal] #[Email] #[Future] #[FutureOrPresent] #[Max] #[Min] #[MinLength] #[MaxLength] #[Negative] #[NegativeOrZero] #[NotBlank] #[NotEmpty] #[NotNull] #[Numeric] #[Password] #[Past] #[PastOrPresent] #[Pattern] #[PositiveOrZero] #[Url]

  Files folder image Files  
File Role Description
Files folder imageapplication (1 file, 2 directories)
Files folder imagedomain (1 file, 3 directories)
Files folder imageinfrastructure (4 files, 7 directories)
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  application  
File Role Description
Files folder imageresources (1 file, 1 directory)
Files folder imagerunner (1 file)
  Accessible without login Plain text file .htaccess Data Auxiliary data

  Files folder image Files  /  application  /  resources  
File Role Description
Files folder imagerequest (1 file)
  Plain text file DemoQueryResource.php Class Class source

  Files folder image Files  /  application  /  resources  /  request  
File Role Description
  Plain text file DemoResquest.php Class Class source

  Files folder image Files  /  application  /  runner  
File Role Description
  Plain text file Main.php Class Class source

  Files folder image Files  /  domain  
File Role Description
Files folder imagemodel (1 file)
Files folder imagerepository (1 file)
Files folder imageservice (1 file)
  Accessible without login Plain text file .htaccess Data Auxiliary data

  Files folder image Files  /  domain  /  model  
File Role Description
  Plain text file Teste.php Class Class source

  Files folder image Files  /  domain  /  repository  
File Role Description
  Plain text file TesteRepository.php Class Class source

  Files folder image Files  /  domain  /  service  
File Role Description
  Plain text file TesteService.php Class Class source

  Files folder image Files  /  infrastructure  
File Role Description
Files folder imagecache (1 file)
Files folder imagecore (1 file, 9 directories)
Files folder imageemail (2 files)
Files folder imagefile (1 file, 1 directory)
Files folder imagehelpers (2 files)
Files folder imagei18n (1 directory)
Files folder imagelibraries (1 directory)
  Accessible without login Plain text file .env Data Auxiliary data
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file composer.json Data Auxiliary data

  Files folder image Files  /  infrastructure  /  cache  
File Role Description
  Plain text file CacheService.php Class Class source

  Files folder image Files  /  infrastructure  /  core  
File Role Description
Files folder imageattributes (4 files, 1 directory)
Files folder imagedatabase (4 files, 2 directories)
Files folder imageenums (4 files)
Files folder imageexception (7 files)
Files folder imagefactory (1 file)
Files folder imagegeneral (7 files)
Files folder imagehttp (7 files)
Files folder imageinterfaces (4 files)
Files folder imagetraits (1 file)
  Plain text file PotatoCore.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  attributes  
File Role Description
Files folder imagevalidation (23 files)
  Plain text file Autowired.php Class Class source
  Plain text file Cache.php Class Class source
  Plain text file Route.php Class Class source
  Plain text file Transactional.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  attributes  /  validation  
File Role Description
  Plain text file AssertFalse.php Class Class source
  Plain text file AssertTrue.php Class Class source
  Plain text file Decimal.php Class Class source
  Plain text file Email.php Class Class source
  Plain text file Future.php Class Class source
  Plain text file FutureOrPresent.php Class Class source
  Plain text file Max.php Class Class source
  Plain text file MaxLength.php Class Class source
  Plain text file Min.php Class Class source
  Plain text file MinLength.php Class Class source
  Plain text file Negative.php Class Class source
  Plain text file NegativeOrZero.php Class Class source
  Plain text file NotBlank.php Class Class source
  Plain text file NotEmpty.php Class Class source
  Plain text file NotNull.php Class Class source
  Plain text file Numeric.php Class Class source
  Plain text file Password.php Class Class source
  Plain text file Past.php Class Class source
  Plain text file PastOrPresent.php Class Class source
  Plain text file Pattern.php Class Class source
  Plain text file Positive.php Class Class source
  Plain text file PositiveOrZero.php Class Class source
  Plain text file Url.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  database  
File Role Description
Files folder imageattributes (3 files)
Files folder imageinterfaces (2 files)
  Plain text file EloquentDriver.php Class Class source
  Plain text file EntityModel.php Class Class source
  Plain text file FactoryDatabase.php Class Class source
  Plain text file Repository.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  database  /  attributes  
File Role Description
  Plain text file Column.php Class Class source
  Plain text file Entity.php Class Class source
  Plain text file SetRepository.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  database  /  interfaces  
File Role Description
  Plain text file iDriverImplements.php Class Class source
  Plain text file iRepository.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  enums  
File Role Description
  Plain text file ContentType.php Class Class source
  Accessible without login Plain text file HttpRequest.php Aux. Auxiliary script
  Accessible without login Plain text file ResponseType.php Aux. Auxiliary script
  Accessible without login Plain text file StatusCode.php Aux. Auxiliary script

  Files folder image Files  /  infrastructure  /  core  /  exception  
File Role Description
  Plain text file BusinessException.php Class Class source
  Plain text file EntityNotFoundOnModelException.php Class Class source
  Plain text file EnvironmentException.php Class Class source
  Plain text file InvalidRequestException.php Class Class source
  Plain text file RepositoryEntityNotFoundException.php Class Class source
  Plain text file ServerException.php Class Class source
  Plain text file SetRepositoryAttri...tFoundException.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  factory  
File Role Description
  Plain text file FactoryResponse.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  general  
File Role Description
  Plain text file GeneralReflection.php Class Class source
  Plain text file MapRequest.php Class Class source
  Plain text file OutputBuffer.php Class Class source
  Plain text file Password.php Class Class source
  Plain text file Services.php Class Class source
  Plain text file Session.php Class Class source
  Plain text file Smarty.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  http  
File Role Description
  Plain text file Request.php Class Class source
  Plain text file Response.php Class Class source
  Plain text file ResponseHtml.php Class Class source
  Plain text file ResponseJson.php Class Class source
  Plain text file ResponseReturn.php Class Class source
  Plain text file RouteMap.php Class Class source
  Plain text file Routes.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  interfaces  
File Role Description
  Plain text file iAttribute.php Class Class source
  Plain text file iCache.php Class Class source
  Plain text file iRunner.php Class Class source
  Plain text file iValidation.php Class Class source

  Files folder image Files  /  infrastructure  /  core  /  traits  
File Role Description
  Plain text file Singleton.php Class Class source

  Files folder image Files  /  infrastructure  /  email  
File Role Description
  Plain text file EmailHelper.php Class Class source
  Plain text file SendEmail.php Class Class source

  Files folder image Files  /  infrastructure  /  file  
File Role Description
Files folder imageUpload (7 files, 2 directories)
  Plain text file Images.php Class Class source

  Files folder image Files  /  infrastructure  /  file  /  Upload  
File Role Description
Files folder imageStorage (1 file)
Files folder imageValidation (4 files)
  Plain text file Autoloader.php Class Class source
  Plain text file Exception.php Class Class source
  Plain text file File.php Class Class source
  Plain text file FileInfo.php Class Class source
  Plain text file FileInfoInterface.php Class Class source
  Plain text file StorageInterface.php Class Class source
  Plain text file ValidationInterface.php Class Class source

  Files folder image Files  /  infrastructure  /  file  /  Upload  /  Storage  
File Role Description
  Plain text file FileSystem.php Class Class source

  Files folder image Files  /  infrastructure  /  file  /  Upload  /  Validation  
File Role Description
  Plain text file Dimensions.php Class Class source
  Plain text file Extension.php Class Class source
  Plain text file Mimetype.php Class Class source
  Plain text file Size.php Class Class source

  Files folder image Files  /  infrastructure  /  helpers  
File Role Description
  Accessible without login Plain text file Core.php Example Example script
  Accessible without login Plain text file Handlers.php Example Example script

  Files folder image Files  /  infrastructure  /  i18n  
File Role Description
Files folder imagept_BR (1 directory)

  Files folder image Files  /  infrastructure  /  i18n  /  pt_BR  
File Role Description
Files folder imageLC_MESSAGES (1 file)

  Files folder image Files  /  infrastructure  /  i18n  /  pt_BR  /  LC_MESSAGES  
File Role Description
  Accessible without login Plain text file messages.po Data Auxiliary data

  Files folder image Files  /  infrastructure  /  libraries  
File Role Description
Files folder imageMoment (7 files, 2 directories)

  Files folder image Files  /  infrastructure  /  libraries  /  Moment  
File Role Description
Files folder imageCustomFormats (1 file)
Files folder imageLocales (36 files)
  Plain text file FormatsInterface.php Class Class source
  Plain text file Moment.php Class Class source
  Plain text file MomentException.php Class Class source
  Plain text file MomentFromVo.php Class Class source
  Plain text file MomentHelper.php Class Class source
  Plain text file MomentLocale.php Class Class source
  Plain text file MomentPeriodVo.php Class Class source

  Files folder image Files  /  infrastructure  /  libraries  /  Moment  /  CustomFormats  
File Role Description
  Plain text file MomentJs.php Class Class source

  Files folder image Files  /  infrastructure  /  libraries  /  Moment  /  Locales  
File Role Description
  Accessible without login Plain text file ar_TN.php Aux. Auxiliary script
  Accessible without login Plain text file ca_ES.php Example Example script
  Accessible without login Plain text file cs_CZ.php Aux. Auxiliary script
  Accessible without login Plain text file da_DK.php Aux. Auxiliary script
  Accessible without login Plain text file de_DE.php Aux. Auxiliary script
  Accessible without login Plain text file en_CA.php Aux. Auxiliary script
  Accessible without login Plain text file en_GB.php Aux. Auxiliary script
  Accessible without login Plain text file en_US.php Aux. Auxiliary script
  Accessible without login Plain text file eo.php Aux. Auxiliary script
  Accessible without login Plain text file es_ES.php Example Example script
  Accessible without login Plain text file fa_IR.php Aux. Auxiliary script
  Accessible without login Plain text file fi_FI.php Aux. Auxiliary script
  Accessible without login Plain text file fr_CA.php Aux. Auxiliary script
  Accessible without login Plain text file fr_FR.php Aux. Auxiliary script
  Accessible without login Plain text file hu_HU.php Example Example script
  Accessible without login Plain text file id_ID.php Aux. Auxiliary script
  Accessible without login Plain text file it_IT.php Example Example script
  Accessible without login Plain text file ja_JP.php Aux. Auxiliary script
  Accessible without login Plain text file ko_KR.php Aux. Auxiliary script
  Accessible without login Plain text file kz_KZ.php Aux. Auxiliary script
  Accessible without login Plain text file lv_LV.php Aux. Auxiliary script
  Accessible without login Plain text file nl_NL.php Aux. Auxiliary script
  Accessible without login Plain text file no_NO.php Aux. Auxiliary script
  Accessible without login Plain text file oc_LNC.php Aux. Auxiliary script
  Accessible without login Plain text file pl_PL.php Example Example script
  Accessible without login Plain text file pt_BR.php Example Example script
  Accessible without login Plain text file pt_PT.php Aux. Auxiliary script
  Accessible without login Plain text file ro_RO.php Aux. Auxiliary script
  Accessible without login Plain text file ru_RU.php Aux. Auxiliary script
  Accessible without login Plain text file sv_SE.php Aux. Auxiliary script
  Accessible without login Plain text file th_TH.php Aux. Auxiliary script
  Accessible without login Plain text file tr_TR.php Aux. Auxiliary script
  Accessible without login Plain text file uk_UA.php Example Example script
  Accessible without login Plain text file vi_VN.php Aux. Auxiliary script
  Accessible without login Plain text file zh_CN.php Aux. Auxiliary script
  Accessible without login Plain text file zh_TW.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:35
This week:2
All time:10,566
This week:349Up