Skip to content

Commit 54e9abe

Browse files
committed
Add support for Laravel 5
1 parent b868b70 commit 54e9abe

File tree

12 files changed

+69
-104
lines changed

12 files changed

+69
-104
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.1.0
2+
_Mar 3 2015_
3+
* enhancements
4+
- Add support for Laravel 5.x, leave a [1.0.x](https://github.com/etrepat/baum/tree/1.0.x-stable) branch for backwards compatibility.
5+
16
## 1.0.13
27
_Sep 30 2014_
38
* bug fixes

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
[![Build Status](https://travis-ci.org/etrepat/baum.png?branch=master)](https://travis-ci.org/etrepat/baum)
44

5-
Baum is an implementation of the [Nested Set](http://en.wikipedia.org/wiki/Nested_set_model)
6-
pattern for [Laravel 4's](http://laravel.com/) Eloquent ORM.
5+
Baum is an implementation of the [Nested Set](http://en.wikipedia.org/wiki/Nested_set_model) pattern for [Laravel 5's](http://laravel.com/) Eloquent ORM.
6+
7+
> For **Laravel 4.2.x compatibility**, check the [1.0.x branch](https://github.com/etrepat/baum/tree/1.0.x-stable) branch or use the latest [1.0.x tagged release](https://github.com/etrepat/baum/releases).
78
89
## Documentation
910

@@ -93,18 +94,18 @@ ordinary trees are suddenly quite fast. Nifty, isn't it?
9394
<a name="installation"></a>
9495
## Installation
9596

96-
Baum works with Laravel 4 onwards. You can add it to your `composer.json` file
97+
Baum works with Laravel 5 onwards. You can add it to your `composer.json` file
9798
with:
9899

99-
"baum/baum": "~1.0"
100+
"baum/baum": "~1.1"
100101

101102
Run `composer install` to install it.
102103

103-
As with most Laravel 4 packages you'll then need to register the Baum
104-
*service provider*. To do that, head over your `app/config/app.php` file and add
104+
As with most Laravel 5 packages you'll then need to register the Baum
105+
*service provider*. To do that, head over your `config/app.php` file and add
105106
the following line into the `providers` array:
106107

107-
'Baum\BaumServiceProvider',
108+
'Baum\Providers\BaumServiceProvider',
108109

109110
<a name="getting-started"></a>
110111
## Getting started

bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
$capsule->addConnection(require(__DIR__.'/tests/config/database.php'));
1414

15-
$capsule->setEventDispatcher(new Illuminate\Events\Dispatcher);
15+
$capsule->setEventDispatcher(new Illuminate\Events\Dispatcher(new Illuminate\Container\Container));
1616

1717
$capsule->bootEloquent();
1818

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "baum/baum",
33
"type": "library",
44
"description": "Baum is an implementation of the Nested Set pattern for Eloquent models.",
5-
"keywords": ["nested set", "laravel", "laravel 4", "eloquent", "database"],
5+
"keywords": ["nested set", "laravel", "laravel 4", "laravel 5", "eloquent", "database"],
66
"license": "MIT",
77
"authors": [
88
{
@@ -12,16 +12,17 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=5.3.0",
16-
"illuminate/support": "4.*|5.*",
17-
"illuminate/console": "4.*|5.*",
18-
"illuminate/filesystem": "4.*|5.*",
19-
"illuminate/database": "4.*|5.*"
15+
"php": ">=5.4.0",
16+
"illuminate/console": "5.*",
17+
"illuminate/database": "5.*",
18+
"illuminate/events": "5.*",
19+
"illuminate/filesystem": "5.*",
20+
"illuminate/support": "5.*"
2021
},
2122
"require-dev": {
2223
"phpunit/phpunit": "~4.0",
2324
"mockery/mockery": "~0.9",
24-
"d11wtq/boris": "~1.0"
25+
"d11wtq/boris": "~1.0.10"
2526
},
2627
"autoload": {
2728
"psr-0": {

src/Baum/Console/InstallCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public function fire() {
6565

6666
$this->writeModel($name);
6767

68-
$this->call('dump-autoload');
6968
}
7069

7170
/**
@@ -109,7 +108,7 @@ protected function writeModel($name) {
109108
* @return string
110109
*/
111110
protected function getMigrationsPath() {
112-
return $this->laravel['path'].'/database/migrations';
111+
return $this->laravel['path.database'].'/migrations';
113112
}
114113

115114
/**
@@ -118,7 +117,7 @@ protected function getMigrationsPath() {
118117
* @return string
119118
*/
120119
protected function getModelsPath() {
121-
return $this->laravel['path'].'/models';
120+
return $this->laravel['path.base'];
122121
}
123122

124123
}

src/Baum/Extensions/Eloquent/Model.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2-
32
namespace Baum\Extensions\Eloquent;
43

54
use Illuminate\Database\Eloquent\Model as BaseModel;
65
use Illuminate\Database\Eloquent\ModelNotFoundException;
6+
use Illuminate\Database\Eloquent\SoftDeletingScope;
77
use Baum\Extensions\Query\Builder as QueryBuilder;
88

99
abstract class Model extends BaseModel {
@@ -50,8 +50,8 @@ public function getObservableEvents() {
5050
* @param Closure|string $callback
5151
* @return void
5252
*/
53-
public static function moving($callback) {
54-
static::registerModelEvent('moving', $callback);
53+
public static function moving($callback, $priority = 0) {
54+
static::registerModelEvent('moving', $callback, $priority);
5555
}
5656

5757
/**
@@ -60,8 +60,8 @@ public static function moving($callback) {
6060
* @param Closure|string $callback
6161
* @return void
6262
*/
63-
public static function moved($callback) {
64-
static::registerModelEvent('moved', $callback);
63+
public static function moved($callback, $priority = 0) {
64+
static::registerModelEvent('moved', $callback, $priority);
6565
}
6666

6767
/**
@@ -95,18 +95,15 @@ protected function getFreshInstance() {
9595
* @return boolean
9696
*/
9797
public function areSoftDeletesEnabled() {
98-
// Soft-delete functionality in 4.2 has been moved into a trait.
99-
// The proper way to check if a model includes a global scope in >= 4.2
100-
// should look similar to the following:
101-
//
102-
// static::hasGlobalScope(new SoftDeletingScope);
103-
//
104-
// We are doing it this way (not the best probably) to keep backwards
105-
// compatibility...
106-
return (
107-
(property_exists($this, 'softDelete') && $this->softDelete == true) ||
108-
(!property_exists($this, 'softDelete') && method_exists($this, 'getDeletedAtColumn'))
109-
);
98+
// To determine if there's a global soft delete scope defined we must
99+
// first determine if there are any, to workaround a non-existent key error.
100+
$globalScopes = $this->getGlobalScopes();
101+
102+
if ( count($globalScopes) === 0 ) return false;
103+
104+
// Now that we're sure that the calling class has some kind of global scope
105+
// we check for the SoftDeletingScope existance
106+
return static::hasGlobalScope(new SoftDeletingScope);
110107
}
111108

112109
/**

src/Baum/Generators/stubs/model.php

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,8 @@ class {{class}} extends Node {
9595
// In the same way as Eloquent's model events, returning false from the
9696
// `moving` event handler will halt the operation.
9797
//
98-
// Below is a sample `boot` method just for convenience, as an example of how
99-
// one should hook into those events. This is the *recommended* way to hook
100-
// into model events, as stated in the documentation. Please refer to the
101-
// Laravel documentation for details.
102-
//
103-
// If you don't plan on using model events in your program you can safely
104-
// remove all the commented code below.
105-
//
106-
107-
// /**
108-
// * The "booting" method of the model.
109-
// *
110-
// * @return void
111-
// */
112-
// protected static function boot() {
113-
// // Do not forget this!
114-
// parent::boot();
115-
116-
// static::moving(function($node) {
117-
// // YOUR CODE HERE
118-
// });
119-
120-
// static::moved(function($node) {
121-
// // YOUR CODE HERE
122-
// });
123-
// }
98+
// Please refer the Laravel documentation for further instructions on how
99+
// to hook your own callbacks/observers into this events:
100+
// http://laravel.com/docs/5.0/eloquent#model-events
124101

125102
}
Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Baum;
2+
namespace Baum\Providers;
33

44
use Baum\Generators\MigrationGenerator;
55
use Baum\Generators\ModelGenerator;
@@ -14,23 +14,7 @@ class BaumServiceProvider extends ServiceProvider {
1414
*
1515
* @var string
1616
*/
17-
const VERSION = '1.0.13';
18-
19-
/**
20-
* Indicates if loading of the provider is deferred.
21-
*
22-
* @var bool
23-
*/
24-
protected $defer = false;
25-
26-
/**
27-
* Bootstrap the application events.
28-
*
29-
* @return void
30-
*/
31-
public function boot() {
32-
$this->package('baum/baum');
33-
}
17+
const VERSION = '1.1.0';
3418

3519
/**
3620
* Register the service provider.
@@ -41,15 +25,6 @@ public function register() {
4125
$this->registerCommands();
4226
}
4327

44-
/**
45-
* Get the services provided by the provider.
46-
*
47-
* @return array
48-
*/
49-
public function provides() {
50-
return array('node');
51-
}
52-
5328
/**
5429
* Register the commands.
5530
*
@@ -70,8 +45,8 @@ public function registerCommands() {
7045
* @return void
7146
*/
7247
protected function registerBaumCommand() {
73-
$this->app['command.baum'] = $this->app->share(function($app) {
74-
return new BaumCommand();
48+
$this->app->singleton('command.baum', function($app) {
49+
return new BaumCommand;
7550
});
7651
}
7752

@@ -81,12 +56,21 @@ protected function registerBaumCommand() {
8156
* @return void
8257
*/
8358
protected function registerInstallCommand() {
84-
$this->app['command.baum.install'] = $this->app->share(function($app) {
59+
$this->app->singleton('command.baum.install', function($app) {
8560
$migrator = new MigrationGenerator($app['files']);
8661
$modeler = new ModelGenerator($app['files']);
8762

8863
return new InstallCommand($migrator, $modeler);
8964
});
9065
}
9166

67+
/**
68+
* Get the services provided by the provider.
69+
*
70+
* @return array
71+
*/
72+
public function provides() {
73+
return array('command.baum', 'command.baum.install');
74+
}
75+
9276
}

tests/models/Category.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use Illuminate\Database\Eloquent\SoftDeletingTrait;
3+
use Illuminate\Database\Eloquent\SoftDeletes;
44
use Baum\Node;
55

66
class Category extends Node {
@@ -39,7 +39,7 @@ class OrderedScopedCategory extends Category {
3939

4040
class SoftCategory extends Category {
4141

42-
use SoftDeletingTrait;
42+
use SoftDeletes;
4343

4444
public $timestamps = true;
4545

tests/models/Cluster.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use Illuminate\Database\Eloquent\SoftDeletingTrait;
3+
use Illuminate\Database\Eloquent\SoftDeletes;
44
use Baum\Node;
55

66
class Cluster extends Node {
@@ -58,7 +58,7 @@ class OrderedCluster extends Cluster {
5858

5959
class SoftCluster extends Cluster {
6060

61-
use SoftDeletingTrait;
61+
use SoftDeletes;
6262

6363
public $timestamps = true;
6464

0 commit comments

Comments
 (0)