php

How to build a Docker development setup for PHP Projects [Tutorial Part 3]

planet PHP - 2019-05-20(月) 17:07:00

In the third part of this tutorial series on developing PHP on Docker we'll lay the fundamentals to build a complete development infrastructure and explain how to "structure" the Docker setup as part of a PHP project. Structure as in

  • folder structure ("what to put where")
  • Dockerfile templates
  • solving common problems (file permissions, runtime configuration, ...)

We will also create a minimal container setup consisting of php-fpm, nginx and a workspace container that we refactor from the previous parts of this tutorial.

Published parts of the Docker PHP Tutorial

All code samples are publicly available in my Docker PHP Tutorial repository on github. The branch for this tutorial is part_3_structuring-the-docker-setup-for-php-projects.

If you want to follow along, please subscribe to the RSS feed or via email to get automatic notifications when the next part comes out :)

Acknowledgements

Shout out to Nils Meyer for giving the final "[...] nichts offensichtlich falsch" ("nothing obviously wrong") :)

Table of contents

Truncated by Planet PHP, read more at the original (another 58661 bytes)

カテゴリー: php

Newcrafts 2019 Day 1

planet PHP - 2019-05-17(金) 23:15:00

This week I attended and spoke at the Newcrafts conference in Paris. The following is a mix of notes and personal observations I wanted to share, centered around some of the talks I saw there.

Romeu Romera: Bourdieu's Social theory and our work in tech

I had never attended a talk by Romeu before. I really enjoyed this one. Somehow I already knew that he uses a mindmap to support his talk. I thought he would use an existing mind map to navigate through the talk, but it turned out he was creating one during the talk. For me personally, a slide deck helps to keep track of the story, and it helps me remember all the different topics I need to talk about. Not so much for Romeu, who knew exactly what he was going to talk about, and didn't seem to forget to mention any important part, or make important connections.

The topic is one that seems close to his heart. Still, he called himself "not an expert", saying that this talk was an experiment. It turned out that he was hinting at the fact that the subject matter is vast, and he could only cover some parts of it during the talk. Still, the things he covered, maybe simplified a lot, were very impactful, and very interesting. I'd definitely recommend watching this talk once it becomes available online.

More than with any other talk, I think you can't help it but apply the ideas mentioned to your own situation when you listen to Romeu. He covered three parts of Bourdieu's social theory. The first part is about icons of power. The way you look and behave shows how much power you have. This modified appearance is called Symbolic Violence; an act of violance people in positions of power put onto themselves. I think in the context of conferences, being a public speaker is a great example of violence the speaker puts onto themselves. Personally, I often find it a painful experience (although I'll keep doing it as long as there's a way to help people do a better job in any way).

The second part of the theory has to do with Cultural Capital. Everyone has their own amount of cultural capital. Take for example the people in your team. Some will have more experience than others, a deeper understanding of design, architecture, etc. People with less cultural capital will be seen as lesser people. Having more cultural capital can also be an issue with speakers at a conference, where they will be automatically taken to be experts, to be better humans (or at least, better designers, programmers, etc.). They will be perceived to be more powerful, and more right. This isn't fair to either party; speakers, and attendees alike, but it's how the game gets played.

Differences in the amounts of cultural capital between people will result in Dissociation. The first thing that might happen is that you see a person with less cultural capital as someone you can ignore, not take seriously, etc. The other thing that could happen is that you'll feel that a person with more cultural capital than you is unreachable, and that they wouldn't be interested in even talking to you. Personally I can relate to this problem a lot. When I'm at a conference, it totally depends how I feel: if I feel like I have a sufficient amount of cultural capital, I'll be perfectly fine, and can speak freely with anyone in the room. If I feel that I lack cultural capital, I'm very shy, and generally tend to avoid other speakers, as I will quickly feel like an imposter, noticing a mismatch between the expected and the actual amount of cultural capital.

The third part of the theory is about Hexis, which means something like to what level you feel like you belong somewhere. Hexis could be considered "high" if you never doubt that you should be where you are now. It's low if you have doubts about your presence. Being self-condident is much appreciated, showing doubt is a signal of fragility, and it will look punishable. The immediate association I had, was how code reviews show a difference in seniority (which comes with self-confidence, never a doubt that you're in the right place). The senior developer is likely to provide a lot of nitpicking comments to the one who is more junior. The junior developer will likely have a hard time providing feedback to the senior. The situation gets worse if the senior is considered to be the boss/manager/team lead as well.

And this is where Romeu brings the discussion back to software development. The problem with some agile practices is that they assume equality in the workplace. Pair programming is easy if none of the programmers are the (perceived) boss. Retrospectives are easy if the (perceived) boss isn't there.

If you have enough cultural capital, and symbolic violence, you can ignore the problem. But if you have not, you can't. The problem is real. And of course, it's better if nobody would ignore the pro

Truncated by Planet PHP, read more at the original (another 4122 bytes)

カテゴリー: php

Command Pattern for Legacy Code Refactoring

planet PHP - 2019-05-17(金) 22:49:00

Just recently I run into an issue on one of my projects which I gracefully solved using the Command pattern. The project has a lot of legacy code, and to avoid the pain of major refactoring we do it gradually, piece by piece.


Continue reading
カテゴリー: php

Interview with Phil Jackson

planet PHP - 2019-05-17(金) 19:06:00
カテゴリー: php

Remove unused "use" imports in PHP

planet PHP - 2019-05-16(木) 04:09:00

To clean up unused namespace imports (use statements) in many PHP files at once, php-cs-fixer (version 2) is of great help:

$ php php-cs-fixer.phar fix --rules=no_unused_imports src/
カテゴリー: php

My Bref Makefile

planet PHP - 2019-05-15(水) 19:02:00

In order to use Bref efficiently, I've developed a Makefile so that I don't have to remember all the various commands required. In particular, looking up the correct parameters to sam package & sam deploy is a pain and it's much easier to type make deploy and it all works as I expect.

It looks like this:

Makefile:

# vim: noexpandtab tabstop=4 filetype=make .PHONY: list invoke invoke-local deploy outputs lastlog clean clean-all setup REGION := eu-west-2 PROJECT_NAME := hello-world UNIQUE_KEY := 1557903576 BUCKET_NAME := $(PROJECT_NAME)-$(UNIQUE_KEY)-brefapp STACK_NAME := $(PROJECT_NAME)-$(UNIQUE_KEY)-brefapp # default function to invoke. To override: make invoke FUNCTION=foo FUNCTION ?= my-function list: @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' invoke: vendor/bin/bref --region=$(REGION) invoke $(FUNCTION) invoke-local: sam local invoke $(FUNCTION) --no-event deploy: sam package \ --region $(REGION) \ --template-file template.yaml \ --output-template-file .stack-template.yaml \ --s3-bucket $(BUCKET_NAME) -sam deploy \ --region $(REGION) \ --template-file .stack-template.yaml \ --stack-name $(STACK_NAME) \ --capabilities CAPABILITY_IAM vendor/bin/bref deployment --region $(REGION) $(STACK_NAME) outputs: aws --region $(REGION) cloudformation describe-stacks --stack-name $(STACK_NAME) | jq '.Stacks[0]["Outputs"]' lastlog: sam logs --region $(REGION) --name $(FUNCTION) geterror: vendor/bin/bref deployment --region $(REGION) $(STACK_NAME) clean: aws --region $(REGION) cloudformation delete-stack --stack-name $(STACK_NAME) clean-all: clean aws --region $(REGION) s3 rb s3://$(BUCKET_NAME) --force setup: aws --region $(REGION) s3 mb s3://$(BUCKET_NAME)

There's three variables that I need to set at the top:

  • REGION – The AWS region. This has to match the Bref layer used in template.yaml.
  • PROJECT_NAME – The name of the project. This is used as part of the S3 bucket and CloudFormation stack names
  • UNIQUE_KEY – A random string to ensure uniqueness for bucket and stack names. I tend to use the current time to the ms, but any string.

I've included a full-cycle set of targets so make setup will create the initial S3 bucket that's required for the project and then make deploy is used to deploy my project.

If I want to start again, make clean will remove the CloudFormation stack and make clean-all will remove the stack and the bucket.

I've also included a few utility targets:

  • make invoke FUNCTION=foo invokes the function foo on AWS.
  • make invoke-local FUNCTION=foo invokes the function foo on sam-local.
  • make outputs displays the outputs of the CloudFormation stack. This is useful for picking up the API Gateway URL for instance, if you set it up in your template.yaml.
  • make lastlog FUNCTION=foo displays the logs for the last invocation of the function foo.
Parameters for template.yaml

I pass the PROJECT_NAME and UNIQUE_KEY through to the template as the parameters ProjectName and UniqueKey respectively. These are then set in the Parameters section of the template:

template.yaml:

Parameters: ProjectName: Type: String UniqueKey: Type: String

I then use them in the template when I need uniqueness, such as when creating an S3 bucket:

template.yaml:

Resources: ImagesBucket: Type: AWS::S3::Bucket Properties: BucketName: !Join [ '-', [!Ref "ProjectName", !Ref "UniqueKey", "files" ] ]

Which creates a bucket named "hello-world-1557903576-files" which nicely complements "hello-world-1557903576-brefapp".

カテゴリー: php

Sorting select fields in EasyAdminBundle

planet PHP - 2019-05-15(水) 18:04:00

I'm currently working on an application using Symfony and their EasyAdminBundle. The experience has been great overall, although there are lots of details and specific usecases that are hard to figure out.

For instance when using relations in your entities and creating the related forms. Select fields for related entities are by default sorted by the key (usually the ID of the related entity), however you'd usually want to sort it alphabetically by the name of the entity. My initial thought was to use the @OrderBy annotation, however that only works for the actual OneToMany relations on the other side of the relation, not on the selectbox for the ManyToOne side of the relation. So that was quickly discarded.

Next up I found that you can do it in Symfony by specifying a query_builder parameter to your form configuration. The downside here is that by default, EasyAdminBundle works with a yaml configuration for your form so that makes it a lot harder to do this. I could do this in an extended AdminController, but that would mess with my form field order.

Eventually, however, I found this comment on Github that gave me the solution. Instead of specifying an anonymous function, you can also specify a static method to be called to fetch the values. And so, my solution was now easily implemented.

In my YAML file, I could now specify the query_builder parameter:

- { property: supplier, label: 'Leverancier', type_options: { 'query_builder': 'App\Repository\SupplierRepository::getSuppliersForSelect' } }

In said repository, I added the specified static method:

static public function getSuppliersForSelect(EntityRepository $entityRepository) { return $entityRepository ->createQueryBuilder('s') ->orderBy('s.name', 'ASC'); }

and now my select field has a nicely alphabetically sorted list of suppliers.

カテゴリー: php

PSR-14: Example - layered caching

planet PHP - 2019-05-15(水) 04:18:00
PSR-14: Example - layered caching

So far we've looked at a number of complete, practical examples of using PSR-14 Events in various ways, both conventional and unconventional. In our final (probably) installment, I want to offer a highly unconventional but still practical use of PSR-14 that really shows off just how flexible Events can be: Layered caching.

"But wait, isn't caching the realm of PSR-6 and PSR-16?" Yes. Yes it is. But neither of those offer a built-in way to compose multiple cache backends together. It's certainly possible, but doing so is left as an exercise for the implementer. Let's use PSR-14 to get some exercise.

Continue reading this post on SteemIt.

Larry 14 May 2019 - 2:18pm
カテゴリー: php

425 Too Early

planet PHP - 2019-05-15(水) 00:00:00

When a HTTP client makes a connection to a HTTPS server, it uses TLS to create a secure connection. TLS can have a bit of a complicated ‘handshake’ to establish the connection. Because there’s a bunch of back and forward, this can take a long time, especially when there’s a lot of latency between server and client.

There are ways for clients to optimize this setup by sending a bunch of data very early in the process, before the full TLS connection is completely setup.

In some cases this can cause security problems. In those cases a the server can tell the client to retry a specific HTTP request after the TLS connection has been fully set up

In these situations, it will return the 425 Too Early status code.

Normally, you would never have to deal with this status code as a developer, unless you are creating HTTP(s) servers from scratch.

References
カテゴリー: php

Changes

planet PHP - 2019-05-14(火) 22:42:00

It was 6 years ago when I was last looking for a change after being a freelancer for a very long time. The idea was simple. I was tired of being the accountant, salesperson, consultant, developer, collections, sysadmin, and more. As a freelance “developer” I had to be all these things to support my family and live in a manner I was accustomed. But I was growing tired of it all, and wanted to have a little more fun by doing the parts I enjoyed most…consulting.

A good friend had been working at a well-known company for about a year and was very happy doing it. He also had grown tired of being a freelance developer, and a job at the company was his answer. So, when I saw an open consulting position on their website, I applied for it.

About a week later I received a call, then went through the typical round of interviews and questions. I was hired!

It was an exciting time, filled with learning new systems, people, and experiences. I was suddenly thrust into meetings with very large companies, and large teams of developers, who needed my help. There were new problems to solve on a weekly basis, and with each problem came new challenges. The number of things I learned during my six years of consulting at the company was mind-blowing, and with each day I discovered there was more and more I didn’t know. I basically went from knowing a bunch of things to village idiot overnight when I was hired.

“I went from knowing a bunch of things to village idiot overnight when I was hired.”

As I transitioned from one customer to another, it also led to traveling quite a bit. I spent half of each year away from home as I went onsite to meet new teams, learn network and application infrastructures, and build relationships with hundreds of people.

I continued to learn a great deal, and with each engagement, I spent less time on search engines and could draw from my own knowledge more often. (Of course, there was still a bunch of searching, but it was less. I’m still the village idiot learning daily.)

As a user group organizer, and speaker, I’ve always enjoyed teaching and sharing, and it was wonderful that my employer encouraged this activity. So I tended to share my knowledge with anyone who would listen, as I began speaking at conferences, user groups, and online from blog posts, podcasts, and videos, as well as through code via online source code repositories.

Through the process, I also did a fair amount of evangelism around products, libraries, and frameworks I believed in and witnessed some real growth from these efforts which drove me to do more.

However, as times change and acquisitions happen, so do the directions companies take. For good, or bad, companies are forced to make decisions and make changes to help them move forward and grow. I’ve witnessed and lived through some events these past couple years that have left me feeling dissatisfied and a little disconnected from the things I’ve come to hold dear.

This doesn’t mean the company is bad. It simply means our paths have diverged for the time being. Therefore, I will be leaving my current employer, as it is time once again for a change.

カテゴリー: php

Interview with Omni Adams

planet PHP - 2019-05-14(火) 22:05:00

@omnicolor Show Notes Audio

This episode is sponsored by


The post Interview with Omni Adams appeared first on Voices of the ElePHPant.

カテゴリー: php

php[world] 2019 Call for Speakers

php.net - 2019-05-10(金) 22:18:25
カテゴリー: php

php|architect: Serverless PHP With Bref, Part One

phpdeveloper.org - 2019-05-10(金) 06:00:01

By Rob Allen In recent years, a different way to build applications has arisen called serverless computing. This term is not a good name; I’m reminded of the adage that there are two hard problems in programming: naming things, cache invalidation, and off-by-one errors. Serverless computing as...

カテゴリー: php

PHP – Code Wall: Setting Up Laravel 5.8 With Authentication & Role Based Access

phpdeveloper.org - 2019-05-10(金) 06:00:01

Setting up your application with authentication & role-based access is much better fleshed out at the very beginning of a new project. There’s nothing worse than being 1 month deep into development and the client then requires login functionality and role-based access, trust me, I’...

カテゴリー: php

Laravel News: PhpStorm 2019.1.2 Released With Blade Debugging Fixes

phpdeveloper.org - 2019-05-10(金) 06:00:01
The PhpStorm IDE v2019.1.2 was released yesterday with support for composer execution using Docker and a Blade template debugging fix. Visit Laravel News for the full post. The post PhpStorm 2019.1.2 Released With Blade Debugging ...
カテゴリー: php

Derick Rethans: PHP Internals News: Episode 9: Bundled Extensions

phpdeveloper.org - 2019-05-10(金) 06:00:01
PHP Internals News: Episode 9: Bundled Extensions London, UK Thursday, May 9th 2019, 09:09 BST In this ninth episode of "PHP Internals News" I talk to Kalle Nielsen (Twitter, GitHub) about bundled extensions, and his work on the Windows por...
カテゴリー: php

PHP Architect: Serverless PHP With Bref, Part 1

planet PHP - 2019-05-09(木) 19:02:00

I've written a two-part series on Serverless PHP on AWS Lambda using Matthieu Napoli's Bref for php[architect].

Part one has been published in the May 2019 issue and if you're not already a subscriber, you should be!

If you just want to learn about Bref though, then my introduction to Bref is available for free, just for you!

カテゴリー: php

Interview with Michael Moussa

planet PHP - 2019-05-09(木) 18:09:00
カテゴリー: php

ページ