Skip to content

Instantly share code, notes, and snippets.

View johnkary's full-sized avatar

John Kary johnkary

View GitHub Profile
@johnkary
johnkary / SwiftMailerHandler.php
Last active August 29, 2015 14:13
Lazy SwiftMailerHandler
<?php
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@johnkary
johnkary / app_dev.php
Created January 4, 2015 21:51
Allow setting breakpoints in Symfony component code when step debugging with Xdebug. Disables cached/compiled files when step debugging. Thanks Joshua Thijssen <https://www.adayinthelifeof.nl/2014/12/31/debugging-symfony-components/> and Antonio J. García Lagar <http://aj.garcialagar.es/blog/debugging-symfony-with-xdebug-2/> for the inspiration.
<?php
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
@johnkary
johnkary / LongController.php
Last active August 29, 2015 14:05
There's a delicate balance between useless instance variables and extracting well-named variables for readability.
<?php
class ModuleController extends Controller
{
public function getIconAction($moduleId)
{
$moduleFinder = $this->get('module_finder');
$module = $moduleFinder->getModule($moduleId);
if (!$module) {
@johnkary
johnkary / ArrayCollectionTest.php
Created June 24, 2014 19:43
Doctrine ArrayCollection ->toArray() usage modifies original array in collection
<?php
use Doctrine\Common\Collections\ArrayCollection;
class ArrayCollectionTest extends \PHPUnit_Framework_TestCase
{
public function testModifiesOriginalCollection()
{
$data = array(
1 => new Destination(),
@johnkary
johnkary / LikeQueryHelpers.php
Last active April 22, 2022 08:09
Proper DQL escaping for LIKE queries with Doctrine 2.
<?php
namespace Foo;
/**
* Methods for safe LIKE querying.
*/
trait LikeQueryHelpers
{
/**
@johnkary
johnkary / after.rb
Last active August 29, 2015 13:56
Response code to Use An Ask, Don't Tell Policy With Ruby - http://patshaughnessy.net/2014/2/10/use-an-ask-dont-tell-policy-with-ruby
class Poem
def initialize(lines)
@lines = lines
end
def lines_after_functional(target)
target_index = (0..@lines.size-1).detect do |i|
@lines[i].include?(target)
end
target_index ? @lines[target_index..-1] : []
@johnkary
johnkary / Request.php
Created December 4, 2013 03:59
Example of how to request raw XML via a SoapClient
<?php
use Psr\Log\LoggerInterface;
/**
* Assembles and dispatches the SOAP request body XML and returns the
* Response body XML from the vendor API.
*/
class Request
{
@johnkary
johnkary / gist:7320946
Created November 5, 2013 15:38
Prevent excess memory usage with long-running Symfony2 Commands
$this->em = $this->getContainer()->get('doctrine')->getEntityManager();
$this->em->getConnection()->getConfiguration()->setSQLLogger(null);
@johnkary
johnkary / freetds.conf
Created September 20, 2013 21:01
Configure FreeTDS to connect from Linux to MSSQL and allow specifying a custom character set. The file location varies based on distribution, but two I've found: Ubuntu /etc/freetds/freetds.conf and Red Hat Enterprise Linux (RHEL) /etc/freetds.conf
[global]
# TDS protocol version
tds version = 7.0
client charset = UTF-8
@johnkary
johnkary / OracleDoctrineTypeMappingListener.php
Created September 8, 2013 03:45
Connecting to Oracle with Symfony2 and Doctrine 2. 1. Map Oracle's DATE type to Doctrine's "date" type instead of "datetime" for Oracle driver. 2. Properly configures Doctrine to use most common Oracle Date and DateTime environment configurations. You may or may not need this. Check your Oracle server configuration and see \Doctrine\DBAL\Event\L…
<?php
namespace Acme\PeopleSoftBundle\Listener;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\Common\EventSubscriber;
/**
* Changes Doctrine's default Oracle-specific column type mapping to Doctrine