lumen

Lumen 框架如何更优雅的使用事务

风格不统一 提交于 2020-08-06 04:44:14
我说的事务指的是一般的数据库事务,而不是什么分布式事务之类高大上的概念。 听起来很简单,但是即便如此,想实现的优雅一点也不是一件容易的事情。 假设有一个 QA 系统,当用户在上面提问的时候,系统保存问题,然后更新用户的提问数,最后触发一个问题已经被创建的异步事件来解耦逻辑(代码均使用 Lumen 框架): 1 <?php 2 3 try { 4 DB :: beginTransaction (); 5 6 $question -> content = '...' ; 7 $question -> save (); 8 9 $user -> questions_count += 1 ; 10 $user -> save (); 11 12 DB :: commit (); 13 14 event ( new QuestionCreatedEvent ( $question )); 15 } catch ( Exception $e ) { 16 DB :: rollBack (); 17 } 18 19 ?> 随着业务逻辑越来越复杂,会出现很多问题,其一:事务处理相关代码的割裂感会越来越严重;其二:事务处理相关逻辑会重复散落在很多地方,很容易遗漏或错乱。 如何解决问题? 学院派面对此类问题,多半会搞出一个新的 service 层,专门用来处理事务,不过对我来说太重了

how to resolve an error to use spatie laravel

99封情书 提交于 2020-06-29 04:08:25
问题 I am using spatie library in laravel lumen to create file into image. But it is giving error. $destinationPath = storage_path('uploads'); $new_path = str_replace('\\', '/', $destinationPath); Browsershot::url('https://www.example.com/') ->setScreenshotType('jpeg', 100) ->save($new_path); Error is: The given path 'your storage file path' did not contain an extension. Please append an extension. 来源: https://stackoverflow.com/questions/62302857/how-to-resolve-an-error-to-use-spatie-laravel

PHP Lumen - request body always empty

空扰寡人 提交于 2020-06-17 14:36:26
问题 I have started writing a small API in Lumen. When I send a request with Postman to my local project on XAMPP, I always get the correct response and all request body data is set. But now that I'm trying to make a request to my project on live hosting, the request body is always completely empty. I'm therefore assuming something in PHP hosting settings is not set correctly, but can't figure out what. Any tips on what to check / look out for would be appreciated. No error is reported on live

Laravel/Lumen/Eloquent - Update coretable::with($OneDimArrayOfTablenames) with multidimensional array

梦想的初衷 提交于 2020-05-31 06:11:53
问题 I want to write a function where a multidimensional array with the following structure: { "id_coretable": 1, "Internal_key": "UPDATED1", "extensiontable_itc": { "description_itc": "UPDATED1" }, "extensiontable_sysops": { "description_sysops": "UPDATED1" } } updates a multidimensional model/collection (i can create either of them, whatever the actual solution to this problem might require) with basically the same structure: { "id_coretable": 1, "Internal_key": "NOTYETUPDATED1", "extensiontable

Laravel/Lumen/Eloquent - Update coretable::with($OneDimArrayOfTablenames) with multidimensional array

冷暖自知 提交于 2020-05-31 06:11:08
问题 I want to write a function where a multidimensional array with the following structure: { "id_coretable": 1, "Internal_key": "UPDATED1", "extensiontable_itc": { "description_itc": "UPDATED1" }, "extensiontable_sysops": { "description_sysops": "UPDATED1" } } updates a multidimensional model/collection (i can create either of them, whatever the actual solution to this problem might require) with basically the same structure: { "id_coretable": 1, "Internal_key": "NOTYETUPDATED1", "extensiontable

How can I serve nested projects in Nginx

*爱你&永不变心* 提交于 2020-05-30 06:55:07
问题 I have a Lumen api project with multiple git tags for api versioning. So I have to deploy multiple checkouts of the project. The folder structure on the server looks like this: var www api-staging master v1 public index.php ... v2 public index.php ... lastest public index.php ... ... Now I'd like to serve the projects via nginx so that the url looks something like this. http://BRANCH.domain.tld/VERSION/ eg. http://master.domain.tld/lastest/ I have tried a lot with regexp, but nothing really

How can I serve nested projects in Nginx

六眼飞鱼酱① 提交于 2020-05-30 06:54:46
问题 I have a Lumen api project with multiple git tags for api versioning. So I have to deploy multiple checkouts of the project. The folder structure on the server looks like this: var www api-staging master v1 public index.php ... v2 public index.php ... lastest public index.php ... ... Now I'd like to serve the projects via nginx so that the url looks something like this. http://BRANCH.domain.tld/VERSION/ eg. http://master.domain.tld/lastest/ I have tried a lot with regexp, but nothing really

TDD: best practices mocking stacks of objects

自作多情 提交于 2020-05-16 19:09:51
问题 I'm trying to get familiar with unit testing in PHP with a small API in Lumen. Writing the first few tests was pretty nice with the help of some tutorials but now I encountered a point where I have to mock/ stub a dependency. My controller depends on a specific custom interface type hinted in the constructor. Of course, I defined this interface/implementation-binding within a ServiceProvider. public function __construct(CustomValidatorContract $validator) { // App\Contracts

How do I use helper functions in Lumen?

我与影子孤独终老i 提交于 2020-05-11 10:44:03
问题 $credentials = app_path(); Results in: [Symfony\Component\Debug\Exception\FatalThrowableError] Call to undefined function App\LtClasses\app_path() But it's listed as a helper here: https://laravel.com/docs/5.3/helpers#method-app-path 回答1: Those are the Laravel docs, you don't have the same helpers available on Lumen, you can have a look at the helpers that the Lumen framework comes with at /vendor/laravel/lumen-framework/src/helpers.php Workarounds to achive what you need here could be app()-