Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a670440

Browse files
committed
Merge branch '4.0'
2 parents a4c76fb + 27102ee commit a670440

7 files changed

Lines changed: 76 additions & 13 deletions

File tree

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct(QueryBuilder $query)
5454
*
5555
* @param mixed $id
5656
* @param array $columns
57-
* @return \Illuminate\Database\Eloquent\Model
57+
* @return \Illuminate\Database\Eloquent\Model|null
5858
*/
5959
public function find($id, $columns = array('*'))
6060
{
@@ -68,7 +68,7 @@ public function find($id, $columns = array('*'))
6868
*
6969
* @param mixed $id
7070
* @param array $columns
71-
* @return \Illuminate\Database\Eloquent\Model|Collection
71+
* @return \Illuminate\Database\Eloquent\Model
7272
*/
7373
public function findOrFail($id, $columns = array('*'))
7474
{
@@ -80,8 +80,8 @@ public function findOrFail($id, $columns = array('*'))
8080
/**
8181
* Execute the query and get the first result.
8282
*
83-
* @param array $columns
84-
* @return array
83+
* @param array $columns
84+
* @return \Illuminate\Database\Eloquent\Model|null
8585
*/
8686
public function first($columns = array('*'))
8787
{
@@ -91,8 +91,8 @@ public function first($columns = array('*'))
9191
/**
9292
* Execute the query and get the first result or throw an exception.
9393
*
94-
* @param array $columns
95-
* @return array
94+
* @param array $columns
95+
* @return \Illuminate\Database\Eloquent\Model
9696
*/
9797
public function firstOrFail($columns = array('*'))
9898
{

src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ public function sync(array $ids, $detaching = true)
508508
}
509509

510510
/**
511-
* Format the sync list so that is is keyed by ID.
511+
* Format the sync list so that it is keyed by ID.
512512
*
513513
* @param array $records
514514
* @return array
@@ -557,7 +557,7 @@ protected function attachNew(array $records, array $current, $touch = true)
557557
}
558558

559559
/**
560-
* Update an existing pivot reord on the table.
560+
* Update an existing pivot record on the table.
561561
*
562562
* @param mixed $id
563563
* @param array $attributes
@@ -773,7 +773,7 @@ protected function guessInverseRelation()
773773
*/
774774
protected function newPivotQuery()
775775
{
776-
$query = $this->query->getQuery()->newQuery()->from($this->table);
776+
$query = $this->newPivotStatement();
777777

778778
return $query->where($this->foreignKey, $this->parent->getKey());
779779
}

src/Illuminate/Routing/Controllers/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ public function getControllerFilters()
282282
/**
283283
* Handle calls to missing methods on the controller.
284284
*
285-
* @param array $parameters
285+
* @param array $parameters
286286
* @return mixed
287287
*/
288288
public function missingMethod($parameters)
289289
{
290-
throw new NotFoundHttpException;
290+
throw new NotFoundHttpException("Controller method not found.");
291291
}
292292

293293
/**
@@ -299,7 +299,7 @@ public function missingMethod($parameters)
299299
*/
300300
public function __call($method, $parameters)
301301
{
302-
throw new NotFoundHttpException;
302+
return $this->missingMethod($parameters);
303303
}
304304

305305
}

src/Illuminate/Support/Str.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ public static function words($value, $words = 100, $end = '...')
161161
return rtrim($matches[0]).$end;
162162
}
163163

164+
/**
165+
* Parse a Class@method style callback into class and method.
166+
*
167+
* @param string $callback
168+
* @param string $default
169+
* @return array
170+
*/
171+
public static function parseCallback($callback, $default)
172+
{
173+
return static::contains($callback, '@') ? explode('@', $callback, 2) : array($callback, $default);
174+
}
175+
164176
/**
165177
* Get the plural form of an English word.
166178
*

src/Illuminate/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Translator extends NamespacedItemResolver implements TranslatorInterface {
1919
*
2020
* @var string
2121
*/
22-
protected $default;
22+
protected $locale;
2323

2424
/**
2525
* The array of loaded translation groups.

tests/Routing/RoutingControllerTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,43 @@ public function testAfterFiltersAreExecutedWhenUsingCallbackFilters()
122122
unset($_SERVER['__controller.after']);
123123
}
124124

125+
126+
/**
127+
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
128+
*/
129+
public function testMissingMethod()
130+
{
131+
$controller = new BasicControllerStub;
132+
$container = new Illuminate\Container\Container;
133+
$container['filter.parser'] = $container->share(function() { return m::mock('StdClass'); });
134+
$container['filter.parser']->shouldReceive('parse')->andReturn(array());
135+
$router = m::mock('Illuminate\Routing\Router');
136+
$router->shouldReceive('getRequest')->andReturn(m::mock('Symfony\Component\HttpFoundation\Request'));
137+
$router->shouldReceive('getCurrentRoute')->andReturn(m::mock('Illuminate\Routing\Route'));
138+
$router->shouldReceive('prepare')->never()->andReturnUsing(function($response, $request) { return new Response($response); });
139+
140+
// Call a method that doesn't exists.
141+
$controller->callAction($container, $router, 'thisMethodDoesntExists', array('foo'));
142+
}
143+
144+
145+
public function testMissingMethodReplacement()
146+
{
147+
$controller = new MissingMethodControllerStub;
148+
$container = new Illuminate\Container\Container;
149+
$container['filter.parser'] = $container->share(function() { return m::mock('StdClass'); });
150+
$container['filter.parser']->shouldReceive('parse')->andReturn(array());
151+
$router = m::mock('Illuminate\Routing\Router');
152+
$router->shouldReceive('getRequest')->andReturn(m::mock('Symfony\Component\HttpFoundation\Request'));
153+
$router->shouldReceive('getCurrentRoute')->andReturn(m::mock('Illuminate\Routing\Route'));
154+
$router->shouldReceive('prepare')->once()->andReturnUsing(function($response, $request) { return new Response($response); });
155+
156+
// Call a method that doesn't exists.
157+
$response = $controller->callAction($container, $router, 'thisMethodDoesntExists', array('foo'));
158+
$this->assertEquals('Missing method!', $response->getContent());
159+
}
160+
161+
125162
}
126163

127164
class BasicControllerStub extends Illuminate\Routing\Controllers\Controller {
@@ -140,4 +177,11 @@ protected function setupLayout()
140177
{
141178
$this->layout = 'Layout';
142179
}
180+
}
181+
182+
class MissingMethodControllerStub extends Illuminate\Routing\Controllers\Controller {
183+
public function missingMethod($parameters)
184+
{
185+
return 'Missing method!';
186+
}
143187
}

tests/Support/SupportStrTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@ public function testStrContains()
7070
$this->assertFalse(Str::contains('taylor', array('xxx')));
7171
}
7272

73+
74+
public function testParseCallback()
75+
{
76+
$this->assertEquals(array('Class', 'method'), Str::parseCallback('Class@method', 'foo'));
77+
$this->assertEquals(array('Class', 'foo'), Str::parseCallback('Class', 'foo'));
78+
}
79+
7380
}

0 commit comments

Comments
 (0)