Пример #1
0
 public function getCommandName()
 {
     if (is_null($this->action) || is_null($this->resource)) {
         return null;
     }
     return Sonata_Utils::camelize($this->action) . Sonata_Utils::camelize($this->resource);
 }
Пример #2
0
<?php

/**
 * This file is part of the Sonata RESTful PHP framework
 * (c) 2009-2010 Pascal Cremer <*****@*****.**>
 *
 * @author Pascal Cremer <*****@*****.**>
 */
require_once dirname(__FILE__) . '/bootstrap.php';
$t = new LimeTest();
// @Test: ::camelize()
$t->is(Sonata_Utils::camelize('foo_bar_baz'), 'FooBarBaz', 'The string was camelized correctly');
$t->is(Sonata_Utils::camelize('foo_bar_baz', true), 'fooBarBaz', 'The string was camelized correctly, starting lower-case');
$t->is(Sonata_Utils::camelize('foo _ bar _baz'), 'FooBarBaz', 'Whitespaces are ignored');
$t->is(Sonata_Utils::camelize(''), '', 'Empty strings are retuned untouched');
// @Test: ::underscore()
$t->is(Sonata_Utils::underscore('FooBar'), 'foo_bar', 'The string was underscored correctly');
$t->is(Sonata_Utils::underscore('myFooBar'), 'my_foo_bar', 'It even works for camelized strings that start lower-case');
$t->is(Sonata_Utils::underscore('Foo Bar-!/#Baz'), 'foo_bar_baz', 'Whitespaces and non-digit characters are ignored');
$t->is(Sonata_Utils::underscore(''), '', 'Empty strings are retuned untouched');
// @Test: ::slugify()
$t->is(Sonata_Utils::slugify('Here be dragons!'), 'here-be-dragons', 'The string was slugified correctly');
$t->is(Sonata_Utils::slugify('Hérè be drägons!'), 'here-be-dragons', 'Transforms UTF-8 characters correctly');
$t->is(Sonata_Utils::slugify(''), 'n-a', '\'n-a\' is returned for empty strings');
Пример #3
0
 public function getControllerClassName(Sonata_Request $request)
 {
     $resource = $request->getParameter('resource');
     if (!$resource) {
         return null;
     }
     return ucfirst(Sonata_Utils::camelize($resource)) . 'Controller';
 }
 /**
  * Renders a template and returns the raw data
  *
  * @param string $name The name of the template 
  * @param string $resource The name of the resource | NULL for generic templates
  * @param string $format The response format
  * @return string The rendered data
  */
 public function render($name, $resource = null, $format = 'xml')
 {
     if ($resource) {
         $templatePath = $this->dir . '/' . Sonata_Utils::underscore($resource) . '/' . $name . 'Success.' . $format . '.php';
     } else {
         $templatePath = dirname(__FILE__) . '/../data/templates/' . $name . 'Success.' . $format . '.php';
     }
     if (!is_readable($templatePath)) {
         throw new Sonata_Exception_Template(sprintf("The template '%s' does not exist or is not readable.", $name));
     }
     ob_start();
     include $templatePath;
     $data = ob_get_clean();
     return $data;
 }