承接 totallyquiche/crudy 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

totallyquiche/crudy

Composer 安装命令:

composer require totallyquiche/crudy

包简介

A proof-of-concept MVC framework.

README 文档

README

CRUDy preview

CRUDy is a proof-of-concept PHP framework with no dependencies.

But why?

For fun, of course! After all, learning is FUNdamental! 🌈

CRUDy is helping me hone my PHP skills and understand more about the concepts popular PHP frameworks are built on.

CRUDy is not meant to be used in production. CRUDy development starts with the naive approach instead of with existing standards (e.g. PSR). I then develop these implementations over time as I learn the pros and cons of different patterns. Compatibility, performance, and even security are not priorities and are not guaranteed.

Feedback is still welcome! You can even open up a Pull Request if you'd like. :smile:

Features

  • Autoloading
  • Page caching
  • Environment variables (.env)
  • Database Abstraction Layer (DBAL)
  • Headless execution
  • MVC architecture
  • Routing
  • Templates
  • Testing

Getting Started

  1. Clone the repo: git clone git@github.com:totallyquiche/CRUDy.git
  2. Create your config file: cp .env.example .env
  3. Start your PHP server: php -S localhost:80
  4. Open http://localhost in your browser

Technically, that's it! CRUDy is up and running! But you probably want to do more than that...

Create a New Page

Add a new route to the $routes array in ./App/Http/routes.php. You can either specify a controller and method or an anonymous function. The method/function you define should return a string (this is what gets rendered).

$routes = [
    '/' => 'HomeController::index'
];
$routes = [
    '/' => fn() => 'Hello, World!'
);

Create a Controller

Create a new class in App/Controllers/Http that extends App\Http\Controllers\HttpController. The class name should end with Controller (e.g. HomeController). The file name should be the class name plus .php (e.g. HomeController.php).

The controller should contain methods matching any register routes you have. For example, if I have registerd a route referencing HomeController::index, then I should have a controller named HomeController with a method named index() which returns a string.

Create a View

Create a new .php file in App/View/Templates. Load the view from your controller by calling $this->renderView($view_name, $args) in the controller method.

The first parameter is the name of the view (without .php). The second parameter is an optional array of data to be passed to the view. The key/value pairs in the array are turned into variables with assigned values.

For example, calling the below method call will result in the the show_object view (App/View/Templates/show_object.php) being loaded. The view will have access to a variable called $object_name with the value Object Name;

$this->renderView('show_object', [
    'object_name' => 'Object Name';
]);

A values in $args can also be a Callable. For example, calling the method below will give the view access to a variable called $message with the value Hello, World!:

$this->renderView('view_name', [
    'message' => fn() => return 'Hello, World!',
]);

Templates

Templates may be used to support a type of single-inheritance View in which the string {{ 💩 }} in the Template is replaced with the contents of the View.

Using a Template

To use a Template, ensure that the first line of your View file contains a string like {{ TEMPLATE_NAME }}, wherein TEMPLATE_NAME is the file name of the Template without .php. For example, the following View would utilize a template located at App\View\Templates\page.php:

{{ page }}
<h1>Hello, World!</h1>

Creating a Template

Templates are files with names matching [a-zA-Z]+\.php (e.g. page.php) and live in App\View\Templates. The should contain a single placeholder, {{ 💩 }} for embedding View within them. For example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $site_title ?></title>
</head>
<body>
    {{ 💩 }}
</body>
</html>

which, with the following View...

{{ page }}
<h1>Hello, World!</h1>

...results in the following being rendered:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $site_title ?></title>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

View Caching

After a View has been fully compiled, it is written to a cache located at ./App/View/Templates/Cache. That cached file is used each time the corresponding page is requested until the cache period expires (the number of seconds the VIEW_CACHE_SECONDS_TO_EXPIRY environment variable is set to).

Testing

Writing Tests

Create a new class in ./App/Tests that extends App\Tests\Test. The class name should end with Test (e.g. HomeControllerTest). The file name should be the class name plus .php (e.g. HomeControllerTest.php).

Your test methods should be public, should start with test_, and should return a boolean indicating whether the test passed.

public function test_that_true_is_true() : bool
{
    return true === true;
}

Running Tests

As long as you follow the above naming conventions, your tests will be run automatically through the following command:

php index.php tests:run

You can run specific tests by passing in their name as arguments:

php index.php tests:run "App\Tests\ModelTest" "App\Tests\RouterTest"

Test results

After running your tests, you will see the results printed to the screen.

Each test cass will be displayed starting with Passed or Failed. The total pass/fail counts will be displayed at the end.

Test results example

totallyquiche/crudy 适用场景与选型建议

totallyquiche/crudy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 10 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 totallyquiche/crudy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 totallyquiche/crudy 我们能提供哪些服务?
定制开发 / 二次开发

基于 totallyquiche/crudy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-10