1589388120
A dropdown form field using a dropdown button inside a form field.
import 'package:dropdown_formfield/dropdown_formfield.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _myActivity;
String _myActivityResult;
final formKey = new GlobalKey<FormState>();
@override
void initState() {
super.initState();
_myActivity = '';
_myActivityResult = '';
}
_saveForm() {
var form = formKey.currentState;
if (form.validate()) {
form.save();
setState(() {
_myActivityResult = _myActivity;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Dropdown Formfield Example'),
),
body: Center(
child: Form(
key: formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.all(16),
child: DropDownFormField(
titleText: 'My workout',
hintText: 'Please choose one',
value: _myActivity,
onSaved: (value) {
setState(() {
_myActivity = value;
});
},
onChanged: (value) {
setState(() {
_myActivity = value;
});
},
dataSource: [
{
"display": "Running",
"value": "Running",
},
{
"display": "Climbing",
"value": "Climbing",
},
{
"display": "Walking",
"value": "Walking",
},
{
"display": "Swimming",
"value": "Swimming",
},
{
"display": "Soccer Practice",
"value": "Soccer Practice",
},
{
"display": "Baseball Practice",
"value": "Baseball Practice",
},
{
"display": "Football Practice",
"value": "Football Practice",
},
],
textField: 'display',
valueField: 'value',
),
),
Container(
padding: EdgeInsets.all(8),
child: RaisedButton(
child: Text('Save'),
onPressed: _saveForm,
),
),
Container(
padding: EdgeInsets.all(16),
child: Text(_myActivityResult),
)
],
),
),
),
);
}
}
Author: cetorres
GitHub: https://github.com/cetorres/dropdown_formfield
#flutter #dart #programming
1667425440
Perl script converts PDF files to Gerber format
Pdf2Gerb generates Gerber 274X photoplotting and Excellon drill files from PDFs of a PCB. Up to three PDFs are used: the top copper layer, the bottom copper layer (for 2-sided PCBs), and an optional silk screen layer. The PDFs can be created directly from any PDF drawing software, or a PDF print driver can be used to capture the Print output if the drawing software does not directly support output to PDF.
The general workflow is as follows:
Please note that Pdf2Gerb does NOT perform DRC (Design Rule Checks), as these will vary according to individual PCB manufacturer conventions and capabilities. Also note that Pdf2Gerb is not perfect, so the output files must always be checked before submitting them. As of version 1.6, Pdf2Gerb supports most PCB elements, such as round and square pads, round holes, traces, SMD pads, ground planes, no-fill areas, and panelization. However, because it interprets the graphical output of a Print function, there are limitations in what it can recognize (or there may be bugs).
See docs/Pdf2Gerb.pdf for install/setup, config, usage, and other info.
#Pdf2Gerb config settings:
#Put this file in same folder/directory as pdf2gerb.pl itself (global settings),
#or copy to another folder/directory with PDFs if you want PCB-specific settings.
#There is only one user of this file, so we don't need a custom package or namespace.
#NOTE: all constants defined in here will be added to main namespace.
#package pdf2gerb_cfg;
use strict; #trap undef vars (easier debug)
use warnings; #other useful info (easier debug)
##############################################################################################
#configurable settings:
#change values here instead of in main pfg2gerb.pl file
use constant WANT_COLORS => ($^O !~ m/Win/); #ANSI colors no worky on Windows? this must be set < first DebugPrint() call
#just a little warning; set realistic expectations:
#DebugPrint("${\(CYAN)}Pdf2Gerb.pl ${\(VERSION)}, $^O O/S\n${\(YELLOW)}${\(BOLD)}${\(ITALIC)}This is EXPERIMENTAL software. \nGerber files MAY CONTAIN ERRORS. Please CHECK them before fabrication!${\(RESET)}", 0); #if WANT_DEBUG
use constant METRIC => FALSE; #set to TRUE for metric units (only affect final numbers in output files, not internal arithmetic)
use constant APERTURE_LIMIT => 0; #34; #max #apertures to use; generate warnings if too many apertures are used (0 to not check)
use constant DRILL_FMT => '2.4'; #'2.3'; #'2.4' is the default for PCB fab; change to '2.3' for CNC
use constant WANT_DEBUG => 0; #10; #level of debug wanted; higher == more, lower == less, 0 == none
use constant GERBER_DEBUG => 0; #level of debug to include in Gerber file; DON'T USE FOR FABRICATION
use constant WANT_STREAMS => FALSE; #TRUE; #save decompressed streams to files (for debug)
use constant WANT_ALLINPUT => FALSE; #TRUE; #save entire input stream (for debug ONLY)
#DebugPrint(sprintf("${\(CYAN)}DEBUG: stdout %d, gerber %d, want streams? %d, all input? %d, O/S: $^O, Perl: $]${\(RESET)}\n", WANT_DEBUG, GERBER_DEBUG, WANT_STREAMS, WANT_ALLINPUT), 1);
#DebugPrint(sprintf("max int = %d, min int = %d\n", MAXINT, MININT), 1);
#define standard trace and pad sizes to reduce scaling or PDF rendering errors:
#This avoids weird aperture settings and replaces them with more standardized values.
#(I'm not sure how photoplotters handle strange sizes).
#Fewer choices here gives more accurate mapping in the final Gerber files.
#units are in inches
use constant TOOL_SIZES => #add more as desired
(
#round or square pads (> 0) and drills (< 0):
.010, -.001, #tiny pads for SMD; dummy drill size (too small for practical use, but needed so StandardTool will use this entry)
.031, -.014, #used for vias
.041, -.020, #smallest non-filled plated hole
.051, -.025,
.056, -.029, #useful for IC pins
.070, -.033,
.075, -.040, #heavier leads
# .090, -.043, #NOTE: 600 dpi is not high enough resolution to reliably distinguish between .043" and .046", so choose 1 of the 2 here
.100, -.046,
.115, -.052,
.130, -.061,
.140, -.067,
.150, -.079,
.175, -.088,
.190, -.093,
.200, -.100,
.220, -.110,
.160, -.125, #useful for mounting holes
#some additional pad sizes without holes (repeat a previous hole size if you just want the pad size):
.090, -.040, #want a .090 pad option, but use dummy hole size
.065, -.040, #.065 x .065 rect pad
.035, -.040, #.035 x .065 rect pad
#traces:
.001, #too thin for real traces; use only for board outlines
.006, #minimum real trace width; mainly used for text
.008, #mainly used for mid-sized text, not traces
.010, #minimum recommended trace width for low-current signals
.012,
.015, #moderate low-voltage current
.020, #heavier trace for power, ground (even if a lighter one is adequate)
.025,
.030, #heavy-current traces; be careful with these ones!
.040,
.050,
.060,
.080,
.100,
.120,
);
#Areas larger than the values below will be filled with parallel lines:
#This cuts down on the number of aperture sizes used.
#Set to 0 to always use an aperture or drill, regardless of size.
use constant { MAX_APERTURE => max((TOOL_SIZES)) + .004, MAX_DRILL => -min((TOOL_SIZES)) + .004 }; #max aperture and drill sizes (plus a little tolerance)
#DebugPrint(sprintf("using %d standard tool sizes: %s, max aper %.3f, max drill %.3f\n", scalar((TOOL_SIZES)), join(", ", (TOOL_SIZES)), MAX_APERTURE, MAX_DRILL), 1);
#NOTE: Compare the PDF to the original CAD file to check the accuracy of the PDF rendering and parsing!
#for example, the CAD software I used generated the following circles for holes:
#CAD hole size: parsed PDF diameter: error:
# .014 .016 +.002
# .020 .02267 +.00267
# .025 .026 +.001
# .029 .03167 +.00267
# .033 .036 +.003
# .040 .04267 +.00267
#This was usually ~ .002" - .003" too big compared to the hole as displayed in the CAD software.
#To compensate for PDF rendering errors (either during CAD Print function or PDF parsing logic), adjust the values below as needed.
#units are pixels; for example, a value of 2.4 at 600 dpi = .0004 inch, 2 at 600 dpi = .0033"
use constant
{
HOLE_ADJUST => -0.004 * 600, #-2.6, #holes seemed to be slightly oversized (by .002" - .004"), so shrink them a little
RNDPAD_ADJUST => -0.003 * 600, #-2, #-2.4, #round pads seemed to be slightly oversized, so shrink them a little
SQRPAD_ADJUST => +0.001 * 600, #+.5, #square pads are sometimes too small by .00067, so bump them up a little
RECTPAD_ADJUST => 0, #(pixels) rectangular pads seem to be okay? (not tested much)
TRACE_ADJUST => 0, #(pixels) traces seemed to be okay?
REDUCE_TOLERANCE => .001, #(inches) allow this much variation when reducing circles and rects
};
#Also, my CAD's Print function or the PDF print driver I used was a little off for circles, so define some additional adjustment values here:
#Values are added to X/Y coordinates; units are pixels; for example, a value of 1 at 600 dpi would be ~= .002 inch
use constant
{
CIRCLE_ADJUST_MINX => 0,
CIRCLE_ADJUST_MINY => -0.001 * 600, #-1, #circles were a little too high, so nudge them a little lower
CIRCLE_ADJUST_MAXX => +0.001 * 600, #+1, #circles were a little too far to the left, so nudge them a little to the right
CIRCLE_ADJUST_MAXY => 0,
SUBST_CIRCLE_CLIPRECT => FALSE, #generate circle and substitute for clip rects (to compensate for the way some CAD software draws circles)
WANT_CLIPRECT => TRUE, #FALSE, #AI doesn't need clip rect at all? should be on normally?
RECT_COMPLETION => FALSE, #TRUE, #fill in 4th side of rect when 3 sides found
};
#allow .012 clearance around pads for solder mask:
#This value effectively adjusts pad sizes in the TOOL_SIZES list above (only for solder mask layers).
use constant SOLDER_MARGIN => +.012; #units are inches
#line join/cap styles:
use constant
{
CAP_NONE => 0, #butt (none); line is exact length
CAP_ROUND => 1, #round cap/join; line overhangs by a semi-circle at either end
CAP_SQUARE => 2, #square cap/join; line overhangs by a half square on either end
CAP_OVERRIDE => FALSE, #cap style overrides drawing logic
};
#number of elements in each shape type:
use constant
{
RECT_SHAPELEN => 6, #x0, y0, x1, y1, count, "rect" (start, end corners)
LINE_SHAPELEN => 6, #x0, y0, x1, y1, count, "line" (line seg)
CURVE_SHAPELEN => 10, #xstart, ystart, x0, y0, x1, y1, xend, yend, count, "curve" (bezier 2 points)
CIRCLE_SHAPELEN => 5, #x, y, 5, count, "circle" (center + radius)
};
#const my %SHAPELEN =
#Readonly my %SHAPELEN =>
our %SHAPELEN =
(
rect => RECT_SHAPELEN,
line => LINE_SHAPELEN,
curve => CURVE_SHAPELEN,
circle => CIRCLE_SHAPELEN,
);
#panelization:
#This will repeat the entire body the number of times indicated along the X or Y axes (files grow accordingly).
#Display elements that overhang PCB boundary can be squashed or left as-is (typically text or other silk screen markings).
#Set "overhangs" TRUE to allow overhangs, FALSE to truncate them.
#xpad and ypad allow margins to be added around outer edge of panelized PCB.
use constant PANELIZE => {'x' => 1, 'y' => 1, 'xpad' => 0, 'ypad' => 0, 'overhangs' => TRUE}; #number of times to repeat in X and Y directions
# Set this to 1 if you need TurboCAD support.
#$turboCAD = FALSE; #is this still needed as an option?
#CIRCAD pad generation uses an appropriate aperture, then moves it (stroke) "a little" - we use this to find pads and distinguish them from PCB holes.
use constant PAD_STROKE => 0.3; #0.0005 * 600; #units are pixels
#convert very short traces to pads or holes:
use constant TRACE_MINLEN => .001; #units are inches
#use constant ALWAYS_XY => TRUE; #FALSE; #force XY even if X or Y doesn't change; NOTE: needs to be TRUE for all pads to show in FlatCAM and ViewPlot
use constant REMOVE_POLARITY => FALSE; #TRUE; #set to remove subtractive (negative) polarity; NOTE: must be FALSE for ground planes
#PDF uses "points", each point = 1/72 inch
#combined with a PDF scale factor of .12, this gives 600 dpi resolution (1/72 * .12 = 600 dpi)
use constant INCHES_PER_POINT => 1/72; #0.0138888889; #multiply point-size by this to get inches
# The precision used when computing a bezier curve. Higher numbers are more precise but slower (and generate larger files).
#$bezierPrecision = 100;
use constant BEZIER_PRECISION => 36; #100; #use const; reduced for faster rendering (mainly used for silk screen and thermal pads)
# Ground planes and silk screen or larger copper rectangles or circles are filled line-by-line using this resolution.
use constant FILL_WIDTH => .01; #fill at most 0.01 inch at a time
# The max number of characters to read into memory
use constant MAX_BYTES => 10 * M; #bumped up to 10 MB, use const
use constant DUP_DRILL1 => TRUE; #FALSE; #kludge: ViewPlot doesn't load drill files that are too small so duplicate first tool
my $runtime = time(); #Time::HiRes::gettimeofday(); #measure my execution time
print STDERR "Loaded config settings from '${\(__FILE__)}'.\n";
1; #last value must be truthful to indicate successful load
#############################################################################################
#junk/experiment:
#use Package::Constants;
#use Exporter qw(import); #https://perldoc.perl.org/Exporter.html
#my $caller = "pdf2gerb::";
#sub cfg
#{
# my $proto = shift;
# my $class = ref($proto) || $proto;
# my $settings =
# {
# $WANT_DEBUG => 990, #10; #level of debug wanted; higher == more, lower == less, 0 == none
# };
# bless($settings, $class);
# return $settings;
#}
#use constant HELLO => "hi there2"; #"main::HELLO" => "hi there";
#use constant GOODBYE => 14; #"main::GOODBYE" => 12;
#print STDERR "read cfg file\n";
#our @EXPORT_OK = Package::Constants->list(__PACKAGE__); #https://www.perlmonks.org/?node_id=1072691; NOTE: "_OK" skips short/common names
#print STDERR scalar(@EXPORT_OK) . " consts exported:\n";
#foreach(@EXPORT_OK) { print STDERR "$_\n"; }
#my $val = main::thing("xyz");
#print STDERR "caller gave me $val\n";
#foreach my $arg (@ARGV) { print STDERR "arg $arg\n"; }
Author: swannman
Source Code: https://github.com/swannman/pdf2gerb
License: GPL-3.0 license
1650446963
In this guide, you’ll learn how to Upload, Preview & Download Images using JavaScript & PHP.
To create Upload, Preview & Download Images using JavaScript & PHP. First, you need to create two Files one PHP File and another one is CSS File.
<?php
//if download button clicked
if(isset($_POST['downloadBtn'])){
//getting the user img url from input field
$imgURL = $_POST['file']; //storing in variable
$regPattern = '/\.(jpe?g|png|gif|bmp)$/i'; //pattern to validataing img extension
if(preg_match($regPattern, $imgURL)){ //if pattern matched to user img url
$initCURL = curl_init($imgURL); //intializing curl
curl_setopt($initCURL, CURLOPT_RETURNTRANSFER, true);
$downloadImgLink = curl_exec($initCURL); //executing curl
curl_close($initCURL); //closing curl
// now we convert the base 64 format to jpg to download
header('Content-type: image/jpg'); //in which extension you want to save img
header('Content-Disposition: attachment;filename="image.jpg"'); //in which name you want to save img
echo $downloadImgLink;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Download in PHP | Codequs</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<div class="wrapper">
<div class="preview-box">
<div class="cancel-icon"><i class="fas fa-times"></i></div>
<div class="img-preview"></div>
<div class="content">
<div class="img-icon"><i class="far fa-image"></i></div>
<div class="text">Paste the image url below, <br/>to see a preview or download!</div>
</div>
</div>
<form action="index.php" method="POST" class="input-data">
<input id="field" type="text" name="file" placeholder="Paste the image url to download..." autocomplete="off">
<input id="button" name="downloadBtn" type="submit" value="Download">
</form>
</div>
<script>
$(document).ready(function(){
//if user focus out from the input field
$("#field").on("focusout", function(){
//getting user entered img URL
var imgURL = $("#field").val();
if(imgURL != ""){ //if input field isn't blank
var regPattern = /\.(jpe?g|png|gif|bmp)$/i; //pattern to validataing img extension
if(regPattern.test(imgURL)){ //if pattern matched to image url
var imgTag = '<img src="'+ imgURL +'" alt="">'; //creating a new img tag to show img
$(".img-preview").append(imgTag); //appending img tag with user entered img url
// adding new class which i've created in css
$(".preview-box").addClass("imgActive");
$("#button").addClass("active");
$("#field").addClass("disabled");
$(".cancel-icon").on("click", function(){
//we'll remove all new added class on cancel icon click
$(".preview-box").removeClass("imgActive");
$("#button").removeClass("active");
$("#field").removeClass("disabled");
$(".img-preview img").remove();
// that's all in javascript/jquery now the main part is PHP
});
}else{
alert("Invalid img URL - " + imgURL);
$("#field").val('');//if pattern not matched we'll leave the input field blank
}
}
});
});
</script>
</body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
html,body{
display: grid;
height: 100%;
place-items: center;
}
::selection{
color: #fff;
background: #4158d0;
}
.wrapper{
height: 450px;
width: 500px;
display: flex;
align-items: center;
justify-content: space-between;
flex-direction: column;
}
.wrapper .preview-box{
position: relative;
width: 100%;
height: 320px;
display: flex;
text-align: center;
align-items: center;
justify-content: center;
border-radius: 5px;
border: 2px dashed #c2cdda;
}
.preview-box.imgActive{
border: 2px solid transparent;
}
.preview-box .cancel-icon{
position: absolute;
right: 20px;
top: 10px;
z-index: 999;
color: #4158d0;
font-size: 20px;
cursor: pointer;
display: none;
}
.preview-box.imgActive:hover .cancel-icon{
display: block;
}
.preview-box .cancel-icon:hover{
color: #ff0000;
}
.preview-box .img-preview{
height: 100%;
width: 100%;
position: absolute;
}
.preview-box .img-preview img{
height: 100%;
width: 100%;
border-radius: 5px;
}
.wrapper .preview-box .img-icon{
font-size: 100px;
background: linear-gradient(-135deg, #c850c0, #4158d0);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.wrapper .preview-box .text{
font-size: 18px;
font-weight: 500;
color: #5B5B7B;
}
.wrapper .input-data{
height: 130px;
width: 100%;;
display: flex;
align-items: center;
justify-content: space-evenly;
flex-direction: column;
}
.wrapper .input-data #field{
width: 100%;
height: 50px;
outline: none;
font-size: 17px;
padding: 0 15px;
user-select: auto;
border-radius: 5px;
border: 2px solid lightgrey;
transition: all 0.3s ease;
}
.input-data #field.disabled{
color: #b3b3b3;
pointer-events: none;
}
.wrapper .input-data #field:focus{
border-color: #4158d0;
}
.input-data #field::placeholder{
color: #b3b3b3;
}
.wrapper .input-data #button{
height: 50px;
width: 100%;
border: none;
outline: none;
color: #fff;
font-weight: 500;
font-size: 18px;
cursor: pointer;
border-radius: 5px;
opacity: 0.5;
pointer-events: none;
background: linear-gradient(-135deg, #c850c0, #4158d0);
transition: all 0.3s ease;
}
.input-data #button.active{
opacity: 1;
pointer-events: auto;
}
.input-data #button:active{
transform: scale(0.99);
}
Now you’ve successfully created a How to Upload, Preview & Download Image using JavaScript & PHP.
1615040237
PHP jquery ajax POST request with MySQL. In this tutorial, you will learn how to create and submit a simple form in PHP using jQuery ajax post request. And how to submit a form data into MySQL database without the whole page refresh or reload. And also you will learn how to show an error message to the user if the user does not fill any form field.
And this tutorial also guide on how to send data to MySQL database using AJAX + jQuery + PHP without reloading the whole page and show a client-side validation error message if it has an error in the form.
Just follow the few below steps and easily create and submit ajax form in PHP and MySQL with client-side validation.
https://www.tutsmake.com/php-jquery-ajax-post-tutorial-example/
#jquery ajax serialize form data example #submit form using ajax in php example #save form data using ajax in php #how to insert form data using ajax in php #php jquery ajax form submit example #jquery ajax and jquery post form submit example with php
1659408900
TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
The TinyTDS gem is meant to serve the extremely common use-case of connecting, querying and iterating over results to Microsoft SQL Server or Sybase databases from Ruby using the FreeTDS's DB-Library API.
TinyTDS offers automatic casting to Ruby primitives along with proper encoding support. It converts all SQL Server datatypes to native Ruby primitives while supporting :utc or :local time zones for time-like types. To date it is the only Ruby client library that allows client encoding options, defaulting to UTF-8, while connecting to SQL Server. It also properly encodes all string and binary data. The motivation for TinyTDS is to become the de-facto low level connection mode for the SQL Server Adapter for ActiveRecord.
The API is simple and consists of these classes:
Installing with rubygems should just work. TinyTDS is currently tested on Ruby version 2.0.0 and upward.
$ gem install tiny_tds
If you use Windows, we pre-compile TinyTDS with static versions of FreeTDS and supporting libraries. If you're using RubyInstaller the binary gem will require that devkit is installed and in your path to operate properly.
On all other platforms, we will find these dependencies. It is recommended that you install the latest FreeTDS via your method of choice. For example, here is how to install FreeTDS on Ubuntu. You might also need the build-essential
and possibly the libc6-dev
packages.
$ apt-get install wget
$ apt-get install build-essential
$ apt-get install libc6-dev
$ wget http://www.freetds.org/files/stable/freetds-1.1.24.tar.gz
$ tar -xzf freetds-1.1.24.tar.gz
$ cd freetds-1.1.24
$ ./configure --prefix=/usr/local --with-tdsver=7.3
$ make
$ make install
Please read the MiniPortile and/or Windows sections at the end of this file for advanced configuration options past the following:
--with-freetds-dir=DIR
Use the freetds library placed under DIR.
Optionally, Microsoft has done a great job writing some articles on how to get started with SQL Server and Ruby using TinyTDS. Please checkout one of the following posts that match your platform.
TinyTDS is developed against FreeTDS 0.95, 0.99, and 1.0 current. Our default and recommended is 1.0. We also test with SQL Server 2008, 2014, and Azure. However, usage of TinyTDS with SQL Server 2000 or 2005 should be just fine. Below are a few QA style notes about installing FreeTDS.
NOTE: Windows users of our pre-compiled native gems need not worry about installing FreeTDS and its dependencies.
Do I need to install FreeTDS? Yes! Somehow, someway, you are going to need FreeTDS for TinyTDS to compile against.
OK, I am installing FreeTDS, how do I configure it? Contrary to what most people think, you do not need to specially configure FreeTDS in any way for client libraries like TinyTDS to use it. About the only requirement is that you compile it with libiconv for proper encoding support. FreeTDS must also be compiled with OpenSSL (or the like) to use it with Azure. See the "Using TinyTDS with Azure" section below for more info.
Do I need to configure --with-tdsver
equal to anything? Most likely! Technically you should not have to. This is only a default for clients/configs that do not specify what TDS version they want to use. We are currently having issues with passing down a TDS version with the login bit. Till we get that fixed, if you are not using a freetds.conf or a TDSVER environment variable, then make sure to use 7.1.
But I want to use TDS version 7.2 for SQL Server 2005 and up! TinyTDS uses TDS version 7.1 (previously named 8.0) and fully supports all the data types supported by FreeTDS, this includes varchar(max)
and nvarchar(max)
. Technically compiling and using TDS version 7.2 with FreeTDS is not supported. But this does not mean those data types will not work. I know, it's confusing If you want to learn more, read this thread. http://lists.ibiblio.org/pipermail/freetds/2011q3/027306.html
I want to configure FreeTDS using --enable-msdblib
and/or --enable-sybase-compat
so it works for my database. Cool? It's a waste of time and totally moot! Client libraries like TinyTDS define their own C structure names where they diverge from Sybase to SQL Server. Technically we use the MSDBLIB structures which does not mean we only work with that database vs Sybase. These configs are just a low level default for C libraries that do not define what they want. So I repeat, you do not NEED to use any of these, nor will they hurt anything since we control what C structure names we use internally!
Our goal is to support every SQL Server data type and covert it to a logical Ruby object. When dates or times are returned, they are instantiated to either :utc
or :local
time depending on the query options. Only [datetimeoffset] types are excluded. All strings are associated the to the connection's encoding and all binary data types are associated to Ruby's ASCII-8BIT/BINARY
encoding.
Below is a list of the data types we support when using the 7.3 TDS protocol version. Using a lower protocol version will result in these types being returned as strings.
Connect to a database.
client = TinyTds::Client.new username: 'sa', password: 'secret', host: 'mydb.host.net'
Creating a new client takes a hash of options. For valid iconv encoding options, see the output of iconv -l
. Only a few have been tested and highly recommended to leave blank for the UTF-8 default.
TinyTds::Client
object. If you are using 1.0rc5 or later, all clients will have an independent timeout setting as you'd expect. Timeouts caused by network failure will raise a timeout error 1 second after the configured timeout limit is hit (see #481 for details).call
-able object such as a Proc
or a method to receive info messages from the database. It should have a single parameter, which will be a TinyTds::Error
object representing the message. For example:opts = ... # host, username, password, etc
opts[:message_handler] = Proc.new { |m| puts m.message }
client = TinyTds::Client.new opts
# => Changed database context to 'master'.
# => Changed language setting to us_english.
client.execute("print 'hello world!'").do
# => hello world!
Use the #active?
method to determine if a connection is good. The implementation of this method may change but it should always guarantee that a connection is good. Current it checks for either a closed or dead connection.
client.dead? # => false
client.closed? # => false
client.active? # => true
client.execute("SQL TO A DEAD SERVER")
client.dead? # => true
client.closed? # => false
client.active? # => false
client.close
client.closed? # => true
client.active? # => false
Escape strings.
client.escape("How's It Going'") # => "How''s It Going''"
Send a SQL string to the database and return a TinyTds::Result object.
result = client.execute("SELECT * FROM [datatypes]")
A result object is returned by the client's execute command. It is important that you either return the data from the query, most likely with the #each method, or that you cancel the results before asking the client to execute another SQL batch. Failing to do so will yield an error.
Calling #each on the result will lazily load each row from the database.
result.each do |row|
# By default each row is a hash.
# The keys are the fields, as you'd expect.
# The values are pre-built Ruby primitives mapped from their corresponding types.
end
A result object has a #fields
accessor. It can be called before the result rows are iterated over. Even if no rows are returned, #fields will still return the column names you expected. Any SQL that does not return columned data will always return an empty array for #fields
. It is important to remember that if you access the #fields
before iterating over the results, the columns will always follow the default query option's :symbolize_keys
setting at the client's level and will ignore the query options passed to each.
result = client.execute("USE [tinytdstest]")
result.fields # => []
result.do
result = client.execute("SELECT [id] FROM [datatypes]")
result.fields # => ["id"]
result.cancel
result = client.execute("SELECT [id] FROM [datatypes]")
result.each(:symbolize_keys => true)
result.fields # => [:id]
You can cancel a result object's data from being loading by the server.
result = client.execute("SELECT * FROM [super_big_table]")
result.cancel
You can use results cancelation in conjunction with results lazy loading, no problem.
result = client.execute("SELECT * FROM [super_big_table]")
result.each_with_index do |row, i|
break if row > 10
end
result.cancel
If the SQL executed by the client returns affected rows, you can easily find out how many.
result.each
result.affected_rows # => 24
This pattern is so common for UPDATE and DELETE statements that the #do method cancels any need for loading the result data and returns the #affected_rows
.
result = client.execute("DELETE FROM [datatypes]")
result.do # => 72
Likewise for INSERT
statements, the #insert method cancels any need for loading the result data and executes a SCOPE_IDENTITY()
for the primary key.
result = client.execute("INSERT INTO [datatypes] ([xml]) VALUES ('<html><br/></html>')")
result.insert # => 420
The result object can handle multiple result sets form batched SQL or stored procedures. It is critical to remember that when calling each with a block for the first time will return each "row" of each result set. Calling each a second time with a block will yield each "set".
sql = ["SELECT TOP (1) [id] FROM [datatypes]",
"SELECT TOP (2) [bigint] FROM [datatypes] WHERE [bigint] IS NOT NULL"].join(' ')
set1, set2 = client.execute(sql).each
set1 # => [{"id"=>11}]
set2 # => [{"bigint"=>-9223372036854775807}, {"bigint"=>9223372036854775806}]
result = client.execute(sql)
result.each do |rowset|
# First time data loading, yields each row from each set.
# 1st: {"id"=>11}
# 2nd: {"bigint"=>-9223372036854775807}
# 3rd: {"bigint"=>9223372036854775806}
end
result.each do |rowset|
# Second time over (if columns cached), yields each set.
# 1st: [{"id"=>11}]
# 2nd: [{"bigint"=>-9223372036854775807}, {"bigint"=>9223372036854775806}]
end
Use the #sqlsent?
and #canceled?
query methods on the client to determine if an active SQL batch still needs to be processed and or if data results were canceled from the last result object. These values reset to true and false respectively for the client at the start of each #execute
and new result object. Or if all rows are processed normally, #sqlsent?
will return false. To demonstrate, lets assume we have 100 rows in the result object.
client.sqlsent? # = false
client.canceled? # = false
result = client.execute("SELECT * FROM [super_big_table]")
client.sqlsent? # = true
client.canceled? # = false
result.each do |row|
# Assume we break after 20 rows with 80 still pending.
break if row["id"] > 20
end
client.sqlsent? # = true
client.canceled? # = false
result.cancel
client.sqlsent? # = false
client.canceled? # = true
It is possible to get the return code after executing a stored procedure from either the result or client object.
client.return_code # => nil
result = client.execute("EXEC tinytds_TestReturnCodes")
result.do
result.return_code # => 420
client.return_code # => 420
Every TinyTds::Result
object can pass query options to the #each method. The defaults are defined and configurable by setting options in the TinyTds::Client.default_query_options
hash. The default values are:
Each result gets a copy of the default options you specify at the client level and can be overridden by passing an options hash to the #each method. For example
result.each(:as => :array, :cache_rows => false) do |row|
# Each row is now an array of values ordered by #fields.
# Rows are yielded and forgotten about, freeing memory.
end
Besides the standard query options, the result object can take one additional option. Using :first => true
will only load the first row of data and cancel all remaining results.
result = client.execute("SELECT * FROM [super_big_table]")
result.each(:first => true) # => [{'id' => 24}]
By default row caching is turned on because the SQL Server adapter for ActiveRecord would not work without it. I hope to find some time to create some performance patches for ActiveRecord that would allow it to take advantages of lazily created yielded rows from result objects. Currently only TinyTDS and the Mysql2 gem allow such a performance gain.
TinyTDS takes an opinionated stance on how we handle encoding errors. First, we treat errors differently on reads vs. writes. Our opinion is that if you are reading bad data due to your client's encoding option, you would rather just find ?
marks in your strings vs being blocked with exceptions. This is how things wold work via ODBC or SMS. On the other hand, writes will raise an exception. In this case we raise the SYBEICONVO/2402 error message which has a description of Error converting characters into server's character set. Some character(s) could not be converted.
. Even though the severity of this message is only a 4
and TinyTDS will automatically strip/ignore unknown characters, we feel you should know that you are inserting bad encodings. In this way, a transaction can be rolled back, etc. Remember, any database write that has bad characters due to the client encoding will still be written to the database, but it is up to you rollback said write if needed. Most ORMs like ActiveRecord handle this scenario just fine.
TinyTDS will raise a TinyTDS::Error
when a timeout is reached based on the options supplied to the client. Depending on the reason for the timeout, the connection could be dead or alive. When db processing is the cause for the timeout, the connection should still be usable after the error is raised. When network failure is the cause of the timeout, the connection will be dead. If you attempt to execute another command batch on a dead connection you will see a DBPROCESS is dead or not enabled
error. Therefore, it is recommended to check for a dead?
connection before trying to execute another command batch.
The TinyTDS gem uses binstub wrappers which mirror compiled FreeTDS Utilities binaries. These native executables are usually installed at the system level when installing FreeTDS. However, when using MiniPortile to install TinyTDS as we do with Windows binaries, these binstubs will find and prefer local gem exe
directory executables. These are the following binstubs we wrap.
TinyTDS is the default connection mode for the SQL Server adapter in versions 3.1 or higher. The SQL Server adapter can be found using the links below.
TinyTDS is fully tested with the Azure platform. You must set the azure: true
connection option when connecting. This is needed to specify the default database name in the login packet since Azure has no notion of USE [database]
. FreeTDS must be compiled with OpenSSL too.
IMPORTANT: Do not use username@server.database.windows.net
for the username connection option! You must use the shorter username@server
instead!
Also, please read the Azure SQL Database General Guidelines and Limitations MSDN article to understand the differences. Specifically, the connection constraints section!
A DBLIB connection does not have the same default SET options for a standard SMS SQL Server connection. Hence, we recommend the following options post establishing your connection.
SET ANSI_DEFAULTS ON
SET QUOTED_IDENTIFIER ON
SET CURSOR_CLOSE_ON_COMMIT OFF
SET IMPLICIT_TRANSACTIONS OFF
SET TEXTSIZE 2147483647
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_NULL_DFLT_ON ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET QUOTED_IDENTIFIER ON
SET CURSOR_CLOSE_ON_COMMIT OFF
SET IMPLICIT_TRANSACTIONS OFF
SET TEXTSIZE 2147483647
SET CONCAT_NULL_YIELDS_NULL ON
TinyTDS must be used with a connection pool for thread safety. If you use ActiveRecord or the Sequel gem this is done for you. However, if you are using TinyTDS on your own, we recommend using the ConnectionPool gem when using threads:
Please read our thread_test.rb file for details on how we test its usage.
This is possible using FreeTDS version 0.95 or higher. You must use the use_utf16
login option or add the following config to your freetds.conf
in either the global section or a specfic dataserver. If you are on Windows, the default location for your conf file will be in C:\Sites
.
[global]
use utf-16 = true
The default is true and since FreeTDS v1.0 would do this as well.
For the convenience of Windows users, TinyTDS ships pre-compiled gems for supported versions of Ruby on Windows. In order to generate these gems, rake-compiler-dock is used. This project provides several Docker images with rvm, cross-compilers and a number of different target versions of Ruby.
Run the following rake task to compile the gems for Windows. This will check the availability of Docker (and boot2docker on Windows or OS-X) and will give some advice for download and installation. When docker is running, it will download the docker image (once-only) and start the build:
$ rake gem:windows
The compiled gems will exist in ./pkg
directory.
First, clone the repo using the command line or your Git GUI of choice.
$ git clone git@github.com:rails-sqlserver/tiny_tds.git
After that, the quickest way to get setup for development is to use Docker. Assuming you have downloaded docker for your platform, you can use docker-compose to run the necessary containers for testing.
$ docker-compose up -d
This will download our SQL Server for Linux Docker image based from microsoft/mssql-server-linux/. Our image already has the [tinytdstest]
DB and tinytds
users created. This will also download a toxiproxy Docker image which we can use to simulate network failures for tests. Basically, it does the following.
$ docker network create main-network
$ docker pull metaskills/mssql-server-linux-tinytds
$ docker run -p 1433:1433 -d --name sqlserver --network main-network metaskills/mssql-server-linux-tinytds
$ docker pull shopify/toxiproxy
$ docker run -p 8474:8474 -p 1234:1234 -d --name toxiproxy --network main-network shopify/toxiproxy
If you are using your own database. Make sure to run these SQL commands as SA to get the test database and user installed.
CREATE DATABASE [tinytdstest];
CREATE LOGIN [tinytds] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [tinytdstest];
USE [tinytdstest];
CREATE USER [tinytds] FOR LOGIN [tinytds];
EXEC sp_addrolemember N'db_owner', N'tinytds';
From here you can build and run tests against an installed version of FreeTDS.
$ bundle install
$ bundle exec rake
Examples us using enviornment variables to customize the test task.
$ rake TINYTDS_UNIT_DATASERVER=mydbserver
$ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2008
$ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
$ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_UNIT_PORT=5000 TINYTDS_SCHEMA=sybase_ase
If you use a multi stage Docker build to assemble your gems in one phase and then copy your app and gems into another, lighter, container without build tools you will need to make sure you tell the OS how to find dependencies for TinyTDS.
After you have built and installed FreeTDS it will normally place library files in /usr/local/lib
. When TinyTDS builds native extensions, it already knows to look here but if you copy your app to a new container that link will be broken.
Set the LD_LIBRARY_PATH environment variable export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}
and run ldconfig
. If you run ldd tiny_tds.so
you should not see any broken links. Make sure you also copied in the library dependencies from your build container with a command like COPY --from=builder /usr/local/lib /usr/local/lib
.
My name is Ken Collins and I currently maintain the SQL Server adapter for ActiveRecord and wrote this library as my first cut into learning Ruby C extensions. Hopefully it will help promote the power of Ruby and the Rails framework to those that have not yet discovered it. My blog is metaskills.net and I can be found on twitter as @metaskills. Enjoy!
TinyTDS is Copyright (c) 2010-2015 Ken Collins, ken@metaskills.net and Will Bond (Veracross LLC) wbond@breuer.com. It is distributed under the MIT license. Windows binaries contain pre-compiled versions of FreeTDS http://www.freetds.org/ which is licensed under the GNU LGPL license at http://www.gnu.org/licenses/lgpl-2.0.html
Author: rails-sqlserver
Source code: https://github.com/rails-sqlserver/tiny_tds
License:
1667086140
This bundle provides a collection of annotations for Symfony2 Controllers, designed to streamline the creation of certain objects and enable smaller and more concise actions.
By default, all annotations are loaded, but any individual annotation can be completely disabled by setting to false active
parameter.
Default values are:
controller_extra:
resolver_priority: -8
request: current
paginator:
active: true
default_name: paginator
default_page: 1
default_limit_per_page: 10
entity:
active: true
default_name: entity
default_persist: true
default_mapping_fallback: false
default_factory_method: create
default_factory_mapping: true
form:
active: true
default_name: form
object_manager:
active: true
default_name: form
flush:
active: true
default_manager: default
json_response:
active: true
default_status: 200
default_headers: []
log:
active: true
default_level: info
default_execute: pre
ResolverEventListener is subscribed to
kernel.controller
event with priority -8. This element can be configured and customized withresolver_priority
config value. If you need to get ParamConverter entities, make sure that this value is lower than 0. The reason is that this listener must be executed always after ParamConverter one.
Entity provider
In some annotations, you can define an entity by several ways. This chapter is about how you can define them.
You can define an entity using its namespace. A simple new new()
be performed.
/**
* Simple controller method
*
* @SomeAnnotation(
* class = "Mmoreram\CustomBundle\Entity\MyEntity",
* )
*/
public function indexAction()
{
}
You can define an entity using Doctrine shortcut notations. With this format you should ensure that your Entities follow Symfony Bundle standards and your entities are placed under Entity/
folder.
/**
* Simple controller method
*
* @SomeAnnotation(
* class = "MmoreramCustomBundle:MyEntity",
* )
*/
public function indexAction()
{
}
You can define an entity using a simple config parameter. Some projects use parameters to define all entity namespaces (To allow overriding). If you define the entity with a parameter, this bundle will try to instance it with a simple new()
accessing directly to the container ParametersBag.
parameters:
#
# Entities
#
my.bundle.entity.myentity: Mmoreram\CustomBundle\Entity\MyEntity
/**
* Simple controller method
*
* @SomeAnnotation(
* class = "my.bundle.entity.myentity",
* )
*/
public function indexAction()
{
}
Controller annotations
This bundle provide a reduced but useful set of annotations for your controller actions.
Creates a Doctrine Paginator object, given a request and a configuration. This annotation just injects into de controller a new Doctrine\ORM\Tools\Pagination\Pagination
instance ready to be iterated.
You can enable/disable this bundle by overriding active
flag in configuration file config.yml
controller_extra:
pagination:
active: true
By default, if
name
option is not set, the generated object will be placed in a parameter named$paginator
. This behaviour can be configured usingdefault_name
in configuration.
This annotation can be configured with these sections
To create a new Pagination object you need to refer to an existing Entity. You can check all available formats you can define it just reading the Entity Provider section.
<?php
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* )
*/
public function indexAction(Paginator $paginator)
{
}
You need to specify Paginator annotation the page to fetch. By default, if none is specified, this bundle will use the default one defined in configuration. You can override in config.yml
controller_extra:
pagination:
default_page: 1
You can refer to an existing Request attribute using ~value~
format, to any $_GET
element by using format ?field?
or to any $_POST
by using format #field#
You can choose between Master Request or Current Request accessing to its attributes, by configuring the request value of the configuration.
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/{foo}
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* page = "~foo~"
* )
*/
public function indexAction(Paginator $paginator)
{
}
or you can hardcode the page to use.
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* page = 1
* )
*/
public function indexAction(Paginator $paginator)
{
}
You need to specify Paginator annotation the limit to fetch. By default, if none is specified, this bundle will use the default one defined in configuration. You can override in config.yml
controller_extra:
pagination:
default_limit_per_page: 10
You can refer to an existing Request attribute using ~value~
format, to any $_GET
element by using format ?field?
or to any $_POST
by using format #field#
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/{foo}/{limit}
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* page = "~foo~",
* limit = "~limit~"
* )
*/
public function indexAction(Paginator $paginator)
{
}
or you can hardcode the page to use.
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* page = 1,
* limit = 10
* )
*/
public function indexAction(Paginator $paginator)
{
}
You can order your Pagination just defining the fields you want to orderBy and the desired direction. The orderBy
section must be defined as an array of arrays, and each array should contain these positions:
x
)use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* orderBy = {
* {"x", "createdAt", "ASC"},
* {"x", "updatedAt", "DESC"},
* {"x", "id", 1, {
* 0 => "ASC",
* 1 => "DESC",
* }},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
With the third and fourth value you can define a map where to match your own direction nomenclature with DQL one. DQL nomenclature just accept ASC for Ascendant and DESC for Descendant.
This is very useful when you need to match a url format with the DQL one. You can refer to an existing Request attribute using ~value~
format, to any $_GET
element by using format ?field?
or to any $_POST
by using format #field#
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/order/{field}/{direction}
*
* For example, some matchings...
*
* /myroute/paginate/order/id/1 -> ORDER BY id DESC
* /myroute/paginate/order/enabled/0 - ORDER BY enabled ASC
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* orderBy = {
* {"x", "createdAt", "ASC"},
* {"x", "updatedAt", "DESC"},
* {"x", "~field~", ~direction~, {
* 0 => "ASC",
* 1 => "DESC",
* }},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
The order of the definitions will alter the order of the DQL query.
You can define some where statements in your Paginator. The wheres
section must be defined as an array of arrays, and each array should contain these positions:
x
)use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* wheres = {
* {"x", "enabled", "=", true},
* {"x", "age", ">", 18},
* {"x", "name", "LIKE", "Eferv%"},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
You can refer to an existing Request attribute using ~value~
format, to any $_GET
element by using format ?field?
or to any $_POST
by using format #field#
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/{field}
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* wheres = {
* {"x", "name", "LIKE", "~field~"},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
You can use as well this feature for optional filtering by setting the last position to true
. In that case, if the filter value is not found, such line will be ignored.
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /myroute?query=name%
* This Controller matches pattern /myroute as well
*
* In both cases this will work. In the first case we will apply the where line
* in the paginator. In the second case, we wont.
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* wheres = {
* {"x", "name", "LIKE", "?query?", true},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
You can also define some fields to not null. Is same as wheres
section, but specific for NULL assignments. The notNulls
section must be defined as an array of arrays, and each array should contain these positions:
x
)use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* notNulls = {
* {"x", "enabled"},
* {"x", "deleted"},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
You can do some left joins in this section. The leftJoins
section must be defined as an array of array, where each array can have these fields:
x
)use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* leftJoins = {
* {"x", "User", "u", true},
* {"x", "Address", "a", true},
* {"x", "Cart", "c"},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
You can do some inner joins in this section. The innerJoins
section must be defined as an array of array, where each array can have these fields:
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* innerJoins = {
* {"x", "User", "u", true},
* {"x", "Address", "a", true},
* {"x", "Cart", "c"},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
A nice feature of this annotation is that you can also inject into your controller a Mmoreram\ControllerExtraBundle\ValueObject\PaginatorAttributes
instance with some interesting information about your pagination.
To inject this object you need to define the "attributes" annotation field with the method parameter name.
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
use Mmoreram\ControllerExtraBundle\ValueObject\PaginatorAttributes;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/
*
* @CreatePaginator(
* attributes = "paginatorAttributes",
* entityNamespace = "MmoreramCustomBundle:User",
* page = 1,
* limit = 10
* )
*/
public function indexAction(
Paginator $paginator,
PaginatorAttributes $paginatorAttributes
)
{
$currentPage = $paginatorAttributes->getCurrentPage();
$totalElements = $paginatorAttributes->getTotalElements();
$totalPages = $paginatorAttributes->getTotalPages();
$limitPerPage = $paginatorAttributes->getLimitPerPage();
}
This is a completed example and its DQL resolution
use Doctrine\ORM\Tools\Pagination\Pagination;
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
/**
* Simple controller method
*
* This Controller matches pattern /paginate/nb/{limit}/{page}
*
* Where:
*
* * limit = 10
* * page = 1
*
* @CreatePaginator(
* entityNamespace = "ControllerExtraBundle:Fake",
* page = "~page~",
* limit = "~limit~",
* orderBy = {
* { "x", "createdAt", "ASC" },
* { "x", "updatedAt", "DESC" },
* { "x", "id", "0", {
* "1" = "ASC",
* "2" = "DESC",
* }}
* },
* wheres = {
* { "x", "enabled" , "=", true }
* },
* leftJoins = {
* { "x", "relation", "r" },
* { "x", "relation2", "r2" },
* { "x", "relation5", "r5", true },
* },
* innerJoins = {
* { "x", "relation3", "r3" },
* { "x", "relation4", "r4", true },
* },
* notNulls = {
* {"x", "address1"},
* {"x", "address2"},
* }
* )
*/
public function indexAction(Paginator $paginator)
{
}
The DQL generated by this annotation is
SELECT x, r4, r5
FROM Mmoreram\\ControllerExtraBundle\\Tests\\FakeBundle\\Entity\\Fake x
INNER JOIN x.relation3 r3
INNER JOIN x.relation4 r4
LEFT JOIN x.relation r
LEFT JOIN x.relation2 r2
LEFT JOIN x.relation5 r5
WHERE enabled = ?where0
AND x.address1 IS NOT NULL
AND x.address2 IS NOT NULL
ORDER BY createdAt ASC, id ASC
This annotation can create a PagerFanta instance if you need it. You only have to define your parameter as such, and the annotation resolver will wrap your paginator with a Pagerfanta object instance.
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
use Pagerfanta\Pagerfanta;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* page = 1,
* limit = 10
* )
*/
public function indexAction(Pagerfanta $paginator)
{
}
This annotation can create a KNPPaginator instance if you need it. You only have to define your parameter as such, and the annotation resolver will wrap your paginator with a KNPPaginator object instance.
use Mmoreram\ControllerExtraBundle\Annotation\CreatePaginator;
use Knp\Component\Pager\Pagination\PaginationInterface;
/**
* Simple controller method
*
* This Controller matches pattern /myroute/paginate/
*
* @CreatePaginator(
* entityNamespace = "MmoreramCustomBundle:User",
* page = 1,
* limit = 10
* )
*/
public function indexAction(PaginationInterface $paginator)
{
}
Loads an entity from your database, or creates a new one.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Entity;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @Entity(
* namespace = "MmoreramCustomBundle:User",
* name = "user"
* )
*/
public function indexAction(User $user)
{
}
By default, if
name
option is not set, the generated object will be placed in a parameter named$entity
. This behaviour can be configured usingdefault_name
in configuration.
You can also use setters in Entity annotation. It means that you can simply call entity setters using Request attributes.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Entity;
use Mmoreram\ControllerExtraBundle\Entity\Address;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @Entity(
* namespace = "MmoreramCustomBundle:Address",
* name = "address"
* )
* @Entity(
* namespace = "MmoreramCustomBundle:User",
* name = "user",
* setters = {
* "setAddress": "address"
* }
* )
*/
public function indexAction(Address $address, User $user)
{
}
When User
instance is built, method setAddress
is called using as parameter the new Address
instance.
New entities are just created with a simple new()
, so they are not persisted. By default, they will be persisted using configured manager, but you can disable this feature using persist
option.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Entity;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @Entity(
* namespace = "MmoreramCustomBundle:User",
* name = "user",
* persist = false
* )
*/
public function indexAction(User $user)
{
}
When you define a new Entity annotation, you can also request the mapped entity given a map. It means that if a map is defined, this bundle will try to request the mapped instance satisfying it.
The keys of the map represent the names of the mapped fields and the values represent their desired values. Remember than you can refer to any Request attribute by using format ~field~
, to any $_GET
element by using format ?field?
or to any $_POST
by using format #field#
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Entity;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* This Controller matches pattern /user/edit/{id}/{username}
*
* @Entity(
* namespace = "MmoreramCustomBundle:User",
* name = "user",
* mapping = {
* "id": "~id~",
* "username": "~username~"
* }
* )
*/
public function indexAction(User $user)
{
}
In this case, you will try to get the mapped instance of User with passed id. If some mapping is defined and any entity is found, a new EntityNotFoundException` is thrown.
So what if one ore more than one mapping references are not found? For example, you're trying to map the {id} parameter from your route, but this parameter is not even defined. Whan happens here? Well, you can assume then that you want to pass a new entity instance by using the mappingFallback.
By default, if
mapping_fallback
option is not set, the used value will be the parameterdefault_mapping_fallback
defined in configuration. By default this value isfalse
Don't confuse with the scenario where you're looking for an entity in your database, all mapping references have been resolved, and the entity is not found. In that case, a common "EntityNotFound" exception will be thrown by Doctrine.
Lets see an example. Because we have enabled the mappingFallback, and because the mapping definition does not match the assigned route, we will return a new empty User entity.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Entity;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* This Controller matches pattern /user/edit/{id}
*
* @LoadEntity(
* namespace = "MmoreramCustomBundle:User",
* name = "user",
* mapping = {
* "id": "~id~",
* "username": "~nonexisting~"
* },
* mappingFallback = true
* )
*/
public function indexAction(User $user)
{
// $user->getId() === null
}
By default, the Doctrine entity manager provides the right repository per each entity (not the default one, but the right specific one). Although, you can define a custom repository to be used in your annotation by using the repository configuration.
/**
* Simple controller method
*
* @CreateEntity(
* namespace = "MmoreramCustomBundle:User",
* mapping = {
* "id": "~id~",
* "username": "~username~"
* }
* repository = {
* "class" = "Mmoreram\CustomBundle\Repository\AnotherRepository",
* },
* )
*/
public function indexAction(User $user)
{
}
By default, the method findOneBy will always be used, unless you define another one.
/**
* Simple controller method
*
* @CreateEntity(
* namespace = "MmoreramCustomBundle:User",
* mapping = {
* "id": "~id~",
* "username": "~username~"
* }
* repository = {
* "class" = "Mmoreram\CustomBundle\Repository\AnotherRepository",
* "method" = "find",
* },
* )
*/
public function indexAction(User $user)
{
}
When the annotation considers that a new entity must be created, because no mapping information has been provided, or because the mapping fallback has been activated, by default a new instance will be created by using the namespace value.
This configuration block has three positions
You can define the factory with a simple namespace
/**
* Simple controller method
*
* @CreateEntity(
* namespace = "MmoreramCustomBundle:User",
* factory = {
* "class" = "Mmoreram\CustomBundle\Factory\UserFactory",
* "method" = "create",
* "static" = true,
* },
* )
*/
public function indexAction(User $user)
{
}
If you want to define your Factory as a service, with the possibility of overriding namespace, you can simply define service name. All other options have the same behaviour.
parameters:
#
# Factories
#
my.bundle.factory.user_factory: Mmoreram\CustomBundle\Factory\UserFactory
/**
* Simple controller method
*
* @CreateEntity(
* class = {
* "factory" = my.bundle.factory.user_factory,
* "method" = "create",
* "static" = true,
* },
* )
*/
public function indexAction(User $user)
{
}
If you do not define the method
, default one will be used. You can override this default value by defining new one in your config.yml
. Same with static
value
controller_extra:
entity:
default_factory_method: create
default_factory_static: true
Provides form injection in your controller actions. This annotation only needs a name to be defined in, where you must define namespace where your form is placed.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\CreateForm;
use Symfony\Component\Form\AbstractType;
/**
* Simple controller method
*
* @CreateForm(
* class = "\Mmoreram\CustomBundle\Form\Type\UserType",
* name = "userType"
* )
*/
public function indexAction(AbstractType $userType)
{
}
By default, if
name
option is not set, the generated object will be placed in a parameter named$form
. This behaviour can be configured usingdefault_name
in configuration.
You can not just define your Type location using the namespace, in which case a new AbstractType element will be created. but you can also define it using service alias, in which case this bundle will return an instance using Symfony DI.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\CreateForm;
use Symfony\Component\Form\AbstractType;
/**
* Simple controller method
*
* @CreateForm(
* class = "user_type",
* name = "userType"
* )
*/
public function indexAction(AbstractType $userType)
{
}
This annotation allows you to not only create an instance of FormType, but also allows you to inject a Form object or a FormView object
To inject a Form object you only need to cast method value as such.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\CreateForm;
use Symfony\Component\Form\Form;
/**
* Simple controller method
*
* @CreateForm(
* class = "user_type",
* name = "userForm"
* )
*/
public function indexAction(Form $userForm)
{
}
You can also, using [SensioFrameworkExtraBundle][1]'s [ParamConverter][2], create a Form object with an previously created entity. you can define this entity using entity
parameter.
<?php
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Form\Form;
use Mmoreram\ControllerExtraBundle\Annotation\CreateForm;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @Route(
* path = "/user/{id}",
* name = "view_user"
* )
* @ParamConverter("user", class="MmoreramCustomBundle:User")
* @CreateForm(
* class = "user_type",
* entity = "user"
* name = "userForm",
* )
*/
public function indexAction(User $user, Form $userForm)
{
}
To handle current request, you can set handleRequest
to true. By default this value is set to false
<?php
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Form\Form;
use Mmoreram\ControllerExtraBundle\Annotation\CreateForm;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @Route(
* path = "/user/{id}",
* name = "view_user"
* )
* @ParamConverter("user", class="MmoreramCustomBundle:User")
* @CreateForm(
* class = "user_type",
* entity = "user"
* handleRequest = true,
* name = "userForm",
* )
*/
public function indexAction(User $user, Form $userForm)
{
}
You can also add as a method parameter if the form is valid, using validate
setting. Annotation will place result of $form->isValid()
in specified method argument.
<?php
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\Form\Form;
use Mmoreram\ControllerExtraBundle\Annotation\CreateForm;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @Route(
* path = "/user/{id}",
* name = "view_user"
* )
* @ParamConverter("user", class="MmoreramCustomBundle:User")
* @CreateForm(
* class = "user_type",
* entity = "user"
* handleRequest = true,
* name = "userForm",
* validate = "isValid",
* )
*/
public function indexAction(User $user, Form $userForm, $isValid)
{
}
To inject a FormView object you only need to cast method variable as such.
<?php
use Symfony\Component\Form\FormView;
use Mmoreram\ControllerExtraBundle\Annotation\CreateForm;
/**
* Simple controller method
*
* @CreateForm(
* class = "user_type",
* name = "userFormView"
* )
*/
public function indexAction(FormView $userFormView)
{
}
Flush annotation allows you to flush entityManager at the end of request using kernel.response event
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Flush;
/**
* Simple controller method
*
* @Flush
*/
public function indexAction()
{
}
If not otherwise specified, default Doctrine Manager will be flushed with this annotation. You can overwrite default Manager in your config.yml
file.
controller_extra:
flush:
default_manager: my_custom_manager
You can also override this value in every single Flush Annotation instance defining manager
value
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Flush;
/**
* Simple controller method
*
* @Flush(
* manager = "my_own_manager"
* )
*/
public function indexAction()
{
}
If you want to change default manager in all annotation instances, you should override bundle parameter in your config.yml
file.
controller_extra:
flush:
default_manager: my_own_manager
If any parameter is set, annotation will flush all. If you only need to flush one or many entities, you can define explicitly which entity must be flushed.
<?php
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Mmoreram\ControllerExtraBundle\Annotation\Flush;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @ParamConverter("user", class="MmoreramCustomBundle:User")
* @Flush(
* entity = "user"
* )
*/
public function indexAction(User $user)
{
}
You can also define a set of entities to flush
<?php
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Mmoreram\ControllerExtraBundle\Annotation\Flush;
use Mmoreram\ControllerExtraBundle\Entity\Address;
use Mmoreram\ControllerExtraBundle\Entity\User;
/**
* Simple controller method
*
* @ParamConverter("user", class="MmoreramCustomBundle:User")
* @ParamConverter("address", class="MmoreramCustomBundle:Address")
* @Flush(
* entity = {
* "user",
* "address"
* }
* )
*/
public function indexAction(User $user, Address $address)
{
}
If multiple @Mmoreram\Flush are defined in same action, last instance will overwrite previous. Anyway just one instance should be defined.
JsonResponse annotation allows you to create a Symfony\Component\HttpFoundation\JsonResponse
object, given a simple controller return value.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\ToJsonResponse;
/**
* Simple controller method
*
* @ToJsonResponse
*/
public function indexAction(User $user, Address $address)
{
return array(
'This is my response'
);
}
By default, JsonResponse is created using default status
and headers
defined in bundle parameters. You can overwrite them in your config.yml
file.
controller_extra:
json_response:
default_status: 403
default_headers:
"User-Agent": "Googlebot/2.1"
You can also overwrite these values in each @JsonResponse
annotation.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\ToJsonResponse;
/**
* Simple controller method
*
* @ToJsonResponse(
* status = 403,
* headers = {
* "User-Agent": "Googlebot/2.1"
* }
* )
*/
public function indexAction(User $user, Address $address)
{
return array(
'This is my response'
);
}
If an Exception is returned the response status is set by default to 500 and the Exception message is returned as response.
STATUS 500 Internal server error
{
message : 'Exception message'
}
In case we use a HttpExceptionInterface the use the exception status code as status code. In case we launch this exception
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
...
return new NotFoundHttpException('Resource not found');
We'll receive this response
STATUS 404 Not Found
{
message : 'Resource not found'
}
If the exception is being launched on an annotation (e.g. Entity annotation) remember to add the JsonResponse annotation at the beginning or at least before any annotation that could cause an exception.
If multiple @Mmoreram\JsonResponse are defined in same action, last instance will overwrite previous. Anyway just one instance should be defined.
Log annotation allows you to log any plain message before or after controller action execution
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Log;
/**
* Simple controller method
*
* @Log("Executing index Action")
*/
public function indexAction()
{
}
You can define the level of the message. You can define default one if none is specified overriding it in your config.yml
file.
controller_extra:
log:
default_level: warning
Every Annotation instance can overwrite this value using level
field.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Log;
/**
* Simple controller method
*
* @Log(
* value = "Executing index Action",
* level = @Log::LVL_WARNING
* )
*/
public function indexAction()
{
}
Several levels can be used, as defined in [Psr\Log\LoggerInterface][6] interface
You can also define the execution of the log. You can define default one if none is specified overriding it in your config.yml
file.
controller_extra:
log:
default_execute: pre
Every Annotation instance can overwrite this value using level
field.
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Log;
/**
* Simple controller method
*
* @Log(
* value = "Executing index Action",
* execute = @Log::EXEC_POST
* )
*/
public function indexAction()
{
}
Several executions can be used,
The Get annotation allows you to get any parameter from the request query string.
For a GET
request like:
GET /my-page?foo=bar HTTP/1.1
You can can simply get the foo
var using the GET
annotation
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Get;
/**
* Simple controller method
*
* @Get(
* path = "foo"
* )
*/
public function indexAction($foo)
{
// Use the foo var
}
You can also customize the var name and the default value in case the var is not sent on the query string.
For a GET
request like:
GET /my-page HTTP/1.1
And this annotation
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Get;
/**
* Simple controller method
*
* @Get(
* path = "foo",
* name = "varName",
* default = 'bar',
* )
*/
public function indexAction($varName)
{
// This would print 'bar'
echo $varName;
}
The Post annotation allows you to get any parameter from the post request body.
For a POST
request like:
POST /my-page HTTP/1.1
foo=bar
You can can simply get the foo
var using the POST
annotation
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Post;
/**
* Simple controller method
*
* @Post(
* path = "foo"
* )
*/
public function indexAction($foo)
{
// Use the foo var
}
You can also customize the var name and the default value in case the var is not sent on the query string.
For a POST
request like:
POST /my-page HTTP/1.1
And this annotation
<?php
use Mmoreram\ControllerExtraBundle\Annotation\Post;
/**
* Simple controller method
*
* @Post(
* path = "foo",
* name = "varName",
* default = 'bar',
* )
*/
public function indexAction($varName)
{
// This would print 'bar'
echo $varName;
}
Custom annotations
Using this bundle you can now create, in a very easy way, your own controller annotation.
The annotation object. You need to define the fields your custom annotation will contain. Must extends Mmoreram\ControllerExtraBundle\Annotation\Annotation
abstract class.
<?php
namespace My\Bundle\Annotation;
use Mmoreram\ControllerExtraBundle\Annotation\Annotation;
/**
* Entity annotation driver
*
* @Annotation
* @Target({"METHOD"})
*/
final class MyCustomAnnotation extends Annotation
{
/**
* @var string
*
* Dummy field
*/
public $field;
/**
* Get Dummy field
*
* @return string Dummy field
*/
public function getField()
{
return $this->field;
}
}
Once you have defined your own annotation, you have to resolve how this annotation works in a controller. You can manage this using a Resolver. Must extend Mmoreram\ControllerExtraBundle\Resolver\AnnotationResolver;
abstract class.
<?php
namespace My\Bundle\Resolver;
use Symfony\Component\HttpFoundation\Request;
use Mmoreram\ControllerExtraBundle\Resolver\AnnotationResolver;
use Mmoreram\ControllerExtraBundle\Annotation\Annotation;
/**
* MyCustomAnnotation Resolver
*/
class MyCustomAnnotationResolver extends AnnotationResolver
{
/**
* Specific annotation evaluation.
*
* This method must be implemented in every single EventListener
* with specific logic
*
* All method code will executed only if specific active flag is true
*
* @param Request $request
* @param Annotation $annotation
* @param ReflectionMethod $method
*/
public function evaluateAnnotation(
Request $request,
Annotation $annotation,
ReflectionMethod $method
)
{
/**
* You can now manage your annotation.
* You can access to its fields using public methods.
*
* Annotation fields can be public and can be acceded directly,
* but is better for testing to use getters; they can be mocked.
*/
$field = $annotation->getField();
/**
* You can also access to existing method parameters.
*
* Available parameters are:
*
* # ParamConverter parameters ( See `resolver_priority` config value )
* # All method defined parameters, included Request object if is set.
*/
$entity = $request->attributes->get('entity');
/**
* And you can now place new elements in the controller action.
* In this example we are creating new method parameter
* called $myNewField with some value
*/
$request->attributes->set(
'myNewField',
new $field()
);
return $this;
}
}
This class will be defined as a service, so this method is computed just before executing current controller. You can also subscribe to some kernel events and do whatever you need to do ( You can check Mmoreram\ControllerExtraBundle\Resolver\LogAnnotationResolver
for some examples.
Once Resolver is done, we need to define our service as an Annotation Resolver. We will use a custom tag
.
parameters:
#
# Resolvers
#
my.bundle.resolver.my_custom_annotation_resolver.class: My\Bundle\Resolver\MyCustomAnnotationResolver
services:
#
# Resolvers
#
my.bundle.resolver.my_custom_annotation_resolver:
class: %my.bundle.resolver.my_custom_annotation_resolver.class%
tags:
- { name: controller_extra.annotation }
We need to register our annotation inside our application. We can just do it in the boot()
method of bundle.php
file.
<?php
namespace My\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Doctrine\Common\Annotations\AnnotationRegistry;
/**
* MyBundle
*/
class ControllerExtraBundle extends Bundle
{
/**
* Boots the Bundle.
*/
public function boot()
{
$kernel = $this->container->get('kernel');
AnnotationRegistry::registerFile($kernel
->locateResource("@MyBundle/Annotation/MyCustomAnnotation.php")
);
}
}
Et voilà! We can now use our custom Annotation in our project controllers.
Author: mmoreram
Source Code: https://github.com/mmoreram/ControllerExtraBundle
License: MIT license