Skip to content

Instantly share code, notes, and snippets.

@timoschinkel
timoschinkel / pre-push.sh
Last active May 13, 2019 08:25
Git pre-push hook for php inspections
#!/bin/bash
UPSTREAM="upstream" # Could come from env
CHANGED_FILES=`git diff --name-only --diff-filter=ACM HEAD $UPSTREAM/master --raw`
PHP_SOURCE_FILES=""
PHP_TEST_FILES=""
TWIG_FILES=""
for file in $CHANGED_FILES
@timoschinkel
timoschinkel / Implementing_PSR-18_and_extending_it_with_middleware.md
Last active January 21, 2019 22:22
Implementing PSR-18 and extending it with middleware

Implementing PSR-18 and extending it with middleware

With the current trend of using microservices chances are that the majority of your projects either perform http calls, or use one or more packages that do so. And thus chances are that you are either using Guzzle or another http request library or abstraction, directly or via a package. This causes a hard dependency to this library and maybe even to multiple libraries. You might even run into the issue of being unable to use or upgrade a package due to a version mismatch. The [PHP-FIG][php-fig] was founded with the intent to handle these kind of situations. And with the introduction of [PSR-18][psr-18] the entire HTTP stack was "standardized" via PSR's; with [PSR-7][psr-7], [PSR-15][psr-15], [PSR-17][psr-17] and PSR-18 it is now possible to make completely framework agnostic packages and applications. And for us the introduction of PSR-18 came at the ideal moment as we were preparing to migrate from [Guzzle][guzzle] 5 to Guzzle 6. When we learned about

<?php
function mb_ucfirst($string) {
return mb_convert_case(mb_substr($string, 0, 1), MB_CASE_UPPER) . mb_substr($string, 1);
}
function mb_ucwords($string) {
return mb_convert_case($string, MB_CASE_TITLE);
}
@timoschinkel
timoschinkel / tokenizer.php
Created October 5, 2017 13:46
Visual tokenizer using the PHP_Codesniffer tokenizer
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Tokenize</title>
<style>
span.token:hover {
background: powderblue;
}
pre {