Author Archives:
OAuth2 with PHP’s built in Streams Functions
(this drives me nuts, I love upgrading systems but the downside is you have to work with the old ones first and none of the tools you want have been invented yet!)
For OAuth2, all I had to be able to do was to send an Authorization
header with my web request from PHP. My second-favourite way of making API calls from PHP is to use PHP’s stream handling, so I did that. It’s not code you see very often but it’s super-simple and it works on every PHP platform I’ve tried so far, so here’s an example:
// assemble the options
$opts = array(
'http'=>array(
'header'=> "Authorization: Bearer " . $access_token
)
);
// create the context
$context = stream_context_create($opts);
// now make the request! Use the context and simply output the result
echo file_get_contents('http://api.example.com/endpoint1', false, $context);
If you’re trying to make an API call from PHP and installing better tools is hard for any reason, this example may help!
API Testing with Runscope
Relying on A Dev-Master Dependency in Composer
If your project installation instructions recommend requiring dev-master in composer, I may need to reconsider my choice of package
— Lorna Mitchell (@lornajane) December 2, 2015
I got a few responses asking me to expand so I thought I would take the opportunity to write more than 140 characters on this topic. Continue reading
Insert Data with Phinx
change()
description.
One thing I didn’t immediately find was how to insert data. Continue reading
Generating a File List for Phan
phan -f filelist.txt
I generated my filelist.txt
files with a little help from grep – by looking for all files with opening PHP tags in, and putting that list of filenames into a file. My command looks like this:
grep -R -l "<?php" * > filelist.txt
This simply greps recursively (the -R
switch) in all files looking for <?php
and when it finds it, outputs only the filename (the -l
switch does that bit). Then I just put all the output into my filelist.txt
file.
Phan is in its early stages but it’s ready for you to run on your own projects. Look out that you may need to put your bootstrap or other include files first in the filelist.txt
file if phan isn’t finding things in the right order – luckily with it all in one file, it’s relatively easy to move things around if you need to.
Git Won’t Check Out A Path It Autocompleted
Why My Open Source Project Needs a Code of Conduct
I feel the same way about codes of conduct for open source projects as I do about codes of conduct for events. You can absolutely run a totally safe and effective event without one, but by having one you make very clear what your expectations are – and in turn this manages the expectations of the people attending that event. Continue reading