Skip to content

Instantly share code, notes, and snippets.

View intellix's full-sized avatar

D intellix

View GitHub Profile
@intellix
intellix / Module.php
Created July 22, 2013 10:38
ServiceManager into Service models
public function getServiceConfig()
{
return array(
'factories' => array(
'Application\Service\PlayerService' => function ($sm) {
$model = new Service\PlayerService($sm);
return $model;
}
)
);
@intellix
intellix / ManyObjectsExist.php
Created July 27, 2013 15:01
User wants to send mail to many other users in the game. This validator checks that they all exist within a Doctrine Repository.. based on ObjectExists for Doctrine ZF2 module.
<?php
namespace Application\Validator;
use Zend\Validator\AbstractValidator;
use Zend\Validator\Exception;
use Doctrine\Common\Persistence\ObjectRepository;
use Zend\Stdlib\ArrayUtils;
/**
@intellix
intellix / gist:6098619
Created July 28, 2013 13:40
Multi Dimensional array_unique
/**
* Removes duplicate entries in a multi-dimensional array
* @param array $a the array you want to process
* @param string $i the index you would like to run against
* @return array the processed array
*/
public function md_array_unique($a, $i) {
$unset = array();
for($x = 0; $x < sizeof($a); $x++){
for($y = 1; $y < (sizeof($a) - $x); $y++){
@intellix
intellix / Application\Service\UserService.php
Created July 28, 2013 22:42
Bcrypt passwords with ZF2 + Doctrine ORM Module
<?php
namespace Application\Service;
use Zend\Crypt\Password\Bcrypt;
use Application\Entity;
class UserService
{
@intellix
intellix / YourForm.php
Last active December 20, 2015 12:19
Simple ZF2 validation using inputProviderInterface
<?php
namespace Application\Form;
use Zend\Form\Form;
use Zend\Validator;
use Zend\InputFilter\InputFilterProviderInterface;
class YourForm extends Form implements InputFilterProviderInterface
{
@intellix
intellix / IndexController.php
Created August 1, 2013 16:14
Add data-ajax="1" and on submit, it will post the form to a ZF2 ControllerAction via AJAX and push the errors into your form. HTML is what is generated via DluTwBootstrap. You'll need jQuery UI Widget Factory and Twitter Bootstrap
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Mvc\MvcEvent;
use Zend\View\Model\JsonModel;
class IndexController extends AbstractActionController
{
@intellix
intellix / Application\Controller\IndexController.php
Last active December 20, 2015 14:49
Event Listeners in ZF2/Doctrine ORM
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class VillageController extends AbstractActionController
{
private $em;
@intellix
intellix / slmlocale.global.php
Created August 20, 2013 22:08
SlmLocale.php with aliases for auto redirect to locale
<?php
/**
* SlmLocale Configuration
*
* If you have a ./config/autoload/ directory set up for your project, you can
* drop this config file in it and change the values as you wish.
*/
$settings = array(
/**
* Default locale
@intellix
intellix / Gruntfile.js
Last active December 21, 2015 16:09
GruntJS for development and production.
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compass: {
files: [
'sass/**/*.scss'
]
clean: {
options: {
@intellix
intellix / ApplicationTest\Service\AccountServiceTest.php
Last active December 26, 2015 11:39
Testing a Doctrine ZF2 Application with rollbacking of data inserted into your database during the test. Listener solution found through stackoverflow: http://stackoverflow.com/questions/12456281/how-to-clean-a-test-database-with-doctrine And apparently since creating this, I've been provided this by ocramius for a Doctrine testing environment: h…
<?php
namespace ApplicationTest\Service;
use PHPUnit_Framework_TestCase;
use ApplicationTest\Bootstrap;
use Application\Service;
use Application\Entity;