Skip to content

Instantly share code, notes, and snippets.

@samsamm777
samsamm777 / gist:7230159
Last active April 26, 2024 13:24
PHP set private property value using reflection. This allows you to set a private property value from outside the object, great for PHPUnit testing.
<?php
$a = new A();
$reflection = new \ReflectionClass($a);
$property = $reflection->getProperty('privateProperty');
$property->setAccessible(true);
$property->setValue($a, 'new-value');
echo $a->getPrivateProperty();
//outputs:
@nateevans
nateevans / MenuBuilder.php
Created April 3, 2014 16:56
KNP Menu Bundle with Bootstrap 3 and Font Awesome 4 (see http://bit.ly/1sd1rJr , thanks to Niels Mouthaan!)
<?php
namespace Acme\HelloBundle\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class MenuBuilder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
@tbrianjones
tbrianjones / Inflect.php
Last active February 21, 2024 21:28
A PHP Class for converting English words between Singular and Plural.
<?php
// original source: http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/
/*
The MIT License (MIT)
Copyright (c) 2015
Permission is hereby granted, free of charge, to any person obtaining a copy
@erighetto
erighetto / print_zpl.php
Last active June 16, 2022 16:06
Send raw ZPL to Zebra printer
<?php
error_reporting(E_ALL);
/* Get the port for the service. */
$port = "9100";
/* Get the IP address for the target host. */
$host = "172.17.144.89";
/* construct the label */
@tonydub
tonydub / DeletedFilter.php
Created May 30, 2016 07:26 — forked from baptistedonaux/DeletedFilter.php
Soft Delete Symfony/Doctrine
<?php
namespace Namespace\MyBundle\Repository\Filters;
use Doctrine\ORM\Mapping\ClassMetaData;
use Doctrine\ORM\Query\Filter\SQLFilter;
class DeletedFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
@wadtech
wadtech / AppDatabaseSessionHandler.php
Last active December 13, 2023 15:31
Laravel 5.3 Custom Database Session Handler Example
<?php
namespace App\Extensions;
// we have an Eloquent model that allows using the session table with the querybuilder methods and eloquent fluent interface- read only!
use App\Session;
// use the provided database session handler to avoid too much duplicated effort.
use Illuminate\Session\DatabaseSessionHandler;
class AppDatabaseSessionHandler extends DatabaseSessionHandler
@edutrul
edutrul / convert-integer-to-roman.php
Created September 8, 2017 16:26
How to convert integer to Roman number
<?php
/**
* Converts integer to Roman.
*
* @param int $integer
* Integer to be converted to Roman string.
*
* @return string
*/
public function integerToRoman($integer) {
@olegpolyakov
olegpolyakov / create-element.js
Last active July 14, 2022 21:10
A utility function for creating dom elements similar to `React.createElement`
export function createElement(tag, props, ...children) {
const element = document.createElement(tag);
if (props) {
Object.entries(props).forEach(([key, value]) => {
if (key.startsWith('on') && typeof value === 'function') {
element.addEventListener(key.substring(2), value);
} else if (key.startsWith('data-')) {
element.setAttribute(key, value);
} else {