diff --git a/composer.json b/composer.json
index 846a36c1..94a3ab26 100644
--- a/composer.json
+++ b/composer.json
@@ -20,22 +20,23 @@
}
],
"require": {
- "php": ">=7.4",
- "illuminate/container": "^8.0",
- "illuminate/contracts": "^8.0",
- "illuminate/database": "^8.0",
- "illuminate/events": "^8.0",
- "illuminate/support": "^8.0",
- "illuminate/pagination": "^8.0",
+ "php": "^8.2",
+ "illuminate/container": "^10.0",
+ "illuminate/contracts": "^10.0",
+ "illuminate/database": "^10.0",
+ "illuminate/events": "^10.0",
+ "illuminate/support": "^10.0",
+ "illuminate/pagination": "^10.0",
+ "illuminate/console": "^10.0",
"nesbot/carbon": "^2.0",
- "laudis/neo4j-php-client": "^2.3.3"
+ "laudis/neo4j-php-client": "^3.0"
},
"require-dev": {
- "mockery/mockery": "~1.3.0",
- "phpunit/phpunit": "^9.0",
+ "mockery/mockery": "~1.6.0",
+ "phpunit/phpunit": "^10.0",
"symfony/var-dumper": "*",
- "fzaninotto/faker": "~1.4",
- "composer/composer": "^2.1"
+ "fakerphp/faker": "^1.9.1",
+ "composer/composer": "^2.6"
},
"autoload": {
"psr-4": {
@@ -54,5 +55,10 @@
"Vinelab\\NeoEloquent\\NeoEloquentServiceProvider"
]
}
+ },
+ "config": {
+ "allow-plugins": {
+ "php-http/discovery": true
+ }
}
}
diff --git a/src/Connection.php b/src/Connection.php
index 33629832..814b397c 100644
--- a/src/Connection.php
+++ b/src/Connection.php
@@ -926,11 +926,9 @@ public function node($label)
return $query->from($label);
}
-
+
/**
* Get a new query builder instance.
- *
- * @return \Illuminate\Database\Query\Builder
*/
public function query()
{
@@ -1071,7 +1069,7 @@ public function reconnect()
/**
* Reconnect to the database if a PDO connection is missing.
*/
- protected function reconnectIfMissingConnection()
+ public function reconnectIfMissingConnection()
{
if (is_null($this->getClient())) {
$this->reconnect();
diff --git a/src/ConnectionAdapter.php b/src/ConnectionAdapter.php
index 34c0932d..00a21c90 100644
--- a/src/ConnectionAdapter.php
+++ b/src/ConnectionAdapter.php
@@ -3,11 +3,9 @@
namespace Vinelab\NeoEloquent;
use Closure;
-use Exception;
+use Illuminate\Support\Facades\App;
use Throwable;
use Vinelab\NeoEloquent\Exceptions\QueryException;
-use Vinelab\NeoEloquent\ConnectionInterface;
-
use Illuminate\Contracts\Events\Dispatcher as IlluminateDispatcher;
use Illuminate\Database\Query\Grammars\Grammar;
use Illuminate\Database\Query\Processors\Processor;
@@ -369,7 +367,7 @@ public function reconnect()
*
* @return void
*/
- protected function reconnectIfMissingConnection()
+ public function reconnectIfMissingConnection()
{
$this->neoeloquent->reconnectIfMissingConnection();
}
@@ -535,15 +533,14 @@ public function getEventDispatcher()
return $this->neoeloquent->getEventDispatcher();
}
- /**
- * Set the event dispatcher instance on the connection.
- *
- * @param \Illuminate\Contracts\Events\Dispatcher
- * @return void
- */
- public function setEventDispatcher(IlluminateDispatcher $events)
+ /**
+ * @param IlluminateDispatcher $events
+ *
+ * @return void
+ */
+ public function setEventDispatcher(IlluminateDispatcher $events)
{
- $this->neoeloquent->setEventDispatcher(\App::make(Dispatcher::class));
+ $this->neoeloquent->setEventDispatcher(App::make(Dispatcher::class));
}
/**
diff --git a/src/Console/Migrations/MigrateCommand.php b/src/Console/Migrations/MigrateCommand.php
index 87388f9f..b8180412 100644
--- a/src/Console/Migrations/MigrateCommand.php
+++ b/src/Console/Migrations/MigrateCommand.php
@@ -20,61 +20,39 @@ class MigrateCommand extends BaseCommand
*/
protected $description = 'Run the database migrations';
- /**
- * The migrator instance.
- *
- * @var \Vinelab\NeoEloquent\Migrations\Migrator
- */
- protected $migrator;
-
- /**
- * The path to the packages directory (vendor).
- */
- protected $packagePath;
-
- /**
- * @param \Vinelab\NeoEloquent\Migrations\Migrator $migrator
- * @param string $packagePath
- */
- public function __construct(Migrator $migrator, $packagePath)
+ public function __construct(protected Migrator $migrator, protected string $packagePath)
{
parent::__construct();
-
- $this->migrator = $migrator;
- $this->packagePath = $packagePath;
}
- /**
- * {@inheritDoc}
- */
- public function fire()
+ public function handle()
{
- if (!$this->confirmToProceed()) {
+ if(!$this->confirmToProceed()) {
return;
}
// The pretend option can be used for "simulating" the migration and grabbing
// the SQL queries that would fire if the migration were to be run against
// a database for real, which is helpful for double checking migrations.
- $pretend = $this->input->getOption('pretend');
+ $pretend = $this->input->getOption(name: 'pretend');
$path = $this->getMigrationPath();
- $this->migrator->setConnection($this->input->getOption('database'));
- $this->migrator->run($path, ['pretend' => $pretend]);
+ $this->migrator->setConnection(name: $this->input->getOption(name: 'database'));
+ $this->migrator->run(paths: $path, options: ['pretend' => $pretend]);
// Once the migrator has run we will grab the note output and send it out to
// the console screen, since the migrator itself functions without having
// any instances of the OutputInterface contract passed into the class.
- foreach ($this->migrator->getNotes() as $note) {
- $this->output->writeln($note);
+ foreach($this->migrator->getNotes() as $note) {
+ $this->output->writeln(messages: $note);
}
// Finally, if the "seed" option has been given, we will re-run the database
// seed task to re-populate the database, which is convenient when adding
// a migration and a seed at the same time, as it is only this command.
- if ($this->input->getOption('seed')) {
- $this->call('db:seed', ['--force' => true]);
+ if($this->input->getOption(name: 'seed')) {
+ $this->call(command: 'db:seed', arguments: ['--force' => true]);
}
}
@@ -83,20 +61,20 @@ public function fire()
*/
protected function getOptions()
{
- return array(
- array('bench', null, InputOption::VALUE_OPTIONAL, 'The name of the workbench to migrate.', null),
+ return [
+ ['bench', null, InputOption::VALUE_OPTIONAL, 'The name of the workbench to migrate.', null],
- array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
+ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],
- array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
+ ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
- array('path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null),
+ ['path', null, InputOption::VALUE_OPTIONAL, 'The path to migration files.', null],
- array('package', null, InputOption::VALUE_OPTIONAL, 'The package to migrate.', null),
+ ['package', null, InputOption::VALUE_OPTIONAL, 'The package to migrate.', null],
- array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
+ ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'],
- array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'),
- );
+ ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'],
+ ];
}
}
diff --git a/src/Console/Migrations/MigrateMakeCommand.php b/src/Console/Migrations/MigrateMakeCommand.php
index 6a83fbfd..7c131278 100644
--- a/src/Console/Migrations/MigrateMakeCommand.php
+++ b/src/Console/Migrations/MigrateMakeCommand.php
@@ -2,6 +2,7 @@
namespace Vinelab\NeoEloquent\Console\Migrations;
+use Exception;
use Illuminate\Support\Composer;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
@@ -19,105 +20,72 @@ class MigrateMakeCommand extends BaseCommand
*/
protected $description = 'Create a new migration file';
- /**
- * @var \Vinelab\NeoEloquent\Migrations\MigrationCreator
- */
- protected $creator;
-
- /**
- * The path to the packages directory (vendor).
- *
- * @var string
- */
- protected $packagePath;
-
- /**
- * @var \Illuminate\Foundation\Composer
- */
- protected $composer;
-
- /**
- * @param \Vinelab\NeoEloquent\Migrations\MigrationCreator $creator
- * @param string $packagePath
- */
- public function __construct(MigrationCreator $creator, Composer $composer, $packagePath)
+ public function __construct(protected MigrationCreator $creator, protected Composer $composer, protected string $packagePath)
{
parent::__construct();
- $this->creator = $creator;
- $this->packagePath = $packagePath;
- $this->composer = $composer;
}
- /**
- * {@inheritDoc}
- */
- public function fire()
+ public function handle(): void
{
// It's possible for the developer to specify the tables to modify in this
// schema operation. The developer may also specify if this label needs
// to be freshly created so we can create the appropriate migrations.
- $name = $this->input->getArgument('name');
+ $name = $this->input->getArgument(name: 'name');
- $label = $this->input->getOption('label');
+ $label = $this->input->getOption(name: 'label');
- $modify = $this->input->getOption('create');
+ $modify = $this->input->getOption(name: 'create');
- if (!$label && is_string($modify)) {
+ if(!$label && \is_string(value: $modify)) {
$label = $modify;
}
// Now we are ready to write the migration out to disk. Once we've written
// the migration out, we will dump-autoload for the entire framework to
// make sure that the migrations are registered by the class loaders.
- $this->writeMigration($name, $label);
+ $this->writeMigration(name: $name, label: $label);
$this->composer->dumpAutoloads();
}
/**
- * Write the migration file to disk.
- *
- * @param string $name
- * @param string $label
- * @param bool $create
- *
- * @return string
+ * @throws Exception
*/
- protected function writeMigration($name, $label)
+ protected function writeMigration(string $name, string $label = null): void
{
$path = $this->getMigrationPath();
- $file = pathinfo($this->creator->create($name, $path, $label), PATHINFO_FILENAME);
+ $file = pathinfo(path: $this->creator->create(name: $name, path: $path, table: $label), flags: PATHINFO_FILENAME);
- $this->line("Created Migration: $file");
+ $this->line(string: "Created Migration: $file");
}
/**
* {@inheritDoc}
*/
- protected function getArguments()
+ protected function getArguments(): array
{
- return array(
- array('name', InputArgument::REQUIRED, 'The name of the migration'),
- );
+ return [
+ ['name', InputArgument::REQUIRED, 'The name of the migration'],
+ ];
}
/**
* {@inheritDoc}
*/
- protected function getOptions()
+ protected function getOptions(): array
{
- return array(
- array('bench', null, InputOption::VALUE_OPTIONAL, 'The workbench the migration belongs to.', null),
+ return [
+ ['bench', null, InputOption::VALUE_OPTIONAL, 'The workbench the migration belongs to.', null],
- array('create', null, InputOption::VALUE_OPTIONAL, 'The label schema to be created.'),
+ ['create', null, InputOption::VALUE_OPTIONAL, 'The label schema to be created.'],
- array('package', null, InputOption::VALUE_OPTIONAL, 'The package the migration belongs to.', null),
+ ['package', null, InputOption::VALUE_OPTIONAL, 'The package the migration belongs to.', null],
- array('path', null, InputOption::VALUE_OPTIONAL, 'Where to store the migration.', null),
+ ['path', null, InputOption::VALUE_OPTIONAL, 'Where to store the migration.', null],
- array('label', null, InputOption::VALUE_OPTIONAL, 'The label to migrate.'),
- );
+ ['label', null, InputOption::VALUE_OPTIONAL, 'The label to migrate.'],
+ ];
}
}
diff --git a/src/Eloquent/Edges/Delegate.php b/src/Eloquent/Edges/Delegate.php
index 76e747e5..c3b4cb02 100644
--- a/src/Eloquent/Edges/Delegate.php
+++ b/src/Eloquent/Edges/Delegate.php
@@ -256,7 +256,7 @@ public function asNode(Model $model): ?Node
unset($properties['id']);
}
- return new Node($id, new CypherList([$label]), new CypherMap($properties));
+ return new Node($id, new CypherList([$label]), new CypherMap($properties), null);
}
/**
diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php
index 28bd8b62..5ec041eb 100644
--- a/src/Eloquent/Model.php
+++ b/src/Eloquent/Model.php
@@ -792,7 +792,7 @@ public function newEloquentBuilder($query)
* @override
* Get a new query builder instance for the connection.
*
- * @return Vinelab\NeoEloquent\Query\Builder
+ * @return QueryBuilder
*/
protected function newBaseQueryBuilder()
{
diff --git a/src/MigrationServiceProvider.php b/src/MigrationServiceProvider.php
index 6f5ba9f7..ae60bceb 100644
--- a/src/MigrationServiceProvider.php
+++ b/src/MigrationServiceProvider.php
@@ -13,24 +13,16 @@
use Vinelab\NeoEloquent\Console\Migrations\MigrateRefreshCommand;
use Vinelab\NeoEloquent\Console\Migrations\MigrateRollbackCommand;
-class MigrationServiceProvider extends ServiceProvider {
-
- /**
- * {@inheritDoc}
- */
+class MigrationServiceProvider extends ServiceProvider
+{
protected $defer = true;
- /**
- * {@inheritDoc}
- */
- public function boot()
- {
- }
+ public function boot() {}
/**
* {@inheritDoc}
*/
- public function register()
+ public function register(): void
{
$this->registerRepository();
@@ -45,66 +37,67 @@ public function register()
/**
* Register the migration repository service.
*
- * @return void
*/
- protected function registerRepository()
+ protected function registerRepository(): void
{
- $this->app->singleton('neoeloquent.migration.repository', function($app)
- {
- $model = new MigrationModel;
-
- $label = $app['config']['database.migrations_node'];
-
- if (isset($label)) {
- $model->setLabel($label);
- }
-
- return new DatabaseMigrationRepository(
- $app['db'],
- $app['db']->connection('neo4j')->getSchemaBuilder(),
- $model
- );
- });
+ $this->app->singleton(
+ abstract: 'neoeloquent.migration.repository',
+ concrete: function($app) {
+ $model = new MigrationModel();
+
+ $label = $app['config']['database.migrations_node'];
+
+ if(isset($label)) {
+ $model->setLabel(label: $label);
+ }
+
+ return new DatabaseMigrationRepository(
+ resolver: $app['db'],
+ schema : $app['db']->connection('neo4j')->getSchemaBuilder(),
+ model : $model,
+ );
+ },
+ );
}
/**
* Register the migrator service.
*
- * @return void
*/
- protected function registerMigrator()
+ protected function registerMigrator(): void
{
// The migrator is responsible for actually running and rollback the migration
// files in the application. We'll pass in our database connection resolver
// so the migrator can resolve any of these connections when it needs to.
- $this->app->singleton('neoeloquent.migrator', function($app) {
- $repository = $app['neoeloquent.migration.repository'];
+ $this->app->singleton(
+ abstract: 'neoeloquent.migrator',
+ concrete: function($app) {
+ $repository = $app['neoeloquent.migration.repository'];
- return new Migrator($repository, $app['db'], $app['files']);
- });
+ return new Migrator(repository: $repository, resolver: $app['db'], files: $app['files']);
+ },
+ );
}
/**
* Register all of the migration commands.
*
- * @return void
*/
- protected function registerCommands()
+ protected function registerCommands(): void
{
- $commands = array(
+ $commands = [
'Migrate',
'MigrateRollback',
'MigrateReset',
'MigrateRefresh',
- 'MigrateMake'
- );
+ 'MigrateMake',
+ ];
// We'll simply spin through the list of commands that are migration related
// and register each one of them with an application container. They will
// be resolved in the Artisan start file and registered on the console.
- foreach ($commands as $command)
- {
+ foreach($commands as $command) {
$this->{'register'.$command.'Command'}();
}
@@ -116,94 +109,104 @@ protected function registerCommands()
'command.neoeloquent.migrate.make',
'command.neoeloquent.migrate.rollback',
'command.neoeloquent.migrate.reset',
- 'command.neoeloquent.migrate.refresh'
+ 'command.neoeloquent.migrate.refresh',
);
}
/**
* Register the "migrate" migration command.
*
- * @return void
*/
- protected function registerMigrateCommand()
+ protected function registerMigrateCommand(): void
{
- $this->app->singleton('command.neoeloquent.migrate', function($app) {
- $packagePath = $app['path.base'].'/vendor';
+ $this->app->singleton(
+ abstract: 'command.neoeloquent.migrate',
+ concrete: function($app) {
+ $packagePath = $app['path.base'].'/vendor';
- return new MigrateCommand($app['neoeloquent.migrator'], $packagePath);
- });
+ return new MigrateCommand(migrator: $app['neoeloquent.migrator'], packagePath: $packagePath);
+ },
+ );
}
/**
* Register the "rollback" migration command.
*
- * @return void
*/
- protected function registerMigrateRollbackCommand()
+ protected function registerMigrateRollbackCommand(): void
{
- $this->app->singleton('command.neoeloquent.migrate.rollback', function($app)
- {
- return new MigrateRollbackCommand($app['neoeloquent.migrator']);
- });
+ $this->app->singleton(
+ abstract: 'command.neoeloquent.migrate.rollback',
+ concrete: function($app) {
+ return new MigrateRollbackCommand(migrator: $app['neoeloquent.migrator']);
+ },
+ );
}
/**
* Register the "reset" migration command.
*
- * @return void
*/
- protected function registerMigrateResetCommand()
+ protected function registerMigrateResetCommand(): void
{
- $this->app->singleton('command.neoeloquent.migrate.reset', function($app)
- {
- return new MigrateResetCommand($app['neoeloquent.migrator']);
- });
+ $this->app->singleton(
+ abstract: 'command.neoeloquent.migrate.reset',
+ concrete: function($app) {
+ return new MigrateResetCommand(migrator: $app['neoeloquent.migrator']);
+ },
+ );
}
/**
* Register the "refresh" migration command.
*
- * @return void
*/
- protected function registerMigrateRefreshCommand()
+ protected function registerMigrateRefreshCommand(): void
{
- $this->app->singleton('command.neoeloquent.migrate.refresh', function($app)
- {
- return new MigrateRefreshCommand();
- });
+ $this->app->singleton(
+ abstract: 'command.neoeloquent.migrate.refresh',
+ concrete: function($app) {
+ return new MigrateRefreshCommand();
+ },
+ );
}
/**
* Register the "install" migration command.
*
- * @return void
*/
- protected function registerMigrateMakeCommand()
+ protected function registerMigrateMakeCommand(): void
{
- $this->app->singleton('migration.neoeloquent.creator', function($app) {
- return new MigrationCreator($app['files'], $app->basePath('stubs'));
- });
+ $this->app->singleton(
+ abstract: 'migration.neoeloquent.creator',
+ concrete: function($app) {
+ return new MigrationCreator(files: $app['files'], customStubPath: $app->basePath('stubs'));
+ },
+ );
- $this->app->singleton('command.neoeloquent.migrate.make', function($app) {
- // Once we have the migration creator registered, we will create the command
- // and inject the creator. The creator is responsible for the actual file
- // creation of the migrations, and may be extended by these developers.
- $creator = $app['migration.neoeloquent.creator'];
+ $this->app->singleton(
+ abstract: 'command.neoeloquent.migrate.make',
+ concrete: function($app) {
+ // Once we have the migration creator registered, we will create the command
+ // and inject the creator. The creator is responsible for the actual file
+ // creation of the migrations, and may be extended by these developers.
+ $creator = $app['migration.neoeloquent.creator'];
- $packagePath = $app['path.base'].'/vendor';
+ $packagePath = $app['path.base'].'/vendor';
- $composer = $app->make('Illuminate\Support\Composer');
+ $composer = $app->make('Illuminate\Support\Composer');
- return new MigrateMakeCommand($creator, $composer, $packagePath);
- });
+ return new MigrateMakeCommand(creator: $creator, composer: $composer, packagePath: $packagePath);
+ },
+ );
}
/**
* {@inheritDoc}
*/
- public function provides()
+ public function provides(): array
{
- return array(
+ return [
'neoeloquent.migrator',
'neoeloquent.migration.repository',
'command.neoeloquent.migrate',
@@ -212,7 +215,7 @@ public function provides()
'command.neoeloquent.migrate.refresh',
'migration.neoeloquent.creator',
'command.neoeloquent.migrate.make',
- );
+ ];
}
}
diff --git a/src/Migrations/DatabaseMigrationRepository.php b/src/Migrations/DatabaseMigrationRepository.php
index 47203595..3da89da6 100644
--- a/src/Migrations/DatabaseMigrationRepository.php
+++ b/src/Migrations/DatabaseMigrationRepository.php
@@ -47,7 +47,7 @@ public function __construct(ConnectionResolverInterface $resolver, SchemaBuilder
*/
public function getRan()
{
- return $this->model->all()->lists('migration');
+ return $this->model->all()->pluck('migration')->toArray();
}
/**
@@ -63,6 +63,21 @@ public function getMigrations($steps)
return $query->orderBy('migration', 'desc')->take($steps)->get()->all();
}
+ /**
+ * Get the list of the migrations by batch number.
+ *
+ * @param int $batch
+ * @return array
+ */
+ public function getMigrationsByBatch($batch)
+ {
+ return $this->label()
+ ->where('batch', $batch)
+ ->orderBy('migration', 'desc')
+ ->get()
+ ->all();
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/src/Migrations/MigrationCreator.php b/src/Migrations/MigrationCreator.php
index adb467e1..9f0f1717 100644
--- a/src/Migrations/MigrationCreator.php
+++ b/src/Migrations/MigrationCreator.php
@@ -2,37 +2,87 @@
namespace Vinelab\NeoEloquent\Migrations;
+use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Database\Migrations\MigrationCreator as IlluminateMigrationCreator;
+use Illuminate\Support\Str;
class MigrationCreator extends IlluminateMigrationCreator
{
/**
- * Populate the place-holders in the migration stub.
- *
- * @param string $name
- * @param string $stub
- * @param string $label
+ * @param string $stub
+ * @param null|string $table
*
* @return string
*/
- protected function populateStub($name, $stub, $label)
+ protected function populateStub($stub, $table)
{
- $stub = str_replace('{{class}}', studly_case($name), $stub);
+ $stub = str_replace('{{class}}', Str::studly($table), $stub);
- // Here we will replace the label place-holders with the label specified by
- // the developer, which is useful for quickly creating a labels creation
+ // Here we will replace the table place-holders with the table specified by
+ // the developer, which is useful for quickly creating a tables creation
// or update migration from the console instead of typing it manually.
- if (!is_null($label)) {
- $stub = str_replace('{{label}}', $label, $stub);
+ if ($table !== null) {
+ $stub = str_replace(
+ ['{{ table }}', '{{table}}'],
+ $table, $stub
+ );
}
return $stub;
}
/**
- * {@inheritDoc}
+ * @throws FileNotFoundException
+ */
+ protected function getStub($table, $create)
+ {
+ $customPath = $this->customStubPath;
+ if ($table === null) {
+ $stub = $this->files->exists(path: "$customPath/blank.stub")
+ ? $customPath
+ : $this->stubPath().'/blank.stub';
+ } elseif ($create) {
+ $stub = $this->files->exists(path: "$customPath/create.stub")
+ ? $customPath
+ : $this->stubPath().'/create.stub';
+ } else {
+ $stub = $this->files->exists(path: "$customPath/update.stub")
+ ? $customPath
+ : $this->stubPath().'/update.stub';
+ }
+
+ return $this->files->get($stub);
+ }
+
+ public function create($name, $path, $table = null, $create = false)
+ {
+ $this->ensureMigrationDoesntAlreadyExist($name, $path);
+
+ // First we will get the stub file for the migration, which serves as a type
+ // of template for the migration. Once we have those we will populate the
+ // various place-holders, save the file, and run the post create event.
+ $stub = $this->getStub($table, $create);
+
+ $path = $this->getPath($name, $path);
+
+ $this->files->ensureDirectoryExists(\dirname($path));
+
+ $this->files->put(
+ $path, $this->populateStub($stub, $table ?? $name)
+ );
+
+ // Next, we will fire any hooks that are supposed to fire after a migration is
+ // created. Once that is done we'll be ready to return the full path to the
+ // migration file so it can be used however it's needed by the developer.
+ $this->firePostCreateHooks($table, $path);
+
+ return $path;
+ }
+
+ /**
+ * @return string
*/
- public function getStubPath()
+ public function stubPath()
{
return __DIR__.'/stubs';
}
diff --git a/src/Query/Builder.php b/src/Query/Builder.php
index dac2202a..1666c92d 100644
--- a/src/Query/Builder.php
+++ b/src/Query/Builder.php
@@ -7,10 +7,10 @@
use Carbon\Carbon;
use BadMethodCallException;
use InvalidArgumentException;
+use Laudis\Neo4j\Databags\SummarizedResult;
use Laudis\Neo4j\Types\CypherList;
use Laudis\Neo4j\Types\Node;
use Vinelab\NeoEloquent\ConnectionInterface;
-use GraphAware\Common\Result\AbstractRecordCursor as Result;
use Vinelab\NeoEloquent\Eloquent\Collection;
use Vinelab\NeoEloquent\Query\Grammars\Grammar;
@@ -216,8 +216,6 @@ class Builder
/**
* Create a new query builder instance.
- *
- * @param Vinelab\NeoEloquent\Connection $connection
*/
public function __construct(ConnectionInterface $connection, Grammar $grammar)
{
@@ -453,7 +451,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
}
if (func_num_args() == 2) {
- list($value, $operator) = array($operator, '=');
+ [$value, $operator] = array($operator, '=');
} elseif ($this->invalidOperatorAndValue($operator, $value)) {
throw new \InvalidArgumentException('Value must be provided.');
}
@@ -469,7 +467,7 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
// assume that the developer is just short-cutting the '=' operators and
// we will set the operators to '=' and set the values appropriately.
if (!in_array(mb_strtolower($operator), $this->operators, true)) {
- list($value, $operator) = array($operator, '=');
+ [$value, $operator] = array($operator, '=');
}
// If the value is a Closure, it means the developer is performing an entire
@@ -1406,7 +1404,7 @@ public function get($columns = ['*'])
*
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
- public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
+ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
$page = $page ?: Paginator::resolveCurrentPage($pageName);
@@ -1456,8 +1454,11 @@ public function getCountForPagination($columns = ['*'])
$this->aggregate = ['function' => 'count', 'columns' => $columns];
+ /**
+ *
+ * @var SummarizedResult $results
+ */
$results = $this->get();
-
$this->aggregate = null;
$this->restoreFieldsForCount();
@@ -1466,7 +1467,7 @@ public function getCountForPagination($columns = ['*'])
return count($results);
}
- return isset($results[0]) ? (int) array_change_key_case((array) $results[0])['aggregate'] : 0;
+ return isset($results[0]) ? (int) $results->get(0)->get('count(*)') : 0;
}
/**
@@ -1720,13 +1721,7 @@ public function delete($id = null)
$cypher = $this->grammar->compileDelete($this);
- $result = $this->connection->delete($cypher, $this->getBindings());
-
- if ($result instanceof Result) {
- $result = true;
- }
-
- return $result;
+ return $this->connection->delete($cypher, $this->getBindings());
}
/**
@@ -2251,8 +2246,8 @@ public function countDistinct($column)
public function aggregate($function, $columns = array('*'), $percentile = null)
{
$this->aggregate = array_merge([
- 'label' => $this->from,
- ], compact('function', 'columns', 'percentile'));
+ 'label' => $this->from,
+ ], compact('function', 'columns', 'percentile'));
$previousColumns = $this->columns;