PHPackages                             ntch/pocoapoco - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. ntch/pocoapoco

ActiveLibrary[Framework](/categories/framework)

ntch/pocoapoco
==============

Pocoapoco Framework.

v4.1.0(2y ago)021MITPHPPHP ^8.0

Since Apr 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Homeeat/Pocoapoco)[ Packagist](https://packagist.org/packages/ntch/pocoapoco)[ RSS](/packages/ntch-pocoapoco/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (9)Used By (0)

[![Pocoapoco](https://github.com/Homeeat/Pocoapoco/raw/main/src/Image/Pocoapoco_black.jpg)](#)

[![PHP Version](https://camo.githubusercontent.com/aaba3909a30b7f2eab0806450344de7a0117dbb8a062992f609086394afcac67/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344372e302d626c7565)](#)[![License](https://camo.githubusercontent.com/514010af57abd0ea03cb5830bcac1e3edadfac0b8251b0466e7a0a9911c72940/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d495425323025324225323066696c652532304c4943454e53452d626c7565)](#)

Pocoapoco 框架
------------

[](#pocoapoco-框架)

---

Pocoapoco框架是由國家兩廳院資訊組，針對自家開發需求撰寫而成，透過簡單路由引擎加上 MVC 架構概念，做到程式碼的輕易控管。

框架安裝及部署
-------

[](#框架安裝及部署)

---

### **- 安裝**

[](#--安裝)

composer：

```
composer require ntch/pocoapoco
```

### **- 伺服器**

[](#--伺服器)

伺服器使用 Nginx，其設定檔（nginx.conf）範例如下：

```
# 需自行調整參數
# web_basic -> 專案名稱（執行 composer 的地方）

server {
        listen 60000;
        root   /{web_basic}/src/public/;
        index  index.html index.htm index.php;
        location /NTCH/ {
            alias /{web_basic}/vendor/ntch/pocoapoco/src/;
            location ~ \.php$ {
                fastcgi_pass 127.0.0.1:30001;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                fastcgi_param DOCUMENT_ROOT $document_root;
                fastcgi_param PROJECT_ROOT /{web_basic}/src/;
                fastcgi_param ENVIRONMENT :ENV
            }
        }
        location / {
            try_files $uri /NTCH/Bootstrap.php$is_args$args;
        }
    }
```

目錄結構
----

[](#目錄結構)

---

```

pocoapoco（your projects）
│
└─── src（your code)
│    │
│    │─── controllers
│    │
│    │─── libraries
│    │
│    │─── log
│    │
│    │─── models
│    │
│    │─── public
│    │
│    │─── routes
│    │
│    │─── settings
│    │
│    └─── view
│
└─── vendor（require package）
│
│  composer.json
│  composer.lock

```

學習
--

[](#學習)

---

> ### **router**
>
> [](#router)

資料夾：routes
檔案：router.php

&lt; routes 起手式 &gt;

```
use Ntch\Pocoapoco\WebRestful\Routing\Router;

$router = new Router();
```

&lt; 可用路由的方法 &gt;

```
$router->controller($uri, $path, $file, $method);

$router->view($uri, $path, $file, $data);

$router->public($path, $file);

$router->mix($uri,
    [
        'controller' => [$path, $file],
        'libraries' => [$libraryName],
        'log' => ['$logName'],
        'mails' => ['$mailName'],
        'aws' => ['$awsName'],
        'models' => ['$nickname'],
    ]);

// example
$router->controller('/uri/:parameter', '/path', 'class', 'method');

$router->view('/uri/:parameter', '/path', 'class', ["pocoapoco" => "framework"]);

$router->public('/path', 'index.html');

$router->mix('/uri/:parameter',
    [
        'controller' => ['/path', 'class', 'method'],
        'libraries' => ['name'],
        'mails' => ['name'],
        'aws' => ['name'],
        'models' => ['name'],
    ]);
```

方法說明controller轉向 controller 方法view轉向 view 方法public轉向 public 方法mix需要引入 model 和 library 等物件並轉向 controller 方法＊model 提供的類型再請參考 model 的文件

參數型態說明uristring請求的網址，加 '：' 及代表此為參數pathstring請求導向執行檔案的路徑filestring執行檔案名稱methodstring執行檔案中的方法名稱，預設 indexdataarray要傳入的參數＊注意：重複符合的 uri ，以上面的為主。
＊建議：常用功能方法往上放，能加速執行速度。

> ### **controller**
>
> [](#controller)

資料夾：controllers
檔案：xxx.php

&lt; controllers 起手式 &gt;

```
use Ntch\Pocoapoco\WebRestful\Controllers\Controller;
# 如要導向 view 請把 Router 導入
use Ntch\Pocoapoco\WebRestful\Routing\Router;

class xxx extends Controller
{
    public function index()
    {
        $router = new Router();
        $router->view(null, '/path', 'class', array("name" => "Pocoapoco"));
    }
}
```

&lt; request 提供的物件 &gt;

```
# $this->request

[request] => stdClass Object
        (
            [uuid] => 10AEF2B9-D783-2CAA-8E07-6BDC2EF83117
            [method] => GET
            [uri] => Array
                (
                    [a] => 1
                    [b] => 2
                    [c] => 3
                )

            [query] => Array
                (
                    [name] => Pocoapoco
                )

            [input] =>
            [attribute] => Array
                (
                )

            [authorization] => Array
                (
                )

            [cookies] => Array
                (
                    [php] => omfb5668s9i952d05gdbckp1ej
                )

            [files] => Array
                (
                )

            [client] => Array
                (
                    [ip] => 172.0.0.0
                    [port] => 60505
                )

            [time] => Array
                (
                    [unix] => 1643257668.4144
                    [date] => 2022-01-01
                    [time] => 12:00:00
                )

            [headers] => Array
                (
                )

        )

```

參數說明uuid每次請求的獨立唯一編號method請求方法urirouter 設定的參數queryGET 方法代入的參數attributePOST 方法代入的參數authorizationherder 中的 tokencookies請求帶入的 cookiefilesinput 上傳的 fileclient請求來源time請求時間headers請求 header> ### **setting**
>
> [](#setting)

資料夾：settings
檔案：xxx.ini

- 檔案讀取順序：先讀取 settings 根目錄，再依據 Nginx ENVIRONMENT 設定讀取，若名稱重複做覆蓋。

- libraries.ini：libraries 命名與載入層級設定，實際引入由 router 載入
- mails.ini：郵件參數設定
- aws.ini：aws iam 參數設定
- error.ini：開發與正式上線參數設定
- log.ini：log 參數設定
- project.ini：專案共用參數設定
- models.ini：資料庫參數設定

&lt; settings 起手式 &gt;

```
# libraries.ini
[name]
path      = /path（要載入至哪個路徑下的所有檔案）
models    = nickname (models.ini)
mails     = server_name (mail.ini)
aws       = user (aws.ini)

# 檔名：mails.ini
[name]
Host        = pocoapoco.com
Port        = 25
Username    = pocoapoco
Password    = xxxxxxxxx
SMTPAuth    = true|false
SMTPSecure  = tls|ssl
CharSet     = utf-8
SMTPDebug   = 1|0
Timeout     = 5

# 檔名：aws.ini
[name]
version  = latest
region   = ap-northeast-1
key      = pocoapoco
secret   = xxxxxxxxx

# 檔名：error.ini
[MAIN]
debug                = 1|0
page_4xx             = 4xx.html
page_5xx             = 5xx.html
mail_from            = server@pocoapoco.com
mail_to              = royhylee@mail.npac-ntch.org:ROY
mail_server          = mail.ini-name

[PAGE]
E_EXCEPTION          = 1
E_ERROR              = 1
E_WARNING            = 0
E_PARSE              = 1
E_NOTICE             = 0
E_CORE_ERROR         = 1
E_CORE_WARNING       = 1
E_COMPILE_ERROR      = 1
E_COMPILE_WARNING    = 1
E_USER_ERROR         = 1
E_STRICT             = 1
E_RECOVERABLE_ERROR  = 1
E_DEPRECATED         = 1
E_USER_DEPRECATED    = 1
E_ALL                = 1

[MAIL]
E_EXCEPTION          = 1
E_ERROR              = 1
E_WARNING            = 1
E_PARSE              = 1
E_NOTICE             = 1
E_CORE_ERROR         = 1
E_CORE_WARNING       = 1
E_COMPILE_ERROR      = 1
E_COMPILE_WARNING    = 1
E_USER_ERROR         = 1
E_STRICT             = 1
E_RECOVERABLE_ERROR  = 1
E_DEPRECATED         = 1
E_USER_DEPRECATED    = 1
E_ALL                = 1

# 檔名：log.ini
[name]
file = class
folder = /path（絕對路徑）

# 檔名：project.ini
[name]
key = value

# 檔名：models.ini
[server_name]
type      = server
driver    = oracle|mysql|mssql|postgres
ip        = xx.xx.xx.xx
port      = 1521
sid       = oracle
user      = pocoapoco
password  = xxxxxxxxx
path      = /path
class     = class

[tb_name]
type    = table
server  = server_name
schema  = schema_name
table   = tb
path    = /path
class   = class
```

> ### **library**
>
> [](#library)

資料夾：libraries
檔案：xxx.php

&lt; library 起手式 &gt;

```
# 依據 PSR-4 命名規則，給予路徑
namespace libraries\la\lb\lc;

class xxx
{
    public function index()
    {
        echo 'library import success！' . PHP_EOL;
    }
}
```

&lt; setting 定義別名 &gt;

```
[lib]
path = /la
```

&lt; router 檔案引入至 controller 使用 &gt;

```
$router->mvc('/uri',
    [
        'controller' => ['/path', 'class'],
        'libraries' => ['lib']
    ]);
```

&lt; controller 使用 &gt;

```
use Ntch\Pocoapoco\WebRestful\Controllers\Controller;
use la\lb\lc\xxx;

class test extends Controller
{
    public function index()
    {
        $lib = new xxx();
        $lib->index();
    }
}
```

> ### **model**
>
> [](#model)

資料夾：models
檔案：xxx.php

＊提供類型：Oracle、Mysql、Mssql、Postgres

&lt; model 起手式 &gt;

```
use Ntch\Pocoapoco\WebRestful\Models\Model;

class model_demo extends Model
{
    public function schema()
    {
        $schema['COLUMN_NAME'] = [
            'DATA_TYPE' => '',
            'DATA_SIZE' => '',
            'NULLABLE' => '',
            'DATA_DEFAULT' => '',
            'KEY_TYPE' => '',
            'COMMENT' => '',
            'SYSTEM_SET' => ''
        ];

        return $schema;
    }
}
```

參數說明必填內容DATA\_TYPE欄位型別是各別資料庫如下說明DATA\_SIZE欄位大小否時間參數依各資料庫 format 格式，提供：年、月、日、時、分、秒NULLABLE是否為空值否預設為否DATA\_DEFAULT預設值否預設為 nullKEY\_TYPE鍵值否P：主鍵COMMENT敘述否SYSTEM\_SET系統設定，做 CRUD 時會自動代入否PRIMARY\_KEY：主鍵 , UPDATE\_DATE：更新時間
- Oracle 提供的 DATA\_TYPE

    - CHAR
    - NCHAR
    - VARCHAR2
    - NVARCHAR2
    - NCLOB
    - FLOAT
    - NUMBER
    - DATE
    - TIMESTAMP
    - TIMESTAMP WITH TIME ZONE
    - TIMESTAMP WITH LOCAL TIME ZONE
- Mysql 提供的 DATA\_TYPE

    - char
    - varchar
    - tinyint
    - smallint
    - mediumint
    - bigint
    - int
    - float
    - decimal
    - timestamp
    - datetime
    - date
    - time
    - year
- Mssql 提供的 DATA\_TYPE

    - char
    - varchar
    - nchar
    - nvarchar
    - tinyint
    - smallint
    - bigint
    - int
    - float
    - decimal
    - datetime
    - date
- Postgres 提供的 DATA\_TYPE

    - char
    - varchar
    - uuid
    - bool
    - date
    - inet
    - json
    - float
    - decimal
    - integer
    - bigint
    - smallint
    - timestamp
    - timestamptz
    - xml

&lt; setting 設定檔定義別名 &gt;

```
[server_name]
type      = server
driver    = oracle|mysql|mssql|postgres
ip        = xx.xx.xx.xx
port      = 1521
sid       = oracle
user      = pocoapoco
password  = xxxxxxxxx
path      = /path
class     = class

[tb_name]
type    = table
server  = server_name
schema  = schema_name
table   = tb
path    = /path
class   = class
```

&lt; router 檔案引入至 controller 使用 &gt;

```
$router->mvc('/uri',
    [
        'controller' => ['/path', 'class'],
        'models' => ['nickname']
    ]);
```

＊server 為撈出該 database 所有 table，非必要引入

&lt; controller 使用 &gt;

```
use Ntch\Pocoapoco\WebRestful\Controllers\Controller;

class test extends Controller
{
    public function index()
    {
        # model 導入
        $model = $this->model['nickname'];

        # ORM 架構
        # createTable 範例
        $sql = $model->createTable();

        # commentTable 範例
        $sql = $model->commentTable();

        # select 範例
        $data = $model->select(['a', 'b', 'SUM(c)' => 'c'])->
        where(['b' => 1])->groupby(['a', 'b'])->
        orderby(['a'])->query();

        # insert 範例
        $data = $model->insert()->values(['a' => 1])->query();

        # update 範例
        $data = $model->update()->set(['a' => 1])->where(['b' => 2])->query();

        # delete 範例
        $data = $model->delete()->where(['a' => [1, '>']])->query();

        # merge 範例 - 僅提供 Oracle 使用
        $data = $model->merge()->using('user', 'table')->on("a", "b")->
                    matched()->update()->set(['c' => 'c', 'd' => 'd'])->
                    not()->insert()->value()->query();

        # commit 範例
        $model->commit();

        # rollback 範例
        $model->rollback();

        # 筆數限制 - 第 5 筆開始顯示 8 筆
        # Oracle 範例 - 若兩個方法皆要使用 offset() limit() 順序可顛倒
        $data = $model->select()->offset(5)->limit(8)->query();

        # Mysql 範例 - 若兩個方法皆要使用 limit() offset() 順序可顛倒
        $data = $mysql->select()->limit(8)->offset(5)->query();

        # Mssql 範例 - 兩種方法
        $data = $mssql->select()->top(8)->query();
        $data = $mssql->select()->groupby()->offset(5)->fetch(8)->query();

        # Postgres 範例 - 若兩個方法皆要使用 limit() offset() 順序可顛倒
        $data = $postgres->select()->limit(8)->offset(5)->query();
    }
}
```

- 通用方法
    - createTable()
    - commentTable() // Mysql 不適用
    - insert()
    - values($values)
    - delete()
    - update()
    - set($set)
    - select($select)
    - select\_distinct($select)
    - where($where)
    - orderby($orderby)
    - groupby($groupby)
    - query()
    - query\_pass() // 不檢查 model schema
    - commit()
    - rollback()
    - keyName($keyName) (指定 key 欄位)
    - dataBind() // 將 array key 與 colname 相同的值合併至 model

參數型態說明valuesarray\[ '欄位名稱' =&gt; 值 \]setarray\[ '欄位名稱' =&gt; 值 \]selectarray一維陣列填入欄位名稱, 二維陣列 value 視為別名(as)wherearray\[ '欄位名稱' =&gt; 值 \] or \[ '欄位名稱' =&gt; \[值, 關係運算子\] \]orderbyarray一維陣列填入欄位名稱groupbyarray一維陣列填入欄位名稱keyNamestring指定返回的值的 keyuserNamestring使用者名稱tableNamestring表名稱targetstring目標比對欄位sourcestring來源比對欄位> ### **log**
>
> [](#log)

&lt; log 使用 &gt;

```
# 依據 PSR-3 規則，給予層級

$this->log($level, $message, $info);

// example
$this->log('INFO', 'message', ['name' => 'pocoapoco']);
```

參數型態說明levelstring依據 PSR-3 規則，給予層級messagestring主要訊息標題infoarray要記錄的資訊> ### **mail**
>
> [](#mail)

&lt; mail 使用 &gt;

```
$res = $mailer->header($header)->
                from($from)->
                to($to)->
                subject($subject)->
                content($source, $type, $content, $data)->
                send();

// example
$mailer = $this->mail['mailer'];

$header = ['ID' => 'xxxxxxxx'];
$from = ['server@pocoapoco.com' => 'POCOAPOCO'];
$to = ['royhylee@mail.npac-ntch.org' => 'ROY LEE'];

$res = $res = $mailer->header($header)->
                from($from)->
                to($to)->
                subject('test')->
                content('local', 'html', '/path/error.php', ['error' => 'message'])->
                send();
```

- 方法
    - header($header)
    - from($from)
    - to($to)
    - subject($subject)
    - content($source, $type, $content, $data)
    - attachment($source, $attachment)
    - image($path, $cid, $name)
    - send()

參數型態說明headerarray信件表頭fromarray寄件人 \[ '信箱' =&gt; '寄件人名稱' \]toarray收件人 \[ '信箱' =&gt; '收件人名稱' \]subjectstring信件標題sourcestring資料來源 content =&gt; user|url|local , attachment =&gt; url|localtypearraytext|htmlcontentstring信件內容，依 $content 帶入的值分別給予 text|uri|pathdataarray使用 view 中的檔案，要帶入的參數attachmentstring信件內容，依 $content 帶入的值分別給予 uri|pathpathstring圖片位置 uri|pathcidstring圖片別名namestring圖片名稱> ### **aws**
>
> [](#aws)

&lt; aws 使用 &gt;

```
$aws = $this->aws['name'];

// example
$aws->s3_exist('bucket', '/aws_path', 'aws_file.txt', ['key' => 'xxxxxxxxxxxx', 'md5' => 'oooooooooooo']);

$aws->s3_list('bucket');

$aws->s3_upload('bucket', '/aws_path', 'aws_file.txt', '/local_path', 'local_file.txt', 2, 1)

$aws->s3_read('bucket', '/aws_path', 'aws_file.txt', ['key' => 'xxxxxxxxxxxx', 'md5' => 'oooooooooooo'])

$aws->s3_download('bucket', '/aws_path', 'aws_file.txt', '/local_path', 'local_file.txt', ['key' => 'xxxxxxxxxxxx', 'md5' => 'oooooooooooo'])

$aws->s3_copy('source_bucket', '/source_path', 'source_file.txt', 'target_bucket', '/target_path', 'target_file.txt')

$aws->s3_delete('bucket', '/aws_path', 'aws_file.txt', ['key' => 'xxxxxxxxxxxx', 'md5' => 'oooooooooooo']);

$aws->s3_get('bucket', '/aws_path', 'aws_file.txt', 5, ['key' => 'xxxxxxxxxxxx', 'md5' => 'oooooooooooo']);
```

- 方法
    - s3\_exist($bucket, $awsPath, $awsFile, $sseKey)
    - s3\_list($bucket)
    - s3\_upload($bucket, $awsPath, $awsFile, $localPath, $localFile, $security, $download)
    - s3\_read($bucket, $awsPath, $awsFile, $sseKey)
    - s3\_download($bucket, $awsPath, $awsFile, $localPath, $localFile, sseKey)
    - s3\_copy($sourceBucket, $sourcePath, $sourceFile, $targetBucket, $targetPath, $targetFile)
    - s3\_delete($bucket, $awsPath, $awsFile, $sseKey)
    - s3\_get($bucket, $awsPath, $awsFile, $effectTime, $sseKey)

參數型態預設說明bucketstringaws s3 桶子名稱awsPathstringaws s3 桶子路徑awsFilestringaws s3 桶子文件名稱localPathstring地端路徑localFilestring地端檔案名稱securityint1：public 2：private 3：sse encryptionsseKeyarray\[\]\[ 'key' =&gt; '值', 'md5' =&gt; '值' \]downloadint00：show on web 1：download filesourceBucketstringaws s3 來源桶子名稱sourcePathstringaws s3 來源桶子路徑sourceFilestringaws s3 來源桶子文件名稱targetBucketstringaws s3 目標桶子名稱targetPathstringaws s3 目標桶子路徑targetFilestringaws s3 目標桶子文件名稱effectTimeint網址有效時間（分鐘）-1：永久公開

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 58.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~89 days

Recently: every ~151 days

Total

8

Last Release

852d ago

Major Versions

v1.0.3 → v3.1.02023-02-16

v3.1.0 → v4.0.22023-11-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/66c630a5e0b1a0342e945ad4c470fd0391ae04c444b11bf421bbff93fefaed0c?d=identicon)[Homeeat](/maintainers/Homeeat)

![](https://www.gravatar.com/avatar/c902ffaf6962bff2a6030fcf7128db657299ce3d046999603126e50a1ff44a57?d=identicon)[Bo-Ray](/maintainers/Bo-Ray)

---

Top Contributors

[![Homeeat](https://avatars.githubusercontent.com/u/25120172?v=4)](https://github.com/Homeeat "Homeeat (25 commits)")[![Bo-Ray](https://avatars.githubusercontent.com/u/102424984?v=4)](https://github.com/Bo-Ray "Bo-Ray (17 commits)")[![4yuinfo](https://avatars.githubusercontent.com/u/1540218?v=4)](https://github.com/4yuinfo "4yuinfo (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ntch-pocoapoco/health.svg)

```
[![Health](https://phpackages.com/badges/ntch-pocoapoco/health.svg)](https://phpackages.com/packages/ntch-pocoapoco)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.3k86.3M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[laravel/nightwatch

The official Laravel Nightwatch package.

3486.1M13](/packages/laravel-nightwatch)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

81733.7k](/packages/flow-php-flow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
