# 補洞紀錄 ###### tags: `雜項` ## __invoke() * 如果你的controller只需要處理一個動作,那麼可以直接用 php artisan make:controller --invokeable * 創建出來的controller會包含一個 __invoke 的方法 * route 設定也不用指定method * Route::get('user/{id}', 'ShowProfile'); 設定該class名即可 * 當用類似呼叫函式的方法調用一個 class,__invoke() 這個方法會自動被調用 * https://ithelp.ithome.com.tw/articles/10208779 * https://pandalab.org/articles/99 * PHP Magic Methods * https://imyoungyang.gitbooks.io/php7-study-group-notes/content/Chapter2/php-magic-methods.html * __call() 應用 * https://devindeving.blogspot.com/2018/12/php-call.html ## git 常用指令全部熟練 * 目前常用的 * git pull * git add * git commit * git push remoteName branchName * git diff fileName * git checkout -b branchName * git revert ## PHP namespace 深入理解 * 除了區分同名function、class之外,遵循PSR-4 autoloader的規範的話可輕鬆的使用composer 自動載入相對應的檔案 * http://blog.tonycube.com/2016/09/php-psr-4-autoloader.html * [PHP的語言特性 : Namespaces 與 Class Autoloading](https://ithelp.ithome.com.tw/articles/10134247) * [PHP的語言特性 : PHP內建的interface與class](https://ithelp.ithome.com.tw/articles/10134516) * 她人namespace的坑 * https://soarlin.github.io/2017/05/14/%E5%B7%A5%E4%BD%9C%E7%AD%86%E8%A8%98%E4%B9%8BPHP-PSR-4-autoload/ ## RESTful * https://medium.com/itsems-frontend/api-%E6%98%AF%E4%BB%80%E9%BA%BC-restful-api-%E5%8F%88%E6%98%AF%E4%BB%80%E9%BA%BC-a001a85ab638 * 就是用一個唯一的 URL 定位資源,將動作藏在 HTTP 的 method 裡面。 * 所以使用 RESTful 風格設計的 API,就有了以下幾種優點及限制: 1. 有唯一的URL表示資源位置,統一的 API 接口。(Uniform Interface) 2. 無狀態。(Stateless) 3. 可更高效利用快取來提高回應速度 (Cachable) * 在 server-side,GET 過的資源,如果沒有被變更過,可以利用 cache 機制減少 request。在 client-side,透過 client 端 cache 紀錄chahe 版本,若向 server 要求資源時發現 server 最新版與 cache 相同,則 client 端直接取用本地資源即可,不需要再做一次查詢 4. 分層系統架構 (Layered System) 5. 客戶端服務器分離 (Client-Server) 6. 充份利用 HTTP protocal(GET/POST/PUT/DELETE) (Manipulation of resources through representations) 7. 可執行程式碼的設計,像是 JavaScript(非必要實作項目) Code-On-Demand (optional) * https://medium.com/@jinghua.shih/%E7%AD%86%E8%A8%98-rest-%E5%88%B0%E5%BA%95%E6%98%AF%E4%BB%80%E9%BA%BC-170ad2b45836 1. 伺服器/客戶端分離 Separation of Server and Client * 遵照 REST 設計的系統可以做到伺服器端與客戶端的實作獨立,兩者可以各自發展、互不影響,也就是說不管客戶端的程式碼再怎麼改變都不會影響到伺服器的運作,反之亦然。這是因為兩者遵循著一個溝通的格式,只要客戶端不改變傳訊息給伺服器端的方式,伺服器端也不改變傳訊息給客戶端的方式,就可以做到 seperation of concerns。 2. 無狀態 Stateless * 每個請求都是獨立的、自成一個個體,與前後請求無關。如此好處有很多,包含可靠(容易從錯誤中復原)、高效能與可擴充性(可以將請求交給不同伺服器處理),而元件可以被修改、更動而不會影響到系統整體的運作。 3. 可快取 Cacheable * 快取機制可以在 Client 或 Server 中實作。 4. 分層 Layered * 在發出請求的 Client 與送出回應的 Server 之間可以有好幾個 Server 中間人(稱作 Connectors,下面介紹),彼此獨立並且不會影響到 Request 與 Response。 5. 統一操作介面 Uniform Interface * 將操作細節抽象出來,降低耦合並提高獨立性。 ## 對資料庫做操作(讀取文章之類)的controller會怎麼作 * controller * 在大型的專案之中,如果程式的耦合度太高(比如商業邏輯都塞在 Controller,或者把 Model 當 Library 用),很容易遇到兩個問題: 1. 彈性極低,難以維護 2. 不易寫單元測試 * https://blog.johnsonlu.org/repository-pattern-and-service-layer/ ## 解釋interface abstract trait ### Interface * [介面(Interface)](https://kejyuntw.gitbooks.io/php-learning-notes/content/class/interface.html) ### Abstract * [抽象類別(Abstract Class)](https://kejyuntw.gitbooks.io/php-learning-notes/content/class/abstract-class.html) ### Trait * [PHP Trait](https://imyoungyang.gitbooks.io/php7-study-group-notes/content/Chapter2/php-trait.html) * [掌握 PHP Trait 的概念和用法][(https://](https://zhuanlan.zhihu.com/p/31362082)) ### 未分類 * [何時使用interface or abstract](https://stackoverflow.com/questions/1814821/interface-or-an-abstract-class-which-one-to-use) * [trait & abstract 的差異](https://stackoverflow.com/questions/39466521/difference-between-trait-and-an-abstract-class-in-php) * [逐步提昇PHP技術能力 - PHP的語言特性 : Traits](https://ithelp.ithome.com.tw/articles/10133226) * 對OOP的理解 * Interfaces are used to provide an interface to communicate with, as well as a blueprint for classes to use to implement methods. * Abstract classes are used to provide partial implementation, as well as a base type which facilitate communication and extendibility. * Traits are used for code re-use. It can't be used for type hinting. * If you're doing dependency injection, you'd want to use interfaces to be able to replace the implementation in the future if you choose to. If you have multiple sub-types, you might want to have a base type to share implementation between these (A good example is having a Request type from which you extend for the various HTTP verbs). Traits then allow you to group functionality which might not only apply to that inheritance tree. * https://www.reddit.com/r/PHP/comments/113mm8/when_to_use_abstract_classes_vs_interfaces_and/ * PHP物件導向的第五課:介面(interface)&虛擬類別 * https://ithelp.ithome.com.tw/articles/10115273 * list * https://ithelp.ithome.com.tw/users/20072133/articles?page=2 * 多載(overloading) * https://ithelp.ithome.com.tw/articles/10132318 * 使用在屬性多載的魔術方法 * __set($name, $value):如果想要寫入物件無法存取的屬性,就會觸發這個方法 * __get($name):如果想要讀取物件無法存取的屬性,就會觸發這個方法 * __isset($name):如果想要用isset()或是empty()判斷物件所無法存取的屬性是否存在或為空,就會觸發這個方法 * __unset($name):如果想要用unset()來清除物件無法存取的屬性,就會觸發這個方法 * https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/111201/ * https://icodding.blogspot.com/2015/10/php_6.html * 她人筆記 * https://hackmd.io/@jeff14994/S1dKm1P1v * https://php-learning-simple.mygreatname.com/php-learning/php-class-1.html * [PHP] 學習筆記-類別(class) * https://medium.com/@a663321765/php-%E5%AD%B8%E7%BF%92%E7%AD%86%E8%A8%98-%E9%A1%9E%E5%88%A5-class-f06188307d09 * [PHP面試Q&A](https://blog.csdn.net/u011330276/article/details/79597200) * [PHP面試Q&A 同上不同網站](https://iter01.com/49231.html) ## git flow * https://medium.com/i-think-so-i-live/git%E4%B8%8A%E7%9A%84%E4%B8%89%E7%A8%AE%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B-10f4f915167e * https://ihower.tw/blog/archives/5140 * https://gitbook.tw/chapters/gitflow/why-need-git-flow.html * sourcetree ver * https://gitbook.tw/chapters/gitflow/using-git-flow.html ## testing * [逐步提昇PHP技術能力 - 開發工具 : PHPUnit](https://ithelp.ithome.com.tw/articles/10136977) * [【週五技術直播】用 VS Code 輕鬆寫 PHP 測試](https://www.youtube.com/watch?v=ZWootMKhhj4) * [PHPUnit 手册 : 好像是官方doc](https://phpunit.readthedocs.io/zh_CN/latest/) * https://blog.johnsonlu.org/build-testing-data-into-sqlite-with-seed/ * https://blog.goodjack.tw/2018/07/laravel-phpunit.html * https://blog.johnsonlu.org/phpunit/ * 她人認為測試為何重要的心得 * https://ithelp.ithome.com.tw/articles/10171645 ## 用GET傳JSON * 目前想到的方法 * 整個JSON轉成STRING,問題是內容過長的話URL也塞不下 * [長度限制](https://www.itread01.com/content/1550260474.html) ## 開發環境 * 面試官可能想要了解我是否對於linux的系統需要額外的時間才能上手 * 我回答XAMPP會給對方我還需要另外的時間彌補linux的技術債的感覺 * 除了照實回答目前使用的環境外應該要補充個人對linux的熟練度 * 像是敘述之前的環境使用putty連線,純用cmd操作也是沒有問題的
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up