T
T
thorii2016-10-10 16:54:37
PHP
thorii, 2016-10-10 16:54:37

How crooked is this application architecture?

When writing an answer, please take into account the fact that I just started learning web development, please indicate a more detailed answer to all kinds of "crutches".
It occurred to me to structure some libraries into one package (let's call it Core). It includes libraries Events , Fstream (working with file streams), Errors (actual error handling), Logger (well, I think it’s clear here). I decided to wrap them in one package due to the fact that each library uses another library from the package. It seemed to me that it was a good tone, to structure them, to set logic (The kernel is autonomous, it must be able to work with autoloading and log exceptions, regardless of whether there is a ready-made library for this. The kernel is always sure that it contains functionality for correct operation, which cannot be said for sure when building an application from ready-made third-party libraries ). It is planned that the kernel can be used without changes in different projects, simply adding the necessary libraries using the Kernel API.
Conclusion : The core contains the basic functionality that is used to create any web application, everything else is external libraries that can use the core API to expand its capabilities, etc.
The question arose of how to get instances of classes included in the core and work with them at the application level.
Creating through new Lib () causes me some rejection, because the fact that the specified Lib belongs to the kernel package is not visible to the eye, as a result of which I was visited by the idea to use a kind of transport layer, it will be easier to explain the syntax

$lib = Core::resource('libname', $constructorArg1, $constructorArg2...) //@return Object libname
//Это же далеко не DI или IoC?

To ensure that variables are not passed to the constructor through function_get_args(), I decided to use an interesting php 7 construction below, an example from the link
<?php
function sumOfInts(int ...$ints)
{
    return array_sum($ints);
}
var_dump(sumOfInts(2, '3', 4.1));

$lib = Core::resource('libname', $constructorArg1, $constructorArg2...) //@return Object libname
//Это же далеко не DI или IoC?

This is what I want to use to make the code more readable and to rigidly indicate that libname is being searched as a kernel library.
I don’t have development experience yet, and I don’t want to start production with crutches, so I ask for a clear criticism of the architecture
Here is an example of library dependencies:
Core
  • uses the ErrorTrap error trapping service which uses logger and Report to log and send reports
  • uses an Event to tell listeners that the kernel has been successfully initialized

The actual directory tree of the Core package
615fbda1ba394f9ebb21fae39e2e7d80.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
entermix, 2016-10-10
@entermix

Crooked.
Have you heard about composer, PSR?

M
Michael, 2016-10-10
@springimport

Do you use namespaces?
Still, try to implement a composer, it will not interfere with learning, because it is not necessary to immediately use all ready-made libraries. For example, you don't have to write such low-level things as file handling and so on.
Still up-to-date the right way .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question