承接 rceman/copper 相关项目开发

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

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

rceman/copper

Composer 安装命令:

composer require rceman/copper

包简介

The Copper PHP Framework

关键字:

README 文档

README

Copper is a PHP Framework that is mainly focused on simplicity and development speed

Versions:

Developed and Maintained by Anton (therceman) - Web Developer and Security Researcher / Bug Bounty Hunter

Twitter Bugcrowd HackerOne StackOverflow Medium Reddit

Documentation For v1.0

See The Copper Skeleton for a minimal and empty Copper v1.0 app which you can base your new apps on

Installation

composer require rceman/copper

Folder Structure

 /
  - config
    - routes.php
  - public
    - index.php
  - src
    - Controller
      - HomeController.php
  - templates
    - index.php

Configuration (Getting Started)

create file /public/index.php

<?php

require dirname(__DIR__) . '/vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;

$kernel = new Copper\Kernel();
$kernel->handle(Request::createFromGlobals())->send();

create file /public/.htaccess

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /index.php/
    </IfModule>
</IfModule>

Configuration (Advanced)

update file /composer.json

{
    ...
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    }
}

run console command

composer update

create file /templates/index.php

<?php /** @var \Copper\Component\Templating\ViewHandler $view */ ?>

<?= $view->render('header') ?>

<body>
<h4><?= $view->out($view->dataBag->get('message')) ?></h4>
</body>

create file /src/Controller/HomeController.php

<?php

namespace App\Controller;

use Copper\Controller\AbstractController;

class HomeController extends AbstractController
{
    public function getIndex()
    {
        $parameters = [
            'head_title' => 'App :: Home',
            'head_meta_description' => 'Application based on Copper PHP Framework',
            'head_meta_author' => '{enter your name here}',
            'message' => 'Welcome to your Application!'
        ];

        return $this->viewResponse('index', $parameters);
    }
}

create afile /config/routes.php

<?php

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

use App\Controller\HomeController;

return function (RoutingConfigurator $routes) {
    $routes->add('index', '/')
        ->controller([HomeController::class, 'getIndex'])
        ->methods(['GET']);
};

Configuration (Optional)

create file /.gitignore

vendor/
composer.lock
composer.phar

Framework modules

  • Routes config module (using config/routes.php)
  • Controller module (using Controller/*Controller.php)
  • View (Templating) module (using templates/*.php)

Routes config module :: Classes

Classes

  • [RoutingConfigurator] (Symfony) - Routing Configurator
    • Instances
      • $routes - default instance
    • Methods (basic)
      • ->add($name, $path) - Adds a route.
        • ->controller($controller) - Adds controller to a route.
        • ->methods($methods) - Sets the HTTP methods (e.g. 'POST') this route is restricted to
        • ->requirements($requirements) - Adds route requirements (e.g. ['page' => '\d+'])
        • ->defaults($defaults) - Adds route defaults (e.g. ['page' => 1])

View (Templating) module :: Variables, Methods and Classes

Variables

  • $view->request_method - Request method GET or POST
  • $view->request_uri - Request uri
  • $view->client_ip - Client's IP address
  • $view->controller_name - Controller name
  • $view->route_name - Route name

Methods

  • $view->routeBag->get($key, $default = null) - Route parameter by key
  • $view->postBag->get($key, $default = null) - POST parameter by key
  • $view->queryBag->get($key, $default = null) - GET parameter by key
  • $view->cookiesBag->get($key, $default = null) - Cookies parameter by key
  • $view->dataBag->get($key, $default = null) - Template parameter by key
  • $view->out($value) - Escape HTML code and output as string
  • $view->out($array) - Escape HTML code and output as formatted array
  • $view->render($template) - Render template
  • $view->relativePath($name, $parameters = []) - Returns the relative Path to named route
  • $view->networkPath($name, $parameters = []) - Returns the network Path to named route
  • $view->url($name, $parameters = [], $withScheme = false) - Returns the URL to named route

Classes

  • [ViewOutput] - Output processor (escape, format, etc.)
    • Instances
      • $view->output - default instance
    • Methods
      • ->raw($value) - Output as string (no escape)
      • ->js($value) - Escape Javascript code and output as string
      • ->json($array) - Format Array as JSON string (no escape)
      • ->text($value) - Escape HTML code and output as string
      • ->dump($array) - Escape HTML code and output as formatted array
  • [ParameterBag] (Symfony) - Collection of Request parameters
    • Instances
      • $view->routeBag - Route parameters (iterable)
      • $view->postBag - POST parameters (iterable)
      • $view->queryBag - GET parameters (iterable)
      • $view->cookiesBag - Cookies parameters (iterable)
      • $view->dataBag - Template parameters (iterable)
    • Methods (basic)
      • ->all() - Returns an array with parameters
      • ->get($key) - Returns a parameter by name
      • ->set($key, $value) - Sets a parameter by name
      • ->has($key) - Returns true if the parameter is defined
      • ->remove($key) - Removes a parameter
      • ->getInt($key, $default = 0) - Returns the parameter value converted to integer
      • ->getBoolean($key, $default = false) - Returns the parameter value converted to boolean

Controller module :: Methods and Classes

Methods

  • $this->viewResponse($view, $parameters = []) - Returns a Response with rendered view
  • $this->renderView($view, $parameters = []) - Returns a rendered view
  • $this->response($data, $status = 200, $headers = []) - Returns a HTTP Response
  • $this->json($data, $status = 200, $headers = []) - Returns a JsonResponse that uses json_encode
  • $this->redirectToRoute($route, $parameters = [], $status = 302) - Returns a RedirectResponse to the given route
  • $this->redirect($url, $status = 302) - Returns a RedirectResponse to the given URL

Classes

  • [Request] (Symfony) - Request represents an HTTP request
    • Instances
      • $this->request - default instance
  • [RequestContext] (Symfony) - Holds information about the current request
    • Instances
      • $this->requestContext - default instance
  • [RouteCollection] (Symfony) - A RouteCollection represents a set of Route instances
    • Instances
      • $this->routes - default instance

rceman/copper 适用场景与选型建议

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

它主要适用于以下技术方向: 「framework」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-24