I study OOP in PHP, please give a hint to the structure of classes or an already existing script with competent OOP, where you can see the implementation of a similar task.
It is necessary to process products that have common properties: name, quantity and price, but some products have special properties (for example: for clothes - size, for a laptop - processor). Each property of the product has its limitations (simplified): name (^ [а-я \ s -] {3,50} $), quantity (1-100), price (0.01 - 10 000) and set others. Also, depending on the rights of the user who edits the product, the properties available for editing are also different. For example: a manager can add / edit a product, specifying its name (required) and a link (optional), and only sees the price (without editing), the accountant does not have the right to add, but can change the price of an existing product and its quantity but not the name.
In procedural style, it looks like this:
/** Настройки товаров */ $shop['item']['name']['type'] = 'string'; $shop['item']['name']['min_len'] = 3; $shop['item']['name']['max_len'] = 50; $shop['item']['name']['pattern'] = '~^[а-я\s-]{'.$shop['item']['name']['min_len'].','.$shop['item']['name']['max_len'] .'}$~ui'; $shop['item']['price']['type'] = 'float'; // В БД хранится как DECIMAL $shop['item']['price']['min_val'] = 0.01; $shop['item']['price']['max_val'] = 10000; //... Другие настройки /** * Настройки редактирования товаров */ $shop['edit_type']['manager']['action'] = ['add', 'upd']; $shop['edit_type']['manager']['field']['name']['action'] = 'change'; $shop['edit_type']['manager']['field']['name']['val'] = 'necessarilly'; $shop['edit_type']['manager']['field']['url']['action'] = 'change'; $shop['edit_type']['manager']['field']['url']['val'] = 'optional'; // ... $shop['edit_type']['buch']['action'] = ['upd']; $shop['edit_type']['buch']['field']['price']['action'] = 'change'; $shop['edit_type']['buch']['field']['price']['val'] = 'necessarilly'; $shop['edit_type']['buch']['field']['name']['action'] = 'view';
Next, functions are written that, depending on the parameters of the $ shop ['edit_type'] array, display add / edit forms and validate the entered data (+ its own function using the data of $ shop ['item']) for each type of product property.
Tell me the scheme of building classes / traits / itp to implement the task using OOP? As far as I can imagine, all the settings ($ shop ['item'], $ shop ['edit_type']) are stored in the trail (s) so that they can be used in various class objects, separate classes for data verification and for output ?