fabiomattei/uglyduckling
Composer 安装命令:
composer require fabiomattei/uglyduckling
包简介
Framework to create web applications using json structures
README 文档
README
Documentation
If you are looking for a more complete description of the project check out the documentation site: https://www.uddocs.com/
Demo
This demo shows the main features of the library.
The best code is the code you don't need to write
I wrote this code in order to avoid to write over and over again the same stuff. I have been writing web applications for many years. What were those applications doing? They were thaking data from a form, saving that data in a database and then editing that data in another form and showing that data in a table or in a diagram ad sometimes they were deleting that data (not very often to be fair).
Well, I have done that over and over again, form after form, ORM after ORM, MVC after MVC.
I felt lost and bored. I was working so hard and I was accomplishing so little.
I have learned many framework to speed up my process, I read many books: the new thing, so exiting!
Then I started to notice that my work was repeatable and those frameworks were slowing me down.
With an MVC approach each change you wond to make to your application requires you open at least 3 files.
So I started to wonder: What do I really need in order to make for example a table cotaining data taken from a database? The answer was: I need to make a SQL query, I need to define the structure of the table and I need to put the results of the query on the table. That's it. I need this three things, nothig more than that.
I put all this information in a json file and this came out:
{
"query": {
"sql": "select id, name, amount, duedate FROM requestv1;"
},
"table": {
"title": "My table",
"fields": [
{"headline": "Name", "sqlfield": "name"},
{"headline": "Amount", "sqlfield": "amount"},
{"headline": "Due date", "sqlfield": "duedate"}
]
}
}
No ORM, no MVC, and a framework that stays out of my way.
I know I used SQL and not an ORM but I like SQL! SQL haven't changed in ages, and this means that it works! It is not sad to be old!
I gave a title to the table and in the fields array I defined the headlines and the sql fields that were taken from the query in order to fill the cells of that table. How many times have you solved this same simple problem? Have you ever done it writing less code? If that is true please let me know!
I know what you are thinking about: this is not general enough, what if I need to make calculations or generalize some logic or do something more complicated? Well, you can always get back to your old way, and program a controller a view, maybe made of partials, connect and ORM, write down your model and... so on and so on and so on...
But, let's be straight, do you really need it? How often do you do that? I often found mysel filling a table with the results of just one query, maybe with few joined tables.
Let's add some link
What if I need to add a link to some supported action to the table? I defined that in the json format too.
{
"query": {
"sql": "select id, name, amount, duedate FROM requestv1;"
},
"table": {
"title": "My table",
"fields": [
{"headline": "Name", "sqlfield": "name"},
{"headline": "Amount", "sqlfield": "amount"},
{"headline": "Due date", "sqlfield": "duedate"}
],
"actions": [
{"label": "Info", "resource": "inforequest", "parameters":[{"name": "id", "sqlfield": "id"}] },
{"label": "Edit", "resource": "formrequest", "parameters":[{"name": "id", "sqlfield": "id"}] },
{"label": "Delete", "resource": "deletereport", "parameters":[{"name": "id", "sqlfield": "id"}] }
]
}
}
A link is defined from a label (the user need to see what is clicking) an action and few parameters maybe coming from the SQL query.
If you are wondering what a resource is, it is a index to find a specific json configuration file, like this one, in the system. There are resources for forms, for pdf exports, for data charts, for whatever you need. And if you need more you can always define a new template, this is an open source project after all.
Let's finish up the json file
There are few things to do in order to complete the file. We neet to give it a name so we can find it between al the resources. We need to add some metadata, in case in the future we need to add more features.
The system supports the concept of allowed groups to access a specific resource, this explains the "allowedgroups" array.
There is a get section in this file, it is there because all this configurations are for a GET request.
{
"name": "requesttablev1",
"metadata": { "type":"table", "version": "1" },
"allowedgroups": [ "administrationgroup", "teachergroup", "managergroup" ],
"get": {
"request": {
"parameters": []
},
"query": {
"sql": "select id, name, amount, duedate FROM requestv1;"
},
"table": {
"title": "My table",
"fields": [
{"headline": "Name", "sqlfield": "name"},
{"headline": "Amount", "sqlfield": "amount"},
{"headline": "Due date", "sqlfield": "duedate"}
],
"actions": [
{"label": "Info", "resource": "inforequest", "parameters":[{"name": "id", "sqlfield": "id"}] },
{"label": "Edit", "resource": "formrequest", "parameters":[{"name": "id", "sqlfield": "id"}] },
{"label": "Delete", "resource": "deletereport", "parameters":[{"name": "id", "sqlfield": "id"}] }
]
}
}
}
If you can use the standard templates you can make an entire application just filling the src/Custom folder with all the resources you need. Open that folder and have a look so you can see how the other resources are defined.
Static check using phpstan
vendor/bin/phpstan --memory-limit=1G analyse src
fabiomattei/uglyduckling 适用场景与选型建议
fabiomattei/uglyduckling 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.05k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 「design」 「software」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fabiomattei/uglyduckling 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fabiomattei/uglyduckling 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fabiomattei/uglyduckling 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel package for the Repository Design Pattern.
Symfony bundle for broadway/broadway.
AI Content Translation for Laravel powered by SharpAPI.com
AI SEO Meta Tag Generator for Laravel powered by SharpAPI.com
A Software Development Kit for Silverstripe Search
A PHP console tool to generate Markdown documentation from your docblocks and types hints using templates.
统计信息
- 总下载量: 2.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2019-07-20