Peter
目前在 ITRI 服務
後端開發者
3+ years PHP 後端程式開發
PHP 5.3 → PHP 7+
會一點 Python
No framework→Slim→Laravel
2 years 開源專案貢獻者
find . -name '*.php' | xargs wc -l
47 ./xxxxController.php
32 ./Auth/xxxxxxxController.php
73 ./Auth/xxxxxController.php
117 ./xxxxxController.php
928 ./xxxxxController.php
204 ./xxxxController.php
217 ./xxxxxController.php
73 ./xxxxxxxxController.php
13 ./Controller.php
260 ./xxxxxpController.php
12 ./xxxxxController.php
216 ./xxxxxController.php
43 ./xxxxxController.php
1965 ./xxxxxxController.php
362 ./xxxxxController.php
264 ./xxxxxxController.php
409 ./District/xxxxxxController.php
727 ./xxxxxxController.php
2753 ./xxxxxxController.php
41 ./xxxxxxController.php
public function getAminInfo(Request $request)
{
$adminId = Session::get('admin.id');
$isManager = Session::get('admin.alarmMesg');
$isExtended = Session::get('admin.extended');
$sql='SELECT admin.* FROM admin WHERE id = ?';
$admins = DB::select($sql, array($adminId));
if(empty($admins))
$admin=NULL;
else
$admin = $admins[0];
......
curl -sS https://getcomposer.org/installer | php
https://getcomposer.org/download/
1.8.4/composer.phar
class User
{
protected function formatResponse($data)
{
return [
'name' => $data->name,
'userName' => $data->userName,
];
}
protected function validator($user)
{
if ($user === '') {
throw new \InvalidArgumentException("User doesn't exist");
}
}
protected function fetchUserInformation($userId)
{
return DB::table('users')->findOrFail($userId);
}
}
interface LoginInterface
{
public function authUser($user);
}
class NormalLogin implements LoginInterface
{
public function authUser($user)
{
// auth logic...
}
}
class FacebookLogin implements LoginInterface
{
public function authUser($user)
{
// auth logic...
}
}
class LoginModule
{
public function login(LoginInterface $user)
{
$user->authUser($user);
}
}
class Rectangle
{
protected $width;
protected $height;
public function setHeight($height)
{
$this->height = $height;
}
public function getHeight()
{
return $this->height;
}
public function setWidth($width)
{
$this->width = $width;
}
public function getWidth()
{
return $this->width;
}
public function area()
{
return $this->height * $this->width;
}
}
class Square extends Rectangle
{
public function setHeight($value)
{
$this->width = $value;
$this->height = $value;
}
public function setWidth($value)
{
$this->width = $value;
$this->height = $value;
}
}
interface Codeable
{
public function code();
}
interface Testable
{
public function test();
}
class Programmer implements Codeable, Testable
{
public function code()
{
return 'coding';
}
public function test()
{
return 'testing in localhost';
}
}
class Tester implements Testable
{
public function test()
{
return 'testing in test server';
}
}
class ProjectManagement
{
public function processCode(Codeable $member)
{
$member->code();
}
}
interface Mailer
{
public function send();
}
class SmtpMailer implements Mailer
{
public function send()
{
}
}
class SendWelcomeMessage
{
private $mailer;
public function __construct(Mailer $mailer)
{
$this->mailer = $mailer;
}
}
class SendGridMailer implements Mailer
{
public function send()
{
}
}
$gmp = new GmpCalculator();
$bcMath = new BcMathCalculator();
$calculator = new Calculator($gmp);
$calculator->add('11111', '22222222');
$calculator->minus('11111', '22222222');
$calculator->mul('11111', '22222222');
$calculator->divide('11111', '22222222');
interface CalculatorInterface
{
public function add($num1, $num2);
public function minus($num1, $num2);
public function mul($num1, $num2);
public function divide($num1, $num2);
}
class GmpCalculator extends Calculator
{
// calculation logic implementation
}
class BcMathCalculator extends Calculator
{
// calculation logic implementation
}
class Calculator
{
// calculation logic
}