Skip to content

Commit

Permalink
Merge pull request #16 from thizzle/master
Browse files Browse the repository at this point in the history
Support for generic Exception throwing in resource class methods
  • Loading branch information
davehauenstein committed Mar 2, 2012
2 parents 2031790 + 33ebb69 commit a375814
Show file tree
Hide file tree
Showing 25 changed files with 1,014 additions and 427 deletions.
43 changes: 28 additions & 15 deletions examples/microframework/app/Sonno/Example/Resource/RootResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@
Sonno\Annotation\Context,
Sonno\Annotation\Produces,
Sonno\Annotation\Consumes,
Sonno\Annotation\FormParam,
Sonno\Annotation\PathParam,
Twig_Autoloader,
Twig_Environment,
Twig_Function_Function,
Twig_Loader_Filesystem;

/**
* The root resource class is effectively a single controller class (in a
* traditional MVC paradigm) whose class methods are actions that produce an
* HTML representation for each page of our microsite.
*
* Typically, a class method will simply render a Twig template to produce the
* required HTML document representation.
*
* @Path("/")
* @Produces({"text/html"})
*/
class RootResource
{
/**
Expand Down Expand Up @@ -65,11 +77,10 @@ public function __construct()
}

/**
* Root resource.
* Home page.
* This is static markup rendered by the Twig templating engine.
*
* @GET
* @Path("/")
* @Produces({"text/html"})
*/
public function home()
{
Expand All @@ -79,10 +90,10 @@ public function home()

/**
* About page.
* This is static markup rendered by the Twig templating engine.
*
* @GET
* @Path("/about")
* @Produces({"text/html"})
*/
public function about()
{
Expand All @@ -91,11 +102,11 @@ public function about()
}

/**
* Contact Us page.
* Contact page.
* This is static markup rendered by the Twig templating engine.
*
* @GET
* @Path("/contact")
* @Produces({"text/html"})
*/
public function contact()
{
Expand All @@ -104,19 +115,21 @@ public function contact()
}

/**
* Contact Us page - submission.
* Contact submission page.
* Accepts POST requests with an entity body as
* application/x-www-form-urlencoded which is the default MIME type sent by
* a web browser when you submit a form.
* The request entity can be parsed using the PHP native function parse_str
* which parses a URL-encoded set of key/value pairs. This exposes the form
* data submitted by the web browser.
*
* @POST
* @Path("/contact")
* @Consumes({"application/x-www-form-urlencoded"})
* @Produces({"text/html"})
* @Produces({"text/plain"})
* @FormParam("fullname")
*/
public function contactsubmit() {
parse_str($this->_request->getRequestBody(), $req);

$builder = $this->_uriInfo->getAbsolutePathBuilder();
echo $builder->build();

return 'Thanks for sending us your input, ' . $req['fullname'] . '!';
public function contactsubmit($fullname) {
return "Thanks for sending us your input, $fullname!";
}
}
1 change: 1 addition & 0 deletions examples/microframework/views/about.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

{% block body %}
<section>
<h2>About the Sonno Microframework Example</h2>
<p>
This microsite example is powered by only by
<a href="http://sonno.360i.com">Sonno</a> as the application
Expand Down
14 changes: 10 additions & 4 deletions examples/microframework/views/contact.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
{% block body %}
<section>
<p>Send us a quick message using the form below!</p>
<p>
The form action is handled by a resource function that accepts POST
requests with an entity body as
<code>application/x-www-form-urlencoded</code> which is the default
MIME type sent by a web browser when you submit a form.
</p>
<form action="/contact" method="post">
<label>Full Name: <input type="text" name="fullname" /></label>
<br/>
<label>Message: <textarea cols="30" rows="10" name="message"></textarea></label>
<br/>
<label for="fullname">Full Name</label>
<input type="text" name="fullname" id="fullname" />
<label for="message">Message</label>
<textarea cols="30" rows="10" name="message" id="message"></textarea>
<input type="submit" value="Submit" />
</form>
</section>
Expand Down
1 change: 1 addition & 0 deletions examples/microframework/views/home.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
{% block body %}
<section>
<p>This is the home page.</p>
<p>Read more <a href="/about">about this example</a> or <a href="/contact">send us a message</a>.
</section>
{% endblock %}
5 changes: 3 additions & 2 deletions examples/microframework/views/layout.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>Sonno Microframework Example: {% block title %}{% endblock %}</title>
<title>Sonno Microframework Example // {% block title %}{% endblock %}</title>

<link rel="stylesheet" type="text/css" href="/style.css" />
{% block head %}
{% endblock %}
</head>
Expand All @@ -27,7 +28,7 @@
{% endblock %}

<footer>
Copyright &copy; 2012
Copyright &copy; 2011-2012 <a href="http://www.360i.com">360i</a> LLC
</footer>
</body>
</html>
1 change: 1 addition & 0 deletions examples/microframework/www/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

define('APPLICATION_PATH', realpath(__DIR__ . '/../'));
error_reporting(E_ALL);

// Require our autoloader. It simplest to use Doctrine's Autoloader since
// Doctrine-Common is already installed for Annotation reading and is on the
Expand Down
28 changes: 28 additions & 0 deletions examples/microframework/www/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
body {
font-family: Helvetica, Arial, sans;
font-size: 12px;
}

form {
width: 400px;
}

form label {
width: 125px;
float: left;
clear: left;
font-weight: bold;
color: #999;
}

form input {
float: left;
}

form input[type=submit] {
margin-left: 125px;
}

footer {
clear: both;
}
2 changes: 1 addition & 1 deletion src/Sonno/Annotation/Produces.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Produces
protected $_mediaTypes = array('*/*');

/**
* Construct a new Consumes instance.
* Construct a new Produces instance.
*
* @param $mediaTypes array A list of media types.
* E.g. {"image/jpeg","image/gif"}.
Expand Down
Loading

0 comments on commit a375814

Please sign in to comment.