Skip to content

Instantly share code, notes, and snippets.

View settermjd's full-sized avatar

Matthew Setter settermjd

View GitHub Profile
@settermjd
settermjd / download-file-in-expressive.php
Last active July 25, 2022 01:25
Quick example of how to download/stream a file using Zend Expressive.
<?php
/**
* This is a quick example of how to stream a file to a client, likely a browser,
* using Zend Expressive. There are a lot of factors which it doesn't take in to
* account. But for the purposes of a quick intro, this should suffice.
*/
class ViewDocumentPageAction
{
protected function downloadFile()
{
@settermjd
settermjd / Hydration, Hydration - And Not a Drop to Drink!.md
Last active June 22, 2016 16:39
This is an abstract for a talk about using the Zend Hydrator package to hydrate and extract simple to sophisticated objects.

Data, Data Everywhere And Not a Drop to Drink!

Populating objects with data (commonly referred to hydration), and extraction of said data from objects, are two key aspects of building object-oriented applications. It doesn’t matter whether the data source is a Relational, NoSQL, or Graph database, a flat text file, or a form. We need to hydrate and extract data - a lot. But how do we do it effectively - especially when objects can be quite complex?

In this tutorial, I will teach you how to use the Zend Hydrator package to perform both hydration and extraction. We’ll start off working with simple objects, and hydrate them from a relational database. We’ll then, gradually, increase in complexity, showing how to hydrate increasingly complex objects. We’ll also see how to create flexible and sophisticated hydrators which can use a multitude of data sources, such as forms, along with how to extract data from hydrated o

@settermjd
settermjd / empty-directory-contents.php
Created February 24, 2016 20:49
A simple script to recursively delete all files and directories within a parent directory
<?php
/**
* @param string $directory
*/
function emptyDirectoryContents($directory)
{
$Iterator = new RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(
realpath($directory),
@settermjd
settermjd / InsertTest.php
Last active February 8, 2016 08:49
The following test for Zend\Db\Sql\InsertTest fails. Yet I'd have thought it would pass.
<?php
$this->insert
->into('foo')
->columns(['col1', 'col2', 'col3'])
->values(['val1', 'val2', 'val3']);
$this->assertEquals(
'INSERT INTO foo ("col1", "col2", "col3") VALUES("val1", "val2", "val3")',
$this->insert->getSqlString(new TrustingSql92Platform())
);
@settermjd
settermjd / dependencies.global.php
Created October 30, 2015 11:32
Zend-Expressive Dependencies configuration which adds Zend\Db and Zend\Cache support.
<?php
return [
'dependencies' => [
'invokables' => [
App\Action\PingAction::class => App\Action\PingAction::class,
],
'factories' => [
App\Action\HomePageAction::class => App\Action\HomePageFactory::class,
Zend\Expressive\Application::class => Zend\Expressive\Container\ApplicationFactory::class,
@settermjd
settermjd / cache-config.php
Created October 30, 2015 11:31
Cache configuration showing how to configure Zend\Cache to work with Redis.
<?php
if (extension_loaded('redis')) {
return [
'caches' => [
'Cache\Transient' => [
'adapter' => 'redis',
'ttl' => 60,
'plugins' => [
@settermjd
settermjd / app -> config -> sculpin_kernel.ml
Last active October 5, 2015 11:48
Creating a custom type in Sculpin
sculpin_content_types:
posts:
permalink: pretty
portfolios:
enabled: true
@settermjd
settermjd / database-schema.sql
Created September 22, 2015 07:36
Query across multiple databases in MySQL
DROP TABLE IF EXISTS `departments`;
CREATE TABLE `departments` (
`dept_no` char(4) NOT NULL,
`dept_name` varchar(40) NOT NULL,
PRIMARY KEY (`dept_no`),
UNIQUE KEY `dept_name` (`dept_name`),
KEY `idx_deptno` (`dept_no`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `dept_emp`;
@settermjd
settermjd / DummyDateCalculator.php
Created July 24, 2015 10:37
Issue with using a factory to retrieve a service in PHP-DI
<?php
namespace DiExample;
class DummyDateCalculator
{
protected $date;
protected $secondDate;
public function __construct(\DateTime $date)
<?php
namespace DiExample;
class DummyDateCalculator
{
protected $date;
protected $secondDate;
public function __construct(\DateTime $date)