191 composer 使用國內映象 / 釋出自己的package / 個人專案中使用composer
使用國內映象
開啟命令列視窗(windows使用者)或控制檯(Linux、Mac 使用者)並執行如下命令:
composer config -g repo.packagist composer https://packagist.phpcomposer.com
釋出自己的package
1.在github上建立自己的專案,例如:helloworld
2.將專案通過git克隆到本地,建立composer.json
3.commit並push到github上
4.到https://packagist.org/ 上點選右上角”submit package”,需要登入,點選”login with github”使用github賬號登入即可,初次登入會讓你登記郵箱,完了再次點選”submit package”。
5.填寫專案地址”Repository URL”,這個url就是你github上helloworld專案的url。
6.點選”check”按鈕,系統自動檢測你的專案中composer.json是否合格,並給出原因。如果沒有錯誤的話,請點選提交。
7.包建立成功,可以根據提示繼續配置github自動同步功能,這樣每次push後,packagist對應包的版本號也會更新。
8.修改包並更新,修改後git push,然後到使用該包的專案中執行composer –dev –prefer-source update [包名] ,加–prefer-source意思是從github上檢出最新版本。
個人專案中使用composer
我們這裡建議一個專案demo, 然後我們在demo目錄下執行:
composer require illuminate/database:~4.2
那麼你應該會看到:
Using version ~4.2 for illuminate/database
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing nesbot/carbon (1.13 .0)
Loading from cache
- Installing illuminate/support (v4.2.9)
Downloading: 100%
Downloading: 100%
Downloading: 100%
Failed, trying the next URL
Downloading: 100%
- Installing illuminate/container (v4.2.9)
Downloading: 100%
- Installing illuminate/events (v4.2.9)
Downloading: 100%
- Installing illuminate/database (v4.2.9)
Downloading: 100%
Writing lock file
Generating autoload files
這樣就表示Eloquent已經安裝好了。
配置
下面我們來配置Eloquent。
首先我們建立一個入口檔案,如果你的專案已經有內容,那麼同理在你的專案入口檔案加入即可:
demo/start.php:
<?php
// 載入composer的autoload檔案
include __DIR__ . '/vendor/autoload.php';
然後我們加入資料庫配置:
$database = [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'demo',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
];
上面我們的資料庫配置,庫名demo,使用者名稱root,密碼為空,這個demo是我在mysql裡建立好的空資料庫。
然後我們加入Eloquent初始化程式碼:
use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
// 建立連結
$capsule->addConnection($database);
// 設定全域性靜態可訪問
$capsule->setAsGlobal();
// 啟動Eloquent
$capsule->bootEloquent();
那麼Eloquent就配置完成了。
解決一下問題:
Cannot adopt OID in SQUID-MIB: cacheClients ::= { cacheProtoAggregateStats 15 }
Cannot adopt OID in NET-SNMP-EXTEND-MIB: nsExtendLineIndex ::= { nsExtendOutput2Entry 1 }
Cannot adopt OID in NET-SNMP-EXTEND-MIB: nsExtendOutLine ::= { nsExtendOutput2Entry 2 }
Cannot adopt OID in UCD-SNMP-MIB: laIndex ::= { laEntry 1 }
Cannot adopt OID in UCD-SNMP-MIB: laNames ::= { laEntry 2 }
Cannot adopt OID in UCD-SNMP-MIB: laLoad ::= { laEntry 3 }
Cannot adopt OID in UCD-SNMP-MIB: laConfig ::= { laEntry 4 }
Cannot adopt OID in UCD-SNMP-MIB: laLoadInt ::= { laEntry 5 }
Cannot adopt OID in UCD-SNMP-MIB: laLoadFloat ::= { laEntry 6 }
Cannot adopt OID in UCD-SNMP-MIB: laErrorFlag ::= { laEntry 100 }
Cannot adopt OID in UCD-SNMP-MIB: laErrMessage ::= { laEntry 101 }
Cannot adopt OID in NET-SNMP-AGENT-MIB: nsNotifyRestart ::= { netSnmpNotifications 3 }
Cannot adopt OID in NET-SNMP-AGENT-MIB: nsNotifyShutdown ::= { netSnmpNotifications 2 }
Cannot adopt OID in NET-SNMP-AGENT-MIB: nsNotifyStart ::= { netSnmpNotifications 1 }
sudo apt-get install snmp-mibs-downloader
sudo apt-get update