phpbrew 沒辦法透過 ext install 的方式安裝 pdo_mysql。
若要安裝則需要在編譯 PHP 時直接將 pdo 和 mysql 加入編譯清單:
phpbrew install 7.4.0 +default +pdo +mysql
-->
phpbrew 沒辦法透過 ext install 的方式安裝 pdo_mysql。
若要安裝則需要在編譯 PHP 時直接將 pdo 和 mysql 加入編譯清單:
phpbrew install 7.4.0 +default +pdo +mysql
使用 Airlock 可以更輕鬆的支援 single page application (SPA)、token-based API 等等,同時也可以針對 token 設定可存取犯元 (scope)。 (感覺上類似 OAuth)
以往使用者從 Eloquent ORM 拉出資料以後,使用者可以自訂 cast type,也就是說可用者可以自動 cast attribute 成特定格式。範例可以參考 Laravel 的 Pull Request。
新增不少功能來 render HTML。詳細說明請參考 Larvel Docs。
為了史 API 更靈活,Laravel 使用 Guzzle HTTP client 來與其他 API 溝通。
透過新的方式來做 route 的 cache,即使大型網站 (800 routes) ,route matching 的速度也可以比以往快上 20 倍。
laravel v6.10.1 <= ramsey/uuid ^v3.7
ramsey/uuid <= paragonie/random_compat": "^1 | ^2 | 9.99.99"
APP_URL=http://zeroplex.tw
\URL::forceScheme('https');
alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your-password';
flush privileges;
[mysqld]
default-authentication-plugin = mysql_native_password
$table->foreign('good_id')
->references('id')
->on('goods')
->onDelete('cascade');
$table->index('value');
show create table NAME
<?php
use PHPUnit\Framework\TestCase;
class LibTest extends TestCase
{
public function setUp(): void
{
$this->data = null;
}
public function tearDown(): void
{
$this->data = null;
}
public function testOne()
{
$this->data = 123;
$this->assertEquals(123, $this->data);
return $this->data;
}
/**
* @depends testOne
*/
public function testTwo($data)
{
$this->assertEquals(123, $this->data);
}
}
// -----
PHPUnit 8.2.3 by Sebastian Bergmann and contributors.
.F
class TargetController extends Controller
{
public function doSomething(Request $req)
{
// do something ....
}
}
$req = new \lluminate\Http\Request();
$ctrl = new TargetController()
$result = $ctrl->doSomething($req);
$request->replace([
'key' => 'value',
]);
$c = new Memcache();
$stat = $c->connect('localhost');
if (false === $stat) {
echo 'connection failed';
} else {
echo 'connected to cache server';
}
Warning: Memcache::connect(): Can't connect to localhost:11211, Connection refused (111) in /home/u/he5702/tmp/asd.php on line 4
Call Stack:
0.0001 355600 1. {main}() /home/u/he5702/tmp/asd.php:0
0.0001 355640 2. Memcache->connect() /home/u/he5702/tmp/asd.php:4
connection failed
$stat = @$c->connect('localhost');
$q = new SplPriorityQueue();
$q->insert(1, 'A');
$q->insert(2, 'B');
$q->insert(3, 'C');
$q->insert(4, 'D');
$q->insert(5, 'E');
while ($q->count() > 0) {
echo $q->extract() . PHP_EOL;
}
5
4
3
2
1
$q = new SplPriorityQueue();
$q->insert(1, 1);
$q->insert(2, 1);
$q->insert(3, 1);
$q->insert(4, 1);
$q->insert(5, 1);
while ($q->count() > 0) {
echo $q->extract() . PHP_EOL;
}
1
5
4
3
2
Psy Shell v0.8.18 (PHP 7.1.18 — cli) by Justin Hileman
Unable to check for updates
>>> $q = new SplPriorityQueue();
=> SplPriorityQueue {#201
heap: [],
}
>>> $q->insert(1, [1, 2, 3]);
=> true
>>> $q->insert(2, []);
=> true
>>> $q->insert(3, new Exception())
=> true
靠北啊,Exception 也可以當作 priority 使用 ....>>> while ($q->count() > 0) {
... echo $q->extract() . PHP_EOL;
... }
3
1
2
.... 我不想講了。$list = [
'200' => 'OK',
'404' => 'not found',
'500' => 'internal server error',
];
$keys = array_keys($list);
// array(3) {
// [0]=>
// int(200)
// [1]=>
// int(404)
// [2]=>
// int(500)
// }
>>> $m = new Memcache
=> Memcache {#201}
>>> $m->connect('localhost')
=> true
>>> $m->set('test', ['Hello', 'World'])
=> true
>>> $m->get('test')
=> [
"Hello",
"World",
]
>>> $d = new Memcached
=> Memcached {#198}
>>> $d->addServer('localhost', 11211)
=> true
>>> $d->getAllKeys()
=> [
"test",
]
>>> $d->get('test')
=> 0
$ phpunit Test.php
... Run by vendor/bin/phpunit ...
PHPUnit 7.1.5 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 30 ms, Memory: 4.00MB
OK (1 test, 1 assertion)
composer require 'phpunit/phpunit'
<?php
require __DIR__ . '/vendor/autoload.php';
use PHPUnit\TextUI\Command;
$cmd = new Command();
$cmd->run([
'phpunit', // 1st arg
'Test.php', // 2nd arg
]);
list($a, $b) = [1, 2];
// $a = 1, $b = 2
[$a, $b] = [1, 2];
[$b, $a] = [$a, $b];
$list = [];
$start = microtime(true);
for ($a = 0; $a < 10000000; $a++ ) {
array_push($list, 1);
}
$end = microtime(true);
var_dump($end - $start); // double(7.2292509078979)
$list = [];
$start = microtime(true);
for ($a = 0; $a < 10000000; $a++ ) {
$list[] = 1;
}
$end = microtime(true);
var_dump($end - $start); // double(2.0703480243683)
function assertSame($expected, $actual, string $message = ''): void
{
Assert::assertSame(...\func_get_args());
}
function add($a, $b) {
return $a + $b;
}
add(...[1, 2]); // $a = 1, $b = 2
// or ...
$args = [1, 2];
add(...$args);
class MyTest extends TestCase
{
public function testOne()
{
$GLOBALS['test'] = 123;
$this->assertArrayHasKey('test', $GLOBALS);
}
public function testTwo()
{
$this->assertArrayHasKey('test', $GLOBALS);
}
}
$ phpunit MyTest.php
PHPUnit 7.0.2 by Sebastian Bergmann and contributors.
.. 2 / 2 (100%)
Time: 40 ms, Memory: 4.00MB
OK (2 tests, 2 assertions)
$ phpunit --globals-backup MyTest.php
PHPUnit 7.0.2 by Sebastian Bergmann and contributors.
.F 2 / 2 (100%)
Time: 52 ms, Memory: 4.00MB
There was 1 failure:
1) MyTest::testTwo
Failed asserting that an array has the key 'test'.
/home/johnroyer/tmp/MyTest.php:16
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.
/**
* @runTestsInSeparateProcesses
*/
class MyTest extends TestCase
{
....
}
$ phpunit MyTest.php
PHPUnit 7.0.2 by Sebastian Bergmann and contributors.
.F 2 / 2 (100%)
Time: 303 ms, Memory: 4.00MB
There was 1 failure:
1) MyTest::testTwo
Failed asserting that an array has the key 'test'.
/home/johnroyer/tmp/MyTest.php:19
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.