예제 #1
0
 /**
  * Get the table for the current model.
  *
  * @return Table|null
  */
 public static function getTable()
 {
     $class = implode('', array_slice(explode('\\', static::class), -1));
     if (static::$tableName === null) {
         static::$tableName = Str::pluralize(Str::snakeCase($class));
     }
     $alias = Str::pluralize(Str::snakeCase($class));
     return Table::find(static::$tableName, $alias);
 }
예제 #2
0
 function resource($route, $controller)
 {
     $application = Application::instance();
     if (!is_array($route)) {
         $route = [$route, Str::snakeCase(str_replace('Controller', '', $controller))];
     }
     list($route, $name) = $route;
     get([$route, $name], $controller . '@index');
     post([$route, $name . '.create'], $controller . '@create');
     get([$route . '/{id:int}', $name . '.show'], $controller . '@show');
     post([$route . '/{id:int}', $name . '.update'], $controller . '@update');
     get([$route . '/{id:int}/edit', $name . '.edit'], $controller . '@edit');
     delete([$route . '/{id:int}', $name . '.delete'], $controller . '@destroy');
     post([$route . '/{id:int}/destroy', $name . '.destroy'], $controller . '@destroy');
 }
예제 #3
0
 /**
  * Magic method which allows for dynamically adding where clauses by
  * including the camelCased column name in the method name.
  *
  * e.g. `$query->whereColumnName(3)` is equivalent to `$query->where('column_name', 3)`
  *
  * @param string $methodName The method being called
  * @param array  $args       The arguments provided to the method
  *
  * @return $this
  */
 public function __call($methodName, $args)
 {
     // Convert the method name to snake_case
     $methodName = Str::snakeCase($methodName);
     // Explode the method name, and separate the first word
     $words = explode('_', $methodName);
     $firstWord = array_shift($words);
     // If the method name begins with 'where', convert the rest of the
     // method name into a column name, and add a where clause to the query
     if ($firstWord === 'where') {
         // Get the column name from the method name
         $columnName = implode('_', $words);
         // Add the column name to the beginning of the args array
         array_unshift($args, $columnName);
         // Create new reflection on the Query class
         $ref = new \ReflectionClass(self::class);
         // Invoke the `where` method with the provided arguments
         $method = $ref->getMethod('where');
         $method->invokeArgs($this, $args);
     }
     // Return the query for chaining
     return $this;
 }
예제 #4
0
파일: StrTest.php 프로젝트: molovo/str
 /**
  * Tests conversion of naughty strings to snake_case.
  *
  * @dataProvider bigListOfNaughtyStrings
  *
  * @covers Molovo\Str\Str::slug
  */
 public function testSnameCaseWithNaughtyStrings($string)
 {
     $string = Str::snakeCase(base64_decode($string));
     if (!empty($string)) {
         verify($string)->regExp('/[a-zA-Z0-9_]/');
     }
 }