Skip to content

Instantly share code, notes, and snippets.

View miguelplazasr's full-sized avatar

Miguel Plazas miguelplazasr

  • Pulsar IT
  • Miami, FL
View GitHub Profile
@miguelplazasr
miguelplazasr / javascript select twig
Last active September 8, 2015 01:55
Script for Country, State and City Select
{% block javascripts %}
{{ parent() }}
<script>
$(function(){
$(".country_selector").change(function(){
var data = {
country_id: $(this).val()
};
@miguelplazasr
miguelplazasr / routing.yml
Created September 10, 2015 15:50
Configurate default locale
app:
resource: "@AppBundle/Controller/"
type: annotation
root:
pattern: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /{_locale}
permanent: true
@miguelplazasr
miguelplazasr / README.md
Created July 13, 2016 21:56 — forked from tjamps/README.md
Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authentication
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 2 framework. The following SF2 bundles are used :

@miguelplazasr
miguelplazasr / EntityHandler.php
Last active August 17, 2016 20:27
EntityHandler class
<?php
namespace AppBundle\Handler;
use AppBundle\Exception\AppDBALException;
use AppBundle\Exception\FormErrors;
use Doctrine\DBAL\Driver\PDOException;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
@miguelplazasr
miguelplazasr / http_status_codes.php
Created August 19, 2016 15:42 — forked from nietzscheson/http_status_codes.php
HTTP status codes array
<?php
$code = array();
$code['0'] = 'Connection Failed. Please configure Varnish to accept HTTP purge requests.';
$code['100'] = 'Continue';
$code['101'] = 'Switching Protocols';
$code['102'] = 'Processing';
$code['200'] = 'OK';
$code['201'] = 'Created';
$code['202'] = 'Accepted';
@miguelplazasr
miguelplazasr / TranslateController.php
Created October 5, 2016 20:59
Conviert un archivo i18n de Symfony en JSON
namespace AppBundle\Controller\api;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Yaml\Yaml;
class TranslateController extends FOSRestController implements ClassResourceInterface
@miguelplazasr
miguelplazasr / app.config.js
Last active October 5, 2016 21:00
Configura Angular para las traducciones
/**
* i18n for Angular (https://angular-translate.github.io/)
*
*
*/
(function () {
'use strict';
angular
.module('MyApp')
@miguelplazasr
miguelplazasr / Locale services
Created May 4, 2016 01:11
Services for locale session user
app.locale_listener:
class: AppBundle\EventListener\LocaleListener
arguments: ['%kernel.default_locale%']
tags:
- { name: kernel.event_subscriber }
app.user_locale_listener:
class: AppBundle\EventListener\UserLocaleListener
arguments: ['@session']
tags:
@miguelplazasr
miguelplazasr / LocaleListener.php
Created May 4, 2016 01:10
Listener for set locale session
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LocaleListener implements EventSubscriberInterface
{
@miguelplazasr
miguelplazasr / BaseController.php
Created December 6, 2016 22:09
Base controller for FOSRestController
<?php
/**
* Created by PhpStorm.
* User: miguelplazasr
* Date: 10/14/16
* Time: 1:03 PM
*/
namespace AppBundle\Controller\api;