Пример #1
0
 /**
  * The routing strategy, it creates all necessary routes to match RESTFul URLs for the
  * provided resource name.
  *
  * @param object $router   The router instance.
  * @param string $resource The resource name.
  * @param array  $options  The options array.
  */
 public function __invoke($router, $resource, $options = [])
 {
     $options += ['name' => $resource, 'key' => $this->_key, 'format' => $this->_format, 'rkey' => $this->_rkey, 'rformat' => $this->_format, 'action' => ':{action}'];
     $slug = Inflector::dasherize(Inflector::underscore($resource));
     $path = '{resource:' . $slug . '}';
     $placeholder = '{id:' . $options['format'] . '}';
     $rplaceholder = '{rid:' . $options['rformat'] . '}';
     $pattern = '[{relation}/' . $rplaceholder . '/]' . $path . '[/' . $placeholder . ']' . '[/' . $options['action'] . ']';
     $options['params'] = ['resource' => $slug];
     return $router->bind($pattern, $options, function ($route) use($router, $resource, $options) {
         return $this->dispatch($resource, $route, $router, $options);
     });
 }
Пример #2
0
         $result = Inflector::parameterize('Foo:Bar & Cie', '_');
         expect($result)->toBe('foo_bar_cie');
     });
 });
 describe("::underscore()", function () {
     it("underscores a string", function () {
         expect(Inflector::underscore('ClassName'))->toBe('class_name');
         expect(Inflector::underscore('TestField'))->toBe('test_field');
         expect(Inflector::underscore('MyName\\Space'))->toBe('my_name\\space');
         expect(Inflector::underscore('dashed-version'))->toBe('dashed_version');
     });
 });
 describe("::dasherize()", function () {
     it("dasherizes a string", function () {
         expect(Inflector::dasherize('class_name'))->toBe('class-name');
         expect(Inflector::dasherize('test_field'))->toBe('test-field');
     });
 });
 describe("::camelize()", function () {
     it("camelizes a string", function () {
         expect(Inflector::camelize('test-field'))->toBe('TestField');
         expect(Inflector::camelize('test_field'))->toBe('TestField');
         expect(Inflector::camelize('TEST_FIELD'))->toBe('TestField');
         expect(Inflector::camelize('TestField'))->toBe('TestField');
         expect(Inflector::camelize('my_name\\space'))->toBe('MyName\\Space');
     });
 });
 describe("::camelback()", function () {
     it("camelbacks a string", function () {
         expect(Inflector::camelback('test-field'))->toBe('testField');
         expect(Inflector::camelback('test field'))->toBe('testField');