repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
orchestral/tenanti
src/Migrator/Operation.php
Operation.executeFor
public function executeFor($id, Closure $callback): void { $callback( $this->newQuery()->findOrFail($id) ); }
php
public function executeFor($id, Closure $callback): void { $callback( $this->newQuery()->findOrFail($id) ); }
[ "public", "function", "executeFor", "(", "$", "id", ",", "Closure", "$", "callback", ")", ":", "void", "{", "$", "callback", "(", "$", "this", "->", "newQuery", "(", ")", "->", "findOrFail", "(", "$", "id", ")", ")", ";", "}" ]
Execute query by id. @param int|string $id @param \Closure $callback @return void
[ "Execute", "query", "by", "id", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L74-L79
orchestral/tenanti
src/Migrator/Operation.php
Operation.executeForEach
public function executeForEach(Closure $callback): void { $query = $this->newQuery(); foreach ($query->cursor() as $entity) { $callback($entity); } }
php
public function executeForEach(Closure $callback): void { $query = $this->newQuery(); foreach ($query->cursor() as $entity) { $callback($entity); } }
[ "public", "function", "executeForEach", "(", "Closure", "$", "callback", ")", ":", "void", "{", "$", "query", "=", "$", "this", "->", "newQuery", "(", ")", ";", "foreach", "(", "$", "query", "->", "cursor", "(", ")", "as", "$", "entity", ")", "{", ...
Execute query via cursor. @param \Closure $callback @return void
[ "Execute", "query", "via", "cursor", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L88-L95
orchestral/tenanti
src/Migrator/Operation.php
Operation.getModel
public function getModel(): Model { $name = $this->getModelName(); $model = $this->app->make($name); if (! $model instanceof Model) { throw new InvalidArgumentException("Model [{$name}] should be an instance of Eloquent."); } $database = $this->getConfig('database'); if (! \is_null($database)) { $model->setConnection($database); } $model->useWritePdo(); return $model; }
php
public function getModel(): Model { $name = $this->getModelName(); $model = $this->app->make($name); if (! $model instanceof Model) { throw new InvalidArgumentException("Model [{$name}] should be an instance of Eloquent."); } $database = $this->getConfig('database'); if (! \is_null($database)) { $model->setConnection($database); } $model->useWritePdo(); return $model; }
[ "public", "function", "getModel", "(", ")", ":", "Model", "{", "$", "name", "=", "$", "this", "->", "getModelName", "(", ")", ";", "$", "model", "=", "$", "this", "->", "app", "->", "make", "(", "$", "name", ")", ";", "if", "(", "!", "$", "mode...
Resolve model. @throws \InvalidArgumentException @return \Illuminate\Database\Eloquent\Model
[ "Resolve", "model", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L117-L135
orchestral/tenanti
src/Migrator/Operation.php
Operation.resolveMigrator
protected function resolveMigrator(string $table): Migrator { $app = $this->app; if (! isset($this->migrator[$table])) { $respositoryClass = $this->resolver['repository']; $migratorClass = $this->resolver['migrator']; $repository = new $respositoryClass($app['db'], $table); $migrator = new $migratorClass($repository, $app['db'], $app['files']); $this->migrator[$table] = $migrator; } return $this->migrator[$table]; }
php
protected function resolveMigrator(string $table): Migrator { $app = $this->app; if (! isset($this->migrator[$table])) { $respositoryClass = $this->resolver['repository']; $migratorClass = $this->resolver['migrator']; $repository = new $respositoryClass($app['db'], $table); $migrator = new $migratorClass($repository, $app['db'], $app['files']); $this->migrator[$table] = $migrator; } return $this->migrator[$table]; }
[ "protected", "function", "resolveMigrator", "(", "string", "$", "table", ")", ":", "Migrator", "{", "$", "app", "=", "$", "this", "->", "app", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "migrator", "[", "$", "table", "]", ")", ")", "{", ...
Resolve migrator. @param string $table @return \Orchestra\Tenanti\Migrator\Migrator
[ "Resolve", "migrator", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L154-L169
orchestral/tenanti
src/Migrator/Operation.php
Operation.asDefaultConnection
public function asDefaultConnection(Model $entity, ?string $database): ?string { $connection = $this->asConnection($entity, $database); $this->app->make('config')->set('database.default', $connection); return $connection; }
php
public function asDefaultConnection(Model $entity, ?string $database): ?string { $connection = $this->asConnection($entity, $database); $this->app->make('config')->set('database.default', $connection); return $connection; }
[ "public", "function", "asDefaultConnection", "(", "Model", "$", "entity", ",", "?", "string", "$", "database", ")", ":", "?", "string", "{", "$", "connection", "=", "$", "this", "->", "asConnection", "(", "$", "entity", ",", "$", "database", ")", ";", ...
Set tenant as default database connection and get the connection name. @param \Illuminate\Database\Eloquent\Model $entity @param string|null $database @return string|null
[ "Set", "tenant", "as", "default", "database", "connection", "and", "get", "the", "connection", "name", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L179-L186
orchestral/tenanti
src/Migrator/Operation.php
Operation.asConnection
public function asConnection(Model $entity, ?string $database): ?string { $repository = $this->app->make('config'); $tenants = $this->getConfig('connection'); if (! \is_null($tenants)) { $database = $tenants['name']; } if (\substr($database, -5) !== '_{id}' && $this->getConfig('shared', true) === false) { $database .= '_{id}'; } $connection = $this->bindWithKey($entity, $database); $name = "database.connections.{$connection}"; if (! \is_null($tenants) && \is_null($repository->get($name))) { $config = $this->app->call($tenants['resolver'], [ 'entity' => $entity, 'template' => $tenants['template'], 'connection' => $connection, 'migrator' => $this, ]); $repository->set($name, $config); } return $connection; }
php
public function asConnection(Model $entity, ?string $database): ?string { $repository = $this->app->make('config'); $tenants = $this->getConfig('connection'); if (! \is_null($tenants)) { $database = $tenants['name']; } if (\substr($database, -5) !== '_{id}' && $this->getConfig('shared', true) === false) { $database .= '_{id}'; } $connection = $this->bindWithKey($entity, $database); $name = "database.connections.{$connection}"; if (! \is_null($tenants) && \is_null($repository->get($name))) { $config = $this->app->call($tenants['resolver'], [ 'entity' => $entity, 'template' => $tenants['template'], 'connection' => $connection, 'migrator' => $this, ]); $repository->set($name, $config); } return $connection; }
[ "public", "function", "asConnection", "(", "Model", "$", "entity", ",", "?", "string", "$", "database", ")", ":", "?", "string", "{", "$", "repository", "=", "$", "this", "->", "app", "->", "make", "(", "'config'", ")", ";", "$", "tenants", "=", "$",...
Set tenant database connection. @param \Illuminate\Database\Eloquent\Model $entity @param string|null $database @return string|null
[ "Set", "tenant", "database", "connection", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L196-L224
orchestral/tenanti
src/Migrator/Operation.php
Operation.resolveConnection
public function resolveConnection(Model $entity, string $database) { return $this->app->make('db')->connection($this->asConnection($entity, $database)); }
php
public function resolveConnection(Model $entity, string $database) { return $this->app->make('db')->connection($this->asConnection($entity, $database)); }
[ "public", "function", "resolveConnection", "(", "Model", "$", "entity", ",", "string", "$", "database", ")", "{", "return", "$", "this", "->", "app", "->", "make", "(", "'db'", ")", "->", "connection", "(", "$", "this", "->", "asConnection", "(", "$", ...
Resolve tenant database connection. @param \Illuminate\Database\Eloquent\Model $entity @param string $database @return \Illuminate\Database\Connection
[ "Resolve", "tenant", "database", "connection", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L234-L237
orchestral/tenanti
src/Migrator/Operation.php
Operation.resolveMigrationTableName
protected function resolveMigrationTableName(Model $entity): string { if (! \is_null($table = $this->getConfig('migration'))) { return $this->bindWithKey($entity, $table); } if ($this->getConfig('shared', true) === true) { return $this->bindWithKey($entity, $this->getTablePrefix().'_migrations'); } return 'tenant_migrations'; }
php
protected function resolveMigrationTableName(Model $entity): string { if (! \is_null($table = $this->getConfig('migration'))) { return $this->bindWithKey($entity, $table); } if ($this->getConfig('shared', true) === true) { return $this->bindWithKey($entity, $this->getTablePrefix().'_migrations'); } return 'tenant_migrations'; }
[ "protected", "function", "resolveMigrationTableName", "(", "Model", "$", "entity", ")", ":", "string", "{", "if", "(", "!", "\\", "is_null", "(", "$", "table", "=", "$", "this", "->", "getConfig", "(", "'migration'", ")", ")", ")", "{", "return", "$", ...
Get table name. @param \Illuminate\Database\Eloquent\Model $entity @return string
[ "Get", "table", "name", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L246-L257
orchestral/tenanti
src/Migrator/Operation.php
Operation.bindWithKey
protected function bindWithKey(Model $entity, ?string $name): ?string { if (\is_null($name) || (\strpos($name, '{') === false && \strpos($name, '}') === false)) { return $name; } $id = $entity->getKey(); if (! isset($this->data[$id])) { $data = \array_merge(Arr::dot(['entity' => $entity->toArray()]), \compact('id')); $this->data[$id] = $data; } return Str::replace($name, $this->data[$id]); }
php
protected function bindWithKey(Model $entity, ?string $name): ?string { if (\is_null($name) || (\strpos($name, '{') === false && \strpos($name, '}') === false)) { return $name; } $id = $entity->getKey(); if (! isset($this->data[$id])) { $data = \array_merge(Arr::dot(['entity' => $entity->toArray()]), \compact('id')); $this->data[$id] = $data; } return Str::replace($name, $this->data[$id]); }
[ "protected", "function", "bindWithKey", "(", "Model", "$", "entity", ",", "?", "string", "$", "name", ")", ":", "?", "string", "{", "if", "(", "\\", "is_null", "(", "$", "name", ")", "||", "(", "\\", "strpos", "(", "$", "name", ",", "'{'", ")", "...
Resolve table name. @param \Illuminate\Database\Eloquent\Model $entity @param string|null $name @return string|null
[ "Resolve", "table", "name", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L289-L304
orchestral/tenanti
src/Migrator/Operation.php
Operation.getMigrationPaths
public function getMigrationPaths(Model $entity = null): ?array { if (! \is_null($entity) && isset($this->migrationPaths[$entity->getKey()])) { return $this->migrationPaths[$entity->getKey()]; } return $this->getDefaultMigrationPaths(); }
php
public function getMigrationPaths(Model $entity = null): ?array { if (! \is_null($entity) && isset($this->migrationPaths[$entity->getKey()])) { return $this->migrationPaths[$entity->getKey()]; } return $this->getDefaultMigrationPaths(); }
[ "public", "function", "getMigrationPaths", "(", "Model", "$", "entity", "=", "null", ")", ":", "?", "array", "{", "if", "(", "!", "\\", "is_null", "(", "$", "entity", ")", "&&", "isset", "(", "$", "this", "->", "migrationPaths", "[", "$", "entity", "...
Get migration path. @param \Illuminate\Database\Eloquent\Model|null $entity @return array|null
[ "Get", "migration", "path", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L325-L332
orchestral/tenanti
src/Migrator/Operation.php
Operation.loadMigrationsFrom
public function loadMigrationsFrom($paths, Model $entity): void { $id = $entity->getKey(); if (! isset($this->migrationPaths[$id])) { $this->migrationPaths[$id] = $this->getDefaultMigrationPaths(); } $this->migrationPaths[$id] = \array_merge($this->migrationPaths[$id], Arr::wrap($paths)); $this->migrationPaths[$id] = \array_unique($this->migrationPaths[$id]); }
php
public function loadMigrationsFrom($paths, Model $entity): void { $id = $entity->getKey(); if (! isset($this->migrationPaths[$id])) { $this->migrationPaths[$id] = $this->getDefaultMigrationPaths(); } $this->migrationPaths[$id] = \array_merge($this->migrationPaths[$id], Arr::wrap($paths)); $this->migrationPaths[$id] = \array_unique($this->migrationPaths[$id]); }
[ "public", "function", "loadMigrationsFrom", "(", "$", "paths", ",", "Model", "$", "entity", ")", ":", "void", "{", "$", "id", "=", "$", "entity", "->", "getKey", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "migrationPaths", "[", ...
Load migrations from a specific path. @param string|array $paths @param \Illuminate\Database\Eloquent\Model $entity @return void
[ "Load", "migrations", "from", "a", "specific", "path", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Operation.php#L342-L352
orchestral/tenanti
src/Console/MigrateCommand.php
MigrateCommand.handle
public function handle() { if (! $this->confirmToProceed()) { return; } $driver = $this->getDriver(); $database = $this->option('database'); $id = $this->option('id'); $pretend = $this->option('pretend', false); $this->prepareDatabase($driver, $database, $id); $migrator = $this->tenant->driver($driver); $this->setupMigrationOutput($migrator); $migrator->run($database, $id, $pretend); }
php
public function handle() { if (! $this->confirmToProceed()) { return; } $driver = $this->getDriver(); $database = $this->option('database'); $id = $this->option('id'); $pretend = $this->option('pretend', false); $this->prepareDatabase($driver, $database, $id); $migrator = $this->tenant->driver($driver); $this->setupMigrationOutput($migrator); $migrator->run($database, $id, $pretend); }
[ "public", "function", "handle", "(", ")", "{", "if", "(", "!", "$", "this", "->", "confirmToProceed", "(", ")", ")", "{", "return", ";", "}", "$", "driver", "=", "$", "this", "->", "getDriver", "(", ")", ";", "$", "database", "=", "$", "this", "-...
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/MigrateCommand.php#L30-L48
orchestral/tenanti
src/Console/MigrateCommand.php
MigrateCommand.prepareDatabase
protected function prepareDatabase($driver, $database, $id = null) { $parameters = [ 'driver' => $driver, '--database' => $database, ]; if (! \is_null($id)) { $parameters['--id'] = $id; } $this->call('tenanti:install', $parameters); }
php
protected function prepareDatabase($driver, $database, $id = null) { $parameters = [ 'driver' => $driver, '--database' => $database, ]; if (! \is_null($id)) { $parameters['--id'] = $id; } $this->call('tenanti:install', $parameters); }
[ "protected", "function", "prepareDatabase", "(", "$", "driver", ",", "$", "database", ",", "$", "id", "=", "null", ")", "{", "$", "parameters", "=", "[", "'driver'", "=>", "$", "driver", ",", "'--database'", "=>", "$", "database", ",", "]", ";", "if", ...
Prepare the migration database for running. @param string $driver @param string|null $database @param mixed|null $id @return void
[ "Prepare", "the", "migration", "database", "for", "running", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/MigrateCommand.php#L59-L71
orchestral/tenanti
src/Observer.php
Observer.created
public function created(Model $entity) { $data = [ 'database' => $this->getConnectionName(), 'driver' => $this->getDriverName(), ]; $this->dispatch($this->getCreateTenantJob($entity, $data)); return true; }
php
public function created(Model $entity) { $data = [ 'database' => $this->getConnectionName(), 'driver' => $this->getDriverName(), ]; $this->dispatch($this->getCreateTenantJob($entity, $data)); return true; }
[ "public", "function", "created", "(", "Model", "$", "entity", ")", "{", "$", "data", "=", "[", "'database'", "=>", "$", "this", "->", "getConnectionName", "(", ")", ",", "'driver'", "=>", "$", "this", "->", "getDriverName", "(", ")", ",", "]", ";", "...
Run on created observer. @param \Illuminate\Database\Eloquent\Model $entity @return bool
[ "Run", "on", "created", "observer", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Observer.php#L38-L48
orchestral/tenanti
src/Observer.php
Observer.restored
public function restored(Model $entity) { $data = [ 'database' => $this->getConnectionName(), 'driver' => $this->getDriverName(), ]; $this->dispatch($this->getRestoreTenantJob($entity, $data)); return true; }
php
public function restored(Model $entity) { $data = [ 'database' => $this->getConnectionName(), 'driver' => $this->getDriverName(), ]; $this->dispatch($this->getRestoreTenantJob($entity, $data)); return true; }
[ "public", "function", "restored", "(", "Model", "$", "entity", ")", "{", "$", "data", "=", "[", "'database'", "=>", "$", "this", "->", "getConnectionName", "(", ")", ",", "'driver'", "=>", "$", "this", "->", "getDriverName", "(", ")", ",", "]", ";", ...
Run on restored observer. @param \Illuminate\Database\Eloquent\Model $entity @return bool
[ "Run", "on", "restored", "observer", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Observer.php#L57-L67
orchestral/tenanti
src/Observer.php
Observer.deleted
public function deleted(Model $entity) { $data = [ 'database' => $this->getConnectionName(), 'driver' => $this->getDriverName(), ]; $this->dispatch($this->getDeleteTenantJob($entity, $data)); return true; }
php
public function deleted(Model $entity) { $data = [ 'database' => $this->getConnectionName(), 'driver' => $this->getDriverName(), ]; $this->dispatch($this->getDeleteTenantJob($entity, $data)); return true; }
[ "public", "function", "deleted", "(", "Model", "$", "entity", ")", "{", "$", "data", "=", "[", "'database'", "=>", "$", "this", "->", "getConnectionName", "(", ")", ",", "'driver'", "=>", "$", "this", "->", "getDriverName", "(", ")", ",", "]", ";", "...
Run on deleted observer. @param \Illuminate\Database\Eloquent\Model $entity @return bool
[ "Run", "on", "deleted", "observer", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Observer.php#L76-L86
orchestral/tenanti
src/TenantiServiceProvider.php
TenantiServiceProvider.register
public function register() { $this->app->singleton('orchestra.tenanti', function (Application $app) { $manager = new TenantiManager($app); $this->registerConfigurationForManager($manager); return $manager; }); $this->app->alias('orchestra.tenanti', TenantiManager::class); }
php
public function register() { $this->app->singleton('orchestra.tenanti', function (Application $app) { $manager = new TenantiManager($app); $this->registerConfigurationForManager($manager); return $manager; }); $this->app->alias('orchestra.tenanti', TenantiManager::class); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'orchestra.tenanti'", ",", "function", "(", "Application", "$", "app", ")", "{", "$", "manager", "=", "new", "TenantiManager", "(", "$", "app", ")", ";", ...
Register the service provider. @return void
[ "Register", "the", "service", "provider", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiServiceProvider.php#L16-L27
orchestral/tenanti
src/TenantiServiceProvider.php
TenantiServiceProvider.registerConfigurationForManager
protected function registerConfigurationForManager(TenantiManager $manager): void { $namespace = $this->hasPackageRepository() ? 'orchestra/tenanti::' : 'orchestra.tenanti'; $this->app->booted(function ($app) use ($manager, $namespace) { $manager->setConfig($app->make('config')->get($namespace)); }); }
php
protected function registerConfigurationForManager(TenantiManager $manager): void { $namespace = $this->hasPackageRepository() ? 'orchestra/tenanti::' : 'orchestra.tenanti'; $this->app->booted(function ($app) use ($manager, $namespace) { $manager->setConfig($app->make('config')->get($namespace)); }); }
[ "protected", "function", "registerConfigurationForManager", "(", "TenantiManager", "$", "manager", ")", ":", "void", "{", "$", "namespace", "=", "$", "this", "->", "hasPackageRepository", "(", ")", "?", "'orchestra/tenanti::'", ":", "'orchestra.tenanti'", ";", "$", ...
Register configuration for manager. @param \Orchestra\Tenanti\TenantiManager $manager @return void
[ "Register", "configuration", "for", "manager", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiServiceProvider.php#L36-L43
orchestral/tenanti
src/TenantiServiceProvider.php
TenantiServiceProvider.boot
public function boot() { $path = \realpath(__DIR__.'/../'); $this->addConfigComponent('orchestra/tenanti', 'orchestra/tenanti', "{$path}/config"); if (! $this->hasPackageRepository()) { $this->bootUsingLaravel($path); } }
php
public function boot() { $path = \realpath(__DIR__.'/../'); $this->addConfigComponent('orchestra/tenanti', 'orchestra/tenanti', "{$path}/config"); if (! $this->hasPackageRepository()) { $this->bootUsingLaravel($path); } }
[ "public", "function", "boot", "(", ")", "{", "$", "path", "=", "\\", "realpath", "(", "__DIR__", ".", "'/../'", ")", ";", "$", "this", "->", "addConfigComponent", "(", "'orchestra/tenanti'", ",", "'orchestra/tenanti'", ",", "\"{$path}/config\"", ")", ";", "i...
Boot the service provider. @return void
[ "Boot", "the", "service", "provider", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiServiceProvider.php#L50-L59
orchestral/tenanti
src/Eloquent/Model.php
Model.fillFromExistingOrNew
public function fillFromExistingOrNew(array $attributes = []) { $this->fill($attributes); $this->exists = ! empty($attributes[$this->getKeyName()]); return $this; }
php
public function fillFromExistingOrNew(array $attributes = []) { $this->fill($attributes); $this->exists = ! empty($attributes[$this->getKeyName()]); return $this; }
[ "public", "function", "fillFromExistingOrNew", "(", "array", "$", "attributes", "=", "[", "]", ")", "{", "$", "this", "->", "fill", "(", "$", "attributes", ")", ";", "$", "this", "->", "exists", "=", "!", "empty", "(", "$", "attributes", "[", "$", "t...
Create model instance from existing. @param array $attributes @return $this
[ "Create", "model", "instance", "from", "existing", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Eloquent/Model.php#L25-L32
orchestral/tenanti
src/Eloquent/Model.php
Model.newEloquentBuilder
public function newEloquentBuilder($query) { return \tap(new Builder($query), function ($builder) { $builder->setTenantor($this->tenantor ?? null); }); }
php
public function newEloquentBuilder($query) { return \tap(new Builder($query), function ($builder) { $builder->setTenantor($this->tenantor ?? null); }); }
[ "public", "function", "newEloquentBuilder", "(", "$", "query", ")", "{", "return", "\\", "tap", "(", "new", "Builder", "(", "$", "query", ")", ",", "function", "(", "$", "builder", ")", "{", "$", "builder", "->", "setTenantor", "(", "$", "this", "->", ...
Create a new Eloquent query builder for the model. @param \Illuminate\Database\Query\Builder $query @return \Orchestra\Tenanti\Eloquent\Builder
[ "Create", "a", "new", "Eloquent", "query", "builder", "for", "the", "model", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Eloquent/Model.php#L41-L46
orchestral/tenanti
src/Eloquent/Model.php
Model.newInstance
public function newInstance($attributes = [], $exists = false) { return \tap(parent::newInstance($attributes, $exists), function ($model) { $model->setTenantor($this->tenantor ?? null); }); }
php
public function newInstance($attributes = [], $exists = false) { return \tap(parent::newInstance($attributes, $exists), function ($model) { $model->setTenantor($this->tenantor ?? null); }); }
[ "public", "function", "newInstance", "(", "$", "attributes", "=", "[", "]", ",", "$", "exists", "=", "false", ")", "{", "return", "\\", "tap", "(", "parent", "::", "newInstance", "(", "$", "attributes", ",", "$", "exists", ")", ",", "function", "(", ...
Create a new instance of the given model. @param array $attributes @param bool $exists @return static
[ "Create", "a", "new", "instance", "of", "the", "given", "model", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Eloquent/Model.php#L56-L61
orchestral/tenanti
src/Jobs/Job.php
Job.shouldBeFailed
protected function shouldBeFailed(): bool { if ($this->attempts() > 3 && $this->job) { $this->fail(null); return true; } return false; }
php
protected function shouldBeFailed(): bool { if ($this->attempts() > 3 && $this->job) { $this->fail(null); return true; } return false; }
[ "protected", "function", "shouldBeFailed", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "attempts", "(", ")", ">", "3", "&&", "$", "this", "->", "job", ")", "{", "$", "this", "->", "fail", "(", "null", ")", ";", "return", "true", ";"...
Should the job be failed. @return bool
[ "Should", "the", "job", "be", "failed", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Jobs/Job.php#L45-L54
orchestral/tenanti
src/Jobs/Job.php
Job.shouldBeDelayed
protected function shouldBeDelayed(): bool { if ($this->job && \is_null($this->model)) { $this->release(10); return true; } return false; }
php
protected function shouldBeDelayed(): bool { if ($this->job && \is_null($this->model)) { $this->release(10); return true; } return false; }
[ "protected", "function", "shouldBeDelayed", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "job", "&&", "\\", "is_null", "(", "$", "this", "->", "model", ")", ")", "{", "$", "this", "->", "release", "(", "10", ")", ";", "return", "true",...
Should the job be delayed. @return bool
[ "Should", "the", "job", "be", "delayed", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Jobs/Job.php#L61-L70
orchestral/tenanti
src/Console/QueuedCommand.php
QueuedCommand.handle
public function handle(Kernel $kernel) { if (! $this->confirmToProceed()) { return; } $driver = $this->getDriver(); $action = $this->argument('action'); $database = $this->option('database'); $queue = $this->option('queue') ?? $this->tenant->config()['queue'] ?? 'default'; $delay = $this->option('delay'); if (! \in_array($action, $this->actions)) { throw new InvalidArgumentException("Action [{$action}] is not available for this command."); } $command = "tenanti:{$action}"; $parameters = ['driver' => $driver, '--database' => $database, '--force' => true]; $this->tenant->driver($driver) ->executeForEach(function ($entity) use ($kernel, $command, $parameters, $queue, $delay) { $job = $kernel->queue( $command, \array_merge($parameters, ['--id' => $entity->getKey()]) )->onQueue($queue); if ($delay > 0) { $job->delay($delay); } }); }
php
public function handle(Kernel $kernel) { if (! $this->confirmToProceed()) { return; } $driver = $this->getDriver(); $action = $this->argument('action'); $database = $this->option('database'); $queue = $this->option('queue') ?? $this->tenant->config()['queue'] ?? 'default'; $delay = $this->option('delay'); if (! \in_array($action, $this->actions)) { throw new InvalidArgumentException("Action [{$action}] is not available for this command."); } $command = "tenanti:{$action}"; $parameters = ['driver' => $driver, '--database' => $database, '--force' => true]; $this->tenant->driver($driver) ->executeForEach(function ($entity) use ($kernel, $command, $parameters, $queue, $delay) { $job = $kernel->queue( $command, \array_merge($parameters, ['--id' => $entity->getKey()]) )->onQueue($queue); if ($delay > 0) { $job->delay($delay); } }); }
[ "public", "function", "handle", "(", "Kernel", "$", "kernel", ")", "{", "if", "(", "!", "$", "this", "->", "confirmToProceed", "(", ")", ")", "{", "return", ";", "}", "$", "driver", "=", "$", "this", "->", "getDriver", "(", ")", ";", "$", "action",...
Execute the console command. @param \Illuminate\Contracts\Console\Kernel $kernel @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/QueuedCommand.php#L43-L72
orchestral/tenanti
src/Migrator/Factory.php
Factory.install
public function install(?string $database, $id = null): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database) { $this->runInstall($entity, $database); }); return; } $this->executeForEach(function ($entity) use ($database) { $this->runInstall($entity, $database); }); }
php
public function install(?string $database, $id = null): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database) { $this->runInstall($entity, $database); }); return; } $this->executeForEach(function ($entity) use ($database) { $this->runInstall($entity, $database); }); }
[ "public", "function", "install", "(", "?", "string", "$", "database", ",", "$", "id", "=", "null", ")", ":", "void", "{", "if", "(", "!", "\\", "is_null", "(", "$", "id", ")", ")", "{", "$", "this", "->", "executeFor", "(", "$", "id", ",", "fun...
Install migrations. @param string|null $database @param mixed|null $id @return void
[ "Install", "migrations", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Factory.php#L36-L49
orchestral/tenanti
src/Migrator/Factory.php
Factory.run
public function run(?string $database, $id = null, bool $pretend = false): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database, $pretend) { $this->runUp($entity, $database, $pretend); }); return; } $this->executeForEach(function ($entity) use ($database, $pretend) { $this->runUp($entity, $database, $pretend); }); }
php
public function run(?string $database, $id = null, bool $pretend = false): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database, $pretend) { $this->runUp($entity, $database, $pretend); }); return; } $this->executeForEach(function ($entity) use ($database, $pretend) { $this->runUp($entity, $database, $pretend); }); }
[ "public", "function", "run", "(", "?", "string", "$", "database", ",", "$", "id", "=", "null", ",", "bool", "$", "pretend", "=", "false", ")", ":", "void", "{", "if", "(", "!", "\\", "is_null", "(", "$", "id", ")", ")", "{", "$", "this", "->", ...
Run migrations. @param string|null $database @param mixed|null $id @param bool $pretend @return void
[ "Run", "migrations", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Factory.php#L60-L73
orchestral/tenanti
src/Migrator/Factory.php
Factory.rollback
public function rollback(?string $database, $id = null, bool $pretend = false): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database, $pretend) { $this->runDown($entity, $database, $pretend); }); return; } $this->executeForEach(function ($entity) use ($database, $pretend) { $this->runDown($entity, $database, $pretend); }); }
php
public function rollback(?string $database, $id = null, bool $pretend = false): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database, $pretend) { $this->runDown($entity, $database, $pretend); }); return; } $this->executeForEach(function ($entity) use ($database, $pretend) { $this->runDown($entity, $database, $pretend); }); }
[ "public", "function", "rollback", "(", "?", "string", "$", "database", ",", "$", "id", "=", "null", ",", "bool", "$", "pretend", "=", "false", ")", ":", "void", "{", "if", "(", "!", "\\", "is_null", "(", "$", "id", ")", ")", "{", "$", "this", "...
Rollback migrations. @param string|null $database @param mixed|null $id @param bool $pretend @return void
[ "Rollback", "migrations", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Factory.php#L84-L97
orchestral/tenanti
src/Migrator/Factory.php
Factory.reset
public function reset(?string $database, $id = null, bool $pretend = false): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database, $pretend) { $this->runReset($entity, $database, $pretend); }); return; } $this->executeForEach(function ($entity) use ($database, $pretend) { $this->runReset($entity, $database, $pretend); }); }
php
public function reset(?string $database, $id = null, bool $pretend = false): void { if (! \is_null($id)) { $this->executeFor($id, function ($entity) use ($database, $pretend) { $this->runReset($entity, $database, $pretend); }); return; } $this->executeForEach(function ($entity) use ($database, $pretend) { $this->runReset($entity, $database, $pretend); }); }
[ "public", "function", "reset", "(", "?", "string", "$", "database", ",", "$", "id", "=", "null", ",", "bool", "$", "pretend", "=", "false", ")", ":", "void", "{", "if", "(", "!", "\\", "is_null", "(", "$", "id", ")", ")", "{", "$", "this", "->"...
Reset migrations. @param string|null $database @param mixed|null $id @param bool $pretend @return void
[ "Reset", "migrations", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Factory.php#L108-L121
orchestral/tenanti
src/Migrator/Factory.php
Factory.runInstall
public function runInstall(Model $entity, ?string $database): void { $database = $this->asConnection($entity, $database); $table = $this->resolveMigrationTableName($entity); $migrator = $this->resolveMigrator($table); $repository = $migrator->getRepository(); $migrator->setConnection($database); if (! $repository->repositoryExists()) { $repository->createRepository(); $this->note("<info>Migration table {$table} created successfully.</info>"); } $migrator->resetConnection(); }
php
public function runInstall(Model $entity, ?string $database): void { $database = $this->asConnection($entity, $database); $table = $this->resolveMigrationTableName($entity); $migrator = $this->resolveMigrator($table); $repository = $migrator->getRepository(); $migrator->setConnection($database); if (! $repository->repositoryExists()) { $repository->createRepository(); $this->note("<info>Migration table {$table} created successfully.</info>"); } $migrator->resetConnection(); }
[ "public", "function", "runInstall", "(", "Model", "$", "entity", ",", "?", "string", "$", "database", ")", ":", "void", "{", "$", "database", "=", "$", "this", "->", "asConnection", "(", "$", "entity", ",", "$", "database", ")", ";", "$", "table", "=...
Run migration up on a single entity. @param \Illuminate\Database\Eloquent\Model $entity @param string|null $database @return void
[ "Run", "migration", "up", "on", "a", "single", "entity", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Factory.php#L131-L147
orchestral/tenanti
src/Migrator/Factory.php
Factory.runUp
public function runUp(Model $entity, ?string $database, bool $pretend = false): void { $database = $this->asConnection($entity, $database); $table = $this->resolveMigrationTableName($entity); $migrator = $this->resolveMigratorWithNotes($table); $migrator->setConnection($database); $migrator->setEntity($entity); $migrator->run($this->getMigrationPaths($entity), ['pretend' => (bool) $pretend]); $migrator->resetConnection(); }
php
public function runUp(Model $entity, ?string $database, bool $pretend = false): void { $database = $this->asConnection($entity, $database); $table = $this->resolveMigrationTableName($entity); $migrator = $this->resolveMigratorWithNotes($table); $migrator->setConnection($database); $migrator->setEntity($entity); $migrator->run($this->getMigrationPaths($entity), ['pretend' => (bool) $pretend]); $migrator->resetConnection(); }
[ "public", "function", "runUp", "(", "Model", "$", "entity", ",", "?", "string", "$", "database", ",", "bool", "$", "pretend", "=", "false", ")", ":", "void", "{", "$", "database", "=", "$", "this", "->", "asConnection", "(", "$", "entity", ",", "$", ...
Run migration up on a single entity. @param \Illuminate\Database\Eloquent\Model $entity @param string|null $database @param bool $pretend @return void
[ "Run", "migration", "up", "on", "a", "single", "entity", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Factory.php#L158-L169
orchestral/tenanti
src/Console/InstallCommand.php
InstallCommand.handle
public function handle() { \tap($this->tenant->driver($this->getDriver()), function ($migrator) { $this->setupMigrationOutput($migrator); $migrator->install( $this->option('database'), $this->option('id') ); }); }
php
public function handle() { \tap($this->tenant->driver($this->getDriver()), function ($migrator) { $this->setupMigrationOutput($migrator); $migrator->install( $this->option('database'), $this->option('id') ); }); }
[ "public", "function", "handle", "(", ")", "{", "\\", "tap", "(", "$", "this", "->", "tenant", "->", "driver", "(", "$", "this", "->", "getDriver", "(", ")", ")", ",", "function", "(", "$", "migrator", ")", "{", "$", "this", "->", "setupMigrationOutpu...
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/InstallCommand.php#L28-L37
orchestral/tenanti
src/TenantiManager.php
TenantiManager.createDriver
protected function createDriver($driver): Contracts\Factory { if (\is_null($this->setupDriverConfig($driver))) { throw new InvalidArgumentException("Driver [$driver] not supported."); } return new $this->resolver($this->app, $this, $driver); }
php
protected function createDriver($driver): Contracts\Factory { if (\is_null($this->setupDriverConfig($driver))) { throw new InvalidArgumentException("Driver [$driver] not supported."); } return new $this->resolver($this->app, $this, $driver); }
[ "protected", "function", "createDriver", "(", "$", "driver", ")", ":", "Contracts", "\\", "Factory", "{", "if", "(", "\\", "is_null", "(", "$", "this", "->", "setupDriverConfig", "(", "$", "driver", ")", ")", ")", "{", "throw", "new", "InvalidArgumentExcep...
Create a new driver instance. @param string $driver @throws \InvalidArgumentException @return \Orchestra\Tenanti\Contracts\Factory
[ "Create", "a", "new", "driver", "instance", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiManager.php#L36-L43
orchestral/tenanti
src/TenantiManager.php
TenantiManager.getConfig
public function getConfig(?string $group = null, $default = null) { return Arr::get($this->config, $group, $default); }
php
public function getConfig(?string $group = null, $default = null) { return Arr::get($this->config, $group, $default); }
[ "public", "function", "getConfig", "(", "?", "string", "$", "group", "=", "null", ",", "$", "default", "=", "null", ")", "{", "return", "Arr", "::", "get", "(", "$", "this", "->", "config", ",", "$", "group", ",", "$", "default", ")", ";", "}" ]
Get configuration values. @param string|null $group @param mixed $default @return mixed
[ "Get", "configuration", "values", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiManager.php#L73-L76
orchestral/tenanti
src/TenantiManager.php
TenantiManager.connection
public function connection(?string $using, Closure $callback, array $options = []): void { $repository = $this->app->make('config'); if (\is_null($using)) { $using = $repository->get('database.default'); } $config = $repository->get("database.connections.{$using}", null); if (\is_null($config)) { throw new InvalidArgumentException("Database connection [{$using}] is not available."); } Arr::set($this->config, 'connection', [ 'name' => "{$using}_{id}", 'template' => $config, 'resolver' => $callback, 'options' => $options, ]); }
php
public function connection(?string $using, Closure $callback, array $options = []): void { $repository = $this->app->make('config'); if (\is_null($using)) { $using = $repository->get('database.default'); } $config = $repository->get("database.connections.{$using}", null); if (\is_null($config)) { throw new InvalidArgumentException("Database connection [{$using}] is not available."); } Arr::set($this->config, 'connection', [ 'name' => "{$using}_{id}", 'template' => $config, 'resolver' => $callback, 'options' => $options, ]); }
[ "public", "function", "connection", "(", "?", "string", "$", "using", ",", "Closure", "$", "callback", ",", "array", "$", "options", "=", "[", "]", ")", ":", "void", "{", "$", "repository", "=", "$", "this", "->", "app", "->", "make", "(", "'config'"...
Setup multiple database connection from template. @param string|null $using @param \Closure $callback @param array $option @throws \InvalidArgumentException @return void
[ "Setup", "multiple", "database", "connection", "from", "template", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiManager.php#L103-L123
orchestral/tenanti
src/TenantiManager.php
TenantiManager.setupDriverConfig
protected function setupDriverConfig(string $driver): ?array { if (isset($this->config[$driver])) { return null; } if (\is_null($config = Arr::pull($this->config, "drivers.{$driver}"))) { return null; } $connection = $this->config['connection'] ?? null; if (! \is_null($connection) && $this->driverExcludedByOptions($driver, $connection['options'])) { $connection = null; } return $this->config[$driver] = \array_merge($config, ['connection' => $connection]); }
php
protected function setupDriverConfig(string $driver): ?array { if (isset($this->config[$driver])) { return null; } if (\is_null($config = Arr::pull($this->config, "drivers.{$driver}"))) { return null; } $connection = $this->config['connection'] ?? null; if (! \is_null($connection) && $this->driverExcludedByOptions($driver, $connection['options'])) { $connection = null; } return $this->config[$driver] = \array_merge($config, ['connection' => $connection]); }
[ "protected", "function", "setupDriverConfig", "(", "string", "$", "driver", ")", ":", "?", "array", "{", "if", "(", "isset", "(", "$", "this", "->", "config", "[", "$", "driver", "]", ")", ")", "{", "return", "null", ";", "}", "if", "(", "\\", "is_...
Prepare configuration values. @param string $driver @return array|null
[ "Prepare", "configuration", "values", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiManager.php#L132-L149
orchestral/tenanti
src/TenantiManager.php
TenantiManager.driverExcludedByOptions
protected function driverExcludedByOptions(string $driver, array $options): bool { return (! empty($options['only']) && ! \in_array($driver, (array) $options['only'])) || (! empty($options['except']) && \in_array($driver, (array) $options['except'])); }
php
protected function driverExcludedByOptions(string $driver, array $options): bool { return (! empty($options['only']) && ! \in_array($driver, (array) $options['only'])) || (! empty($options['except']) && \in_array($driver, (array) $options['except'])); }
[ "protected", "function", "driverExcludedByOptions", "(", "string", "$", "driver", ",", "array", "$", "options", ")", ":", "bool", "{", "return", "(", "!", "empty", "(", "$", "options", "[", "'only'", "]", ")", "&&", "!", "\\", "in_array", "(", "$", "dr...
Determine if the given options exclude a particular driver. @param string $driver @param array $options @return bool
[ "Determine", "if", "the", "given", "options", "exclude", "a", "particular", "driver", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/TenantiManager.php#L159-L163
orchestral/tenanti
src/Notice/Command.php
Command.send
protected function send(array $notes): void { foreach ($notes as $note) { $this->output->writeln($note); } }
php
protected function send(array $notes): void { foreach ($notes as $note) { $this->output->writeln($note); } }
[ "protected", "function", "send", "(", "array", "$", "notes", ")", ":", "void", "{", "foreach", "(", "$", "notes", "as", "$", "note", ")", "{", "$", "this", "->", "output", "->", "writeln", "(", "$", "note", ")", ";", "}", "}" ]
Send output of notes. @param array $notes @return void
[ "Send", "output", "of", "notes", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Notice/Command.php#L59-L64
orchestral/tenanti
src/Migrator/Migrator.php
Migrator.setConnection
public function setConnection($name) { if (! \is_null($name)) { $this->defaultConnection = $this->resolver->getDefaultConnection(); } parent::setConnection($name); }
php
public function setConnection($name) { if (! \is_null($name)) { $this->defaultConnection = $this->resolver->getDefaultConnection(); } parent::setConnection($name); }
[ "public", "function", "setConnection", "(", "$", "name", ")", "{", "if", "(", "!", "\\", "is_null", "(", "$", "name", ")", ")", "{", "$", "this", "->", "defaultConnection", "=", "$", "this", "->", "resolver", "->", "getDefaultConnection", "(", ")", ";"...
Set the default connection name. @param string|null $name @return void
[ "Set", "the", "default", "connection", "name", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Migrator.php#L46-L53
orchestral/tenanti
src/Migrator/Migrator.php
Migrator.resetConnection
public function resetConnection(): void { if (! \is_null($this->defaultConnection)) { $this->resolver->connection($this->connection)->disconnect(); $this->setConnection($this->defaultConnection); } }
php
public function resetConnection(): void { if (! \is_null($this->defaultConnection)) { $this->resolver->connection($this->connection)->disconnect(); $this->setConnection($this->defaultConnection); } }
[ "public", "function", "resetConnection", "(", ")", ":", "void", "{", "if", "(", "!", "\\", "is_null", "(", "$", "this", "->", "defaultConnection", ")", ")", "{", "$", "this", "->", "resolver", "->", "connection", "(", "$", "this", "->", "connection", "...
Reset the default connection name. @return void
[ "Reset", "the", "default", "connection", "name", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Migrator.php#L60-L67
orchestral/tenanti
src/Migrator/Migrator.php
Migrator.runUp
protected function runUp($file, $batch, $pretend) { $file = $this->getMigrationName($file); // First we will resolve a "real" instance of the migration class from this // migration file name. Once we have the instances we can run the actual // command such as "up" or "down", or we can just simulate the action. $migration = $this->resolve($file); if ($pretend) { $this->pretendToRun($migration, 'up'); return; } $migration->up($key = $this->entity->getKey(), $this->entity); // Once we have run a migrations class, we will log that it was run in this // repository so that we don't try to run it next time we do a migration // in the application. A migration repository keeps the migrate order. $this->repository->log($file, $batch); $this->note("<info>Migrated [{$this->entity->getTable()}:{$key}]:</info> {$file}"); }
php
protected function runUp($file, $batch, $pretend) { $file = $this->getMigrationName($file); // First we will resolve a "real" instance of the migration class from this // migration file name. Once we have the instances we can run the actual // command such as "up" or "down", or we can just simulate the action. $migration = $this->resolve($file); if ($pretend) { $this->pretendToRun($migration, 'up'); return; } $migration->up($key = $this->entity->getKey(), $this->entity); // Once we have run a migrations class, we will log that it was run in this // repository so that we don't try to run it next time we do a migration // in the application. A migration repository keeps the migrate order. $this->repository->log($file, $batch); $this->note("<info>Migrated [{$this->entity->getTable()}:{$key}]:</info> {$file}"); }
[ "protected", "function", "runUp", "(", "$", "file", ",", "$", "batch", ",", "$", "pretend", ")", "{", "$", "file", "=", "$", "this", "->", "getMigrationName", "(", "$", "file", ")", ";", "// First we will resolve a \"real\" instance of the migration class from thi...
Run "up" a migration instance. @param string $file @param int $batch @param bool $pretend @return void
[ "Run", "up", "a", "migration", "instance", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Migrator.php#L96-L119
orchestral/tenanti
src/Migrator/Migrator.php
Migrator.runDown
protected function runDown($file, $migration, $pretend) { $file = $this->getMigrationName($file); // First we will get the file name of the migration so we can resolve out an // instance of the migration. Once we get an instance we can either run a // pretend execution of the migration or we can run the real migration. $instance = $this->resolve($file); if ($pretend) { return $this->pretendToRun($instance, 'down'); } $instance->down($key = $this->entity->getKey(), $this->entity); // Once we have successfully run the migration "down" we will remove it from // the migration repository so it will be considered to have not been run // by the application then will be able to fire by any later operation. $this->repository->delete($migration); $this->note("<info>Rolled back [{$this->entity->getTable()}:{$key}]:</info> {$file}"); }
php
protected function runDown($file, $migration, $pretend) { $file = $this->getMigrationName($file); // First we will get the file name of the migration so we can resolve out an // instance of the migration. Once we get an instance we can either run a // pretend execution of the migration or we can run the real migration. $instance = $this->resolve($file); if ($pretend) { return $this->pretendToRun($instance, 'down'); } $instance->down($key = $this->entity->getKey(), $this->entity); // Once we have successfully run the migration "down" we will remove it from // the migration repository so it will be considered to have not been run // by the application then will be able to fire by any later operation. $this->repository->delete($migration); $this->note("<info>Rolled back [{$this->entity->getTable()}:{$key}]:</info> {$file}"); }
[ "protected", "function", "runDown", "(", "$", "file", ",", "$", "migration", ",", "$", "pretend", ")", "{", "$", "file", "=", "$", "this", "->", "getMigrationName", "(", "$", "file", ")", ";", "// First we will get the file name of the migration so we can resolve ...
Run "down" a migration instance. @param string $file @param object $migration @param bool $pretend @return void
[ "Run", "down", "a", "migration", "instance", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Migrator.php#L130-L151
orchestral/tenanti
src/Migrator/Migrator.php
Migrator.pretendToRun
protected function pretendToRun($migration, $method) { $table = $this->entity->getTable(); $key = $this->entity->getKey(); foreach ($this->getQueries($migration, $method) as $query) { $name = \get_class($migration); $this->note("<info>{$name} [{$table}:{$key}]:</info> {$query['query']}"); } }
php
protected function pretendToRun($migration, $method) { $table = $this->entity->getTable(); $key = $this->entity->getKey(); foreach ($this->getQueries($migration, $method) as $query) { $name = \get_class($migration); $this->note("<info>{$name} [{$table}:{$key}]:</info> {$query['query']}"); } }
[ "protected", "function", "pretendToRun", "(", "$", "migration", ",", "$", "method", ")", "{", "$", "table", "=", "$", "this", "->", "entity", "->", "getTable", "(", ")", ";", "$", "key", "=", "$", "this", "->", "entity", "->", "getKey", "(", ")", "...
Pretend to run the migrations. @param object $migration @param string $method @return void
[ "Pretend", "to", "run", "the", "migrations", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Migrator.php#L161-L171
orchestral/tenanti
src/Migrator/Migrator.php
Migrator.getQueries
protected function getQueries($migration, $method) { $connection = $migration->getConnection(); // Now that we have the connections we can resolve it and pretend to run the // queries against the database returning the array of raw SQL statements // that would get fired against the database system for this migration. $db = $this->resolveConnection($connection); return $db->pretend(function () use ($migration, $method) { \call_user_func([$migration, $method], $this->entity->getKey(), $this->entity); }); }
php
protected function getQueries($migration, $method) { $connection = $migration->getConnection(); // Now that we have the connections we can resolve it and pretend to run the // queries against the database returning the array of raw SQL statements // that would get fired against the database system for this migration. $db = $this->resolveConnection($connection); return $db->pretend(function () use ($migration, $method) { \call_user_func([$migration, $method], $this->entity->getKey(), $this->entity); }); }
[ "protected", "function", "getQueries", "(", "$", "migration", ",", "$", "method", ")", "{", "$", "connection", "=", "$", "migration", "->", "getConnection", "(", ")", ";", "// Now that we have the connections we can resolve it and pretend to run the", "// queries against ...
Get all of the queries that would be run for a migration. @param object $migration @param string $method @return array
[ "Get", "all", "of", "the", "queries", "that", "would", "be", "run", "for", "a", "migration", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Migrator/Migrator.php#L181-L193
orchestral/tenanti
src/Console/RefreshCommand.php
RefreshCommand.handle
public function handle() { if (! $this->confirmToProceed()) { return; } $parameters = [ 'driver' => $this->getDriver(), '--database' => $this->option('database'), '--force' => true, '--id' => $this->option('id'), ]; $this->call('tenanti:reset', $parameters); // The refresh command is essentially just a brief aggregate of a few other of // the migration commands and just provides a convenient wrapper to execute // them in succession. We'll also see if we need to re-seed the database. $this->call('tenanti:migrate', $parameters); }
php
public function handle() { if (! $this->confirmToProceed()) { return; } $parameters = [ 'driver' => $this->getDriver(), '--database' => $this->option('database'), '--force' => true, '--id' => $this->option('id'), ]; $this->call('tenanti:reset', $parameters); // The refresh command is essentially just a brief aggregate of a few other of // the migration commands and just provides a convenient wrapper to execute // them in succession. We'll also see if we need to re-seed the database. $this->call('tenanti:migrate', $parameters); }
[ "public", "function", "handle", "(", ")", "{", "if", "(", "!", "$", "this", "->", "confirmToProceed", "(", ")", ")", "{", "return", ";", "}", "$", "parameters", "=", "[", "'driver'", "=>", "$", "this", "->", "getDriver", "(", ")", ",", "'--database'"...
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/orchestral/tenanti/blob/e6f271496547fd56d23bd5ea777be6c93a68a54b/src/Console/RefreshCommand.php#L30-L49
1up-lab/OneupUploaderBundle
Uploader/Naming/UrlSafeNamer.php
UrlSafeNamer.name
public function name(FileInterface $file) { $bytes = random_bytes(256 / 8); return rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=').'.'.$file->getExtension(); }
php
public function name(FileInterface $file) { $bytes = random_bytes(256 / 8); return rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=').'.'.$file->getExtension(); }
[ "public", "function", "name", "(", "FileInterface", "$", "file", ")", "{", "$", "bytes", "=", "random_bytes", "(", "256", "/", "8", ")", ";", "return", "rtrim", "(", "strtr", "(", "base64_encode", "(", "$", "bytes", ")", ",", "'+/'", ",", "'-_'", ")"...
Name a given file and return the name. @param FileInterface $file @return string
[ "Name", "a", "given", "file", "and", "return", "the", "name", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Uploader/Naming/UrlSafeNamer.php#L16-L21
1up-lab/OneupUploaderBundle
Controller/AbstractChunkedController.php
AbstractChunkedController.handleChunkedUpload
protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $response, Request $request) { // get basic container stuff $chunkManager = $this->container->get('oneup_uploader.chunk_manager'); // get information about this chunked request [$last, $uuid, $index, $orig] = $this->parseChunkedRequest($request); $chunk = $chunkManager->addChunk($uuid, $index, $file, $orig); if (null !== $chunk) { $this->dispatchChunkEvents($chunk, $response, $request, $last); } if ($chunkManager->getLoadDistribution()) { $chunks = $chunkManager->getChunks($uuid); $assembled = $chunkManager->assembleChunks($chunks, true, $last); if (null === $chunk) { $this->dispatchChunkEvents($assembled, $response, $request, $last); } } // if all chunks collected and stored, proceed // with reassembling the parts if ($last) { if (!$chunkManager->getLoadDistribution()) { $chunks = $chunkManager->getChunks($uuid); $assembled = $chunkManager->assembleChunks($chunks, true, true); } $path = $assembled->getPath(); $this->handleUpload($assembled, $response, $request); $chunkManager->cleanup($path); } }
php
protected function handleChunkedUpload(UploadedFile $file, ResponseInterface $response, Request $request) { // get basic container stuff $chunkManager = $this->container->get('oneup_uploader.chunk_manager'); // get information about this chunked request [$last, $uuid, $index, $orig] = $this->parseChunkedRequest($request); $chunk = $chunkManager->addChunk($uuid, $index, $file, $orig); if (null !== $chunk) { $this->dispatchChunkEvents($chunk, $response, $request, $last); } if ($chunkManager->getLoadDistribution()) { $chunks = $chunkManager->getChunks($uuid); $assembled = $chunkManager->assembleChunks($chunks, true, $last); if (null === $chunk) { $this->dispatchChunkEvents($assembled, $response, $request, $last); } } // if all chunks collected and stored, proceed // with reassembling the parts if ($last) { if (!$chunkManager->getLoadDistribution()) { $chunks = $chunkManager->getChunks($uuid); $assembled = $chunkManager->assembleChunks($chunks, true, true); } $path = $assembled->getPath(); $this->handleUpload($assembled, $response, $request); $chunkManager->cleanup($path); } }
[ "protected", "function", "handleChunkedUpload", "(", "UploadedFile", "$", "file", ",", "ResponseInterface", "$", "response", ",", "Request", "$", "request", ")", "{", "// get basic container stuff", "$", "chunkManager", "=", "$", "this", "->", "container", "->", "...
This function will be called in order to upload and save an uploaded chunk. This function also calls the chunk manager if the function parseChunkedRequest has set true for the "last" key of the returned array to reassemble the uploaded chunks. @param UploadedFile $file - The uploaded chunk @param responseInterface $response - A response object @param Request $request - The request object
[ "This", "function", "will", "be", "called", "in", "order", "to", "upload", "and", "save", "an", "uploaded", "chunk", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractChunkedController.php#L44-L81
1up-lab/OneupUploaderBundle
Controller/AbstractChunkedController.php
AbstractChunkedController.dispatchChunkEvents
protected function dispatchChunkEvents($uploaded, ResponseInterface $response, Request $request, $isLast) { $dispatcher = $this->container->get('event_dispatcher'); // dispatch post upload event (both the specific and the general) $postUploadEvent = new PostChunkUploadEvent($uploaded, $response, $request, $isLast, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_CHUNK_UPLOAD, $postUploadEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_CHUNK_UPLOAD, $this->type), $postUploadEvent); }
php
protected function dispatchChunkEvents($uploaded, ResponseInterface $response, Request $request, $isLast) { $dispatcher = $this->container->get('event_dispatcher'); // dispatch post upload event (both the specific and the general) $postUploadEvent = new PostChunkUploadEvent($uploaded, $response, $request, $isLast, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_CHUNK_UPLOAD, $postUploadEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_CHUNK_UPLOAD, $this->type), $postUploadEvent); }
[ "protected", "function", "dispatchChunkEvents", "(", "$", "uploaded", ",", "ResponseInterface", "$", "response", ",", "Request", "$", "request", ",", "$", "isLast", ")", "{", "$", "dispatcher", "=", "$", "this", "->", "container", "->", "get", "(", "'event_d...
This function is a helper function which dispatches post chunk upload event. @param mixed $uploaded - The uploaded chunk @param responseInterface $response - A response object @param Request $request - The request object @param bool $isLast - True if this is the last chunk, false otherwise
[ "This", "function", "is", "a", "helper", "function", "which", "dispatches", "post", "chunk", "upload", "event", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractChunkedController.php#L91-L99
1up-lab/OneupUploaderBundle
Uploader/Response/AbstractResponse.php
AbstractResponse.addToOffset
public function addToOffset($value, array $offsets) { $element = &$this->data; foreach ($offsets as $offset) { if (isset($element[$offset])) { if (is_array($element[$offset])) { $element = &$element[$offset]; } else { throw new \InvalidArgumentException('The specified offset is set but is not an array at'.$offset); } } else { $element[$offset] = []; $element = &$element[$offset]; } } $element[] = $value; }
php
public function addToOffset($value, array $offsets) { $element = &$this->data; foreach ($offsets as $offset) { if (isset($element[$offset])) { if (is_array($element[$offset])) { $element = &$element[$offset]; } else { throw new \InvalidArgumentException('The specified offset is set but is not an array at'.$offset); } } else { $element[$offset] = []; $element = &$element[$offset]; } } $element[] = $value; }
[ "public", "function", "addToOffset", "(", "$", "value", ",", "array", "$", "offsets", ")", "{", "$", "element", "=", "&", "$", "this", "->", "data", ";", "foreach", "(", "$", "offsets", "as", "$", "offset", ")", "{", "if", "(", "isset", "(", "$", ...
The \ArrayAccess interface does not support multi-dimensional array syntax such as $array["foo"][] = bar This function will take a path of arrays and add a new element to it, creating the path if needed. @param mixed $value @param array $offsets @throws \InvalidArgumentException if the path contains non-array items
[ "The", "\\", "ArrayAccess", "interface", "does", "not", "support", "multi", "-", "dimensional", "array", "syntax", "such", "as", "$array", "[", "foo", "]", "[]", "=", "bar", "This", "function", "will", "take", "a", "path", "of", "arrays", "and", "add", "...
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Uploader/Response/AbstractResponse.php#L43-L59
1up-lab/OneupUploaderBundle
Uploader/File/GaufretteFile.php
GaufretteFile.getSize
public function getSize() { // This can only work on streamable files, so basically local files, // still only perform it once even on local files to avoid bothering the filesystem.php g if ($this->filesystem->getAdapter() instanceof StreamFactory && !$this->size) { if ($this->streamWrapperPrefix) { try { $this->setSize(filesize($this->streamWrapperPrefix.$this->getKey())); } catch (\Exception $e) { // Fail gracefully if there was a problem with opening the file and // let gaufrette load the file into memory allowing it to throw exceptions // if that doesn't work either. // Not empty to make the scrutiziner happy. return parent::getSize(); } } } return parent::getSize(); }
php
public function getSize() { // This can only work on streamable files, so basically local files, // still only perform it once even on local files to avoid bothering the filesystem.php g if ($this->filesystem->getAdapter() instanceof StreamFactory && !$this->size) { if ($this->streamWrapperPrefix) { try { $this->setSize(filesize($this->streamWrapperPrefix.$this->getKey())); } catch (\Exception $e) { // Fail gracefully if there was a problem with opening the file and // let gaufrette load the file into memory allowing it to throw exceptions // if that doesn't work either. // Not empty to make the scrutiziner happy. return parent::getSize(); } } } return parent::getSize(); }
[ "public", "function", "getSize", "(", ")", "{", "// This can only work on streamable files, so basically local files,", "// still only perform it once even on local files to avoid bothering the filesystem.php g", "if", "(", "$", "this", "->", "filesystem", "->", "getAdapter", "(", ...
Returns the size of the file. !! WARNING !! Calling this loads the entire file into memory, unless it is on a stream-capable filesystem. In case of bigger files this could throw exceptions, and will have heavy performance footprint. !! ------- !!
[ "Returns", "the", "size", "of", "the", "file", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Uploader/File/GaufretteFile.php#L45-L64
1up-lab/OneupUploaderBundle
Controller/AbstractController.php
AbstractController.getFiles
protected function getFiles(FileBag $bag) { $files = []; $fileBag = $bag->all(); $fileIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($fileBag), \RecursiveIteratorIterator::SELF_FIRST); foreach ($fileIterator as $file) { if (is_array($file) || null === $file) { continue; } $files[] = $file; } return $files; }
php
protected function getFiles(FileBag $bag) { $files = []; $fileBag = $bag->all(); $fileIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($fileBag), \RecursiveIteratorIterator::SELF_FIRST); foreach ($fileIterator as $file) { if (is_array($file) || null === $file) { continue; } $files[] = $file; } return $files; }
[ "protected", "function", "getFiles", "(", "FileBag", "$", "bag", ")", "{", "$", "files", "=", "[", "]", ";", "$", "fileBag", "=", "$", "bag", "->", "all", "(", ")", ";", "$", "fileIterator", "=", "new", "\\", "RecursiveIteratorIterator", "(", "new", ...
Flattens a given filebag to extract all files. @param FileBag $bag The filebag to use @return array An array of files
[ "Flattens", "a", "given", "filebag", "to", "extract", "all", "files", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractController.php#L80-L95
1up-lab/OneupUploaderBundle
Controller/AbstractController.php
AbstractController.handleUpload
protected function handleUpload($file, ResponseInterface $response, Request $request) { // wrap the file if it is not done yet which can only happen // if it wasn't a chunked upload, in which case it is definitely // on the local filesystem. if (!($file instanceof FileInterface)) { $file = new FilesystemFile($file); } $this->validate($file, $request, $response); $this->dispatchPreUploadEvent($file, $response, $request); // no error happend, proceed $namer = $this->container->get($this->config['namer']); $name = $namer->name($file); // perform the real upload $uploaded = $this->storage->upload($file, $name); $this->dispatchPostEvents($uploaded, $response, $request); }
php
protected function handleUpload($file, ResponseInterface $response, Request $request) { // wrap the file if it is not done yet which can only happen // if it wasn't a chunked upload, in which case it is definitely // on the local filesystem. if (!($file instanceof FileInterface)) { $file = new FilesystemFile($file); } $this->validate($file, $request, $response); $this->dispatchPreUploadEvent($file, $response, $request); // no error happend, proceed $namer = $this->container->get($this->config['namer']); $name = $namer->name($file); // perform the real upload $uploaded = $this->storage->upload($file, $name); $this->dispatchPostEvents($uploaded, $response, $request); }
[ "protected", "function", "handleUpload", "(", "$", "file", ",", "ResponseInterface", "$", "response", ",", "Request", "$", "request", ")", "{", "// wrap the file if it is not done yet which can only happen", "// if it wasn't a chunked upload, in which case it is definitely", "// ...
This internal function handles the actual upload process and will most likely be called from the upload() function in the implemented Controller. Note: The return value differs when @param mixed $file The file to upload @param ResponseInterface $response a response object @param Request $request the request object
[ "This", "internal", "function", "handles", "the", "actual", "upload", "process", "and", "will", "most", "likely", "be", "called", "from", "the", "upload", "()", "function", "in", "the", "implemented", "Controller", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractController.php#L108-L128
1up-lab/OneupUploaderBundle
Controller/AbstractController.php
AbstractController.dispatchPreUploadEvent
protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request) { $dispatcher = $this->container->get('event_dispatcher'); // dispatch pre upload event (both the specific and the general) $preUploadEvent = new PreUploadEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::PRE_UPLOAD, $preUploadEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::PRE_UPLOAD, $this->type), $preUploadEvent); }
php
protected function dispatchPreUploadEvent(FileInterface $uploaded, ResponseInterface $response, Request $request) { $dispatcher = $this->container->get('event_dispatcher'); // dispatch pre upload event (both the specific and the general) $preUploadEvent = new PreUploadEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::PRE_UPLOAD, $preUploadEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::PRE_UPLOAD, $this->type), $preUploadEvent); }
[ "protected", "function", "dispatchPreUploadEvent", "(", "FileInterface", "$", "uploaded", ",", "ResponseInterface", "$", "response", ",", "Request", "$", "request", ")", "{", "$", "dispatcher", "=", "$", "this", "->", "container", "->", "get", "(", "'event_dispa...
This function is a helper function which dispatches pre upload event. @param FileInterface $uploaded the uploaded file @param ResponseInterface $response a response object @param Request $request the request object
[ "This", "function", "is", "a", "helper", "function", "which", "dispatches", "pre", "upload", "event", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractController.php#L137-L145
1up-lab/OneupUploaderBundle
Controller/AbstractController.php
AbstractController.dispatchPostEvents
protected function dispatchPostEvents($uploaded, ResponseInterface $response, Request $request) { $dispatcher = $this->container->get('event_dispatcher'); // dispatch post upload event (both the specific and the general) $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postUploadEvent); if (!$this->config['use_orphanage']) { // dispatch post persist event (both the specific and the general) $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_PERSIST, $this->type), $postPersistEvent); } }
php
protected function dispatchPostEvents($uploaded, ResponseInterface $response, Request $request) { $dispatcher = $this->container->get('event_dispatcher'); // dispatch post upload event (both the specific and the general) $postUploadEvent = new PostUploadEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_UPLOAD, $postUploadEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_UPLOAD, $this->type), $postUploadEvent); if (!$this->config['use_orphanage']) { // dispatch post persist event (both the specific and the general) $postPersistEvent = new PostPersistEvent($uploaded, $response, $request, $this->type, $this->config); $dispatcher->dispatch(UploadEvents::POST_PERSIST, $postPersistEvent); $dispatcher->dispatch(sprintf('%s.%s', UploadEvents::POST_PERSIST, $this->type), $postPersistEvent); } }
[ "protected", "function", "dispatchPostEvents", "(", "$", "uploaded", ",", "ResponseInterface", "$", "response", ",", "Request", "$", "request", ")", "{", "$", "dispatcher", "=", "$", "this", "->", "container", "->", "get", "(", "'event_dispatcher'", ")", ";", ...
This function is a helper function which dispatches post upload and post persist events. @param mixed $uploaded the uploaded file @param ResponseInterface $response a response object @param Request $request the request object
[ "This", "function", "is", "a", "helper", "function", "which", "dispatches", "post", "upload", "and", "post", "persist", "events", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractController.php#L155-L170
1up-lab/OneupUploaderBundle
Controller/AbstractController.php
AbstractController.createSupportedJsonResponse
protected function createSupportedJsonResponse($data, $statusCode = 200) { $request = $this->getRequest(); $response = new JsonResponse($data, $statusCode); $response->headers->set('Vary', 'Accept'); if (!in_array('application/json', $request->getAcceptableContentTypes(), true)) { $response->headers->set('Content-type', 'text/plain'); } return $response; }
php
protected function createSupportedJsonResponse($data, $statusCode = 200) { $request = $this->getRequest(); $response = new JsonResponse($data, $statusCode); $response->headers->set('Vary', 'Accept'); if (!in_array('application/json', $request->getAcceptableContentTypes(), true)) { $response->headers->set('Content-type', 'text/plain'); } return $response; }
[ "protected", "function", "createSupportedJsonResponse", "(", "$", "data", ",", "$", "statusCode", "=", "200", ")", "{", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "$", "response", "=", "new", "JsonResponse", "(", "$", "data", ",...
Creates and returns a JsonResponse with the given data. On top of that, if the client does not support the application/json type, then the content type of the response will be set to text/plain instead. @param mixed $data @param int $statusCode @return JsonResponse
[ "Creates", "and", "returns", "a", "JsonResponse", "with", "the", "given", "data", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractController.php#L192-L203
1up-lab/OneupUploaderBundle
Controller/AbstractController.php
AbstractController.getRequest
protected function getRequest() { if (version_compare(Kernel::VERSION, '2.4', '<=')) { return $this->container->get('request'); } return $this->container->get('request_stack')->getMasterRequest(); }
php
protected function getRequest() { if (version_compare(Kernel::VERSION, '2.4', '<=')) { return $this->container->get('request'); } return $this->container->get('request_stack')->getMasterRequest(); }
[ "protected", "function", "getRequest", "(", ")", "{", "if", "(", "version_compare", "(", "Kernel", "::", "VERSION", ",", "'2.4'", ",", "'<='", ")", ")", "{", "return", "$", "this", "->", "container", "->", "get", "(", "'request'", ")", ";", "}", "retur...
Get the master request. @return Request
[ "Get", "the", "master", "request", "." ]
train
https://github.com/1up-lab/OneupUploaderBundle/blob/1fb5be7e7d5bb96f5936bc6bac7c35ecd6148989/Controller/AbstractController.php#L210-L217
graphp/graph
src/Set/Vertices.php
Vertices.getVertexId
public function getVertexId($id) { try { return $this->getVertexMatch($this->getCallbackId($id)); } catch (UnderflowException $e) { throw new OutOfBoundsException('Vertex ' . $id . ' does not exist', 0, $e); } }
php
public function getVertexId($id) { try { return $this->getVertexMatch($this->getCallbackId($id)); } catch (UnderflowException $e) { throw new OutOfBoundsException('Vertex ' . $id . ' does not exist', 0, $e); } }
[ "public", "function", "getVertexId", "(", "$", "id", ")", "{", "try", "{", "return", "$", "this", "->", "getVertexMatch", "(", "$", "this", "->", "getCallbackId", "(", "$", "id", ")", ")", ";", "}", "catch", "(", "UnderflowException", "$", "e", ")", ...
get Vertex with the given vertex $id @param int|string $id @return Vertex @throws OutOfBoundsException if no Vertex with the given ID exists @uses self::getVertexMatch()
[ "get", "Vertex", "with", "the", "given", "vertex", "$id" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L102-L110
graphp/graph
src/Set/Vertices.php
Vertices.getIndexVertex
public function getIndexVertex(Vertex $vertex) { $id = array_search($vertex, $this->vertices, true); if ($id === false) { throw new OutOfBoundsException('Given vertex does NOT exist'); } return $id; }
php
public function getIndexVertex(Vertex $vertex) { $id = array_search($vertex, $this->vertices, true); if ($id === false) { throw new OutOfBoundsException('Given vertex does NOT exist'); } return $id; }
[ "public", "function", "getIndexVertex", "(", "Vertex", "$", "vertex", ")", "{", "$", "id", "=", "array_search", "(", "$", "vertex", ",", "$", "this", "->", "vertices", ",", "true", ")", ";", "if", "(", "$", "id", "===", "false", ")", "{", "throw", ...
get array index for given Vertex not every set of Vertices represents a map, as such array index and Vertex ID do not necessarily have to match. @param Vertex $vertex @throws OutOfBoundsException @return mixed
[ "get", "array", "index", "for", "given", "Vertex" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L134-L141
graphp/graph
src/Set/Vertices.php
Vertices.getVertexFirst
public function getVertexFirst() { if (!$this->vertices) { throw new UnderflowException('Does not contain any vertices'); } reset($this->vertices); return current($this->vertices); }
php
public function getVertexFirst() { if (!$this->vertices) { throw new UnderflowException('Does not contain any vertices'); } reset($this->vertices); return current($this->vertices); }
[ "public", "function", "getVertexFirst", "(", ")", "{", "if", "(", "!", "$", "this", "->", "vertices", ")", "{", "throw", "new", "UnderflowException", "(", "'Does not contain any vertices'", ")", ";", "}", "reset", "(", "$", "this", "->", "vertices", ")", "...
return first Vertex in this set of Vertices some algorithms do not need a particular vertex, but merely a (random) starting point. this is a convenience function to just pick the first vertex from the list of known vertices. @return Vertex first Vertex in this set of Vertices @throws UnderflowException if set is empty @see self::getVertexOrder() if you need to apply ordering first
[ "return", "first", "Vertex", "in", "this", "set", "of", "Vertices" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L154-L162
graphp/graph
src/Set/Vertices.php
Vertices.getVertexLast
public function getVertexLast() { if (!$this->vertices) { throw new UnderflowException('Does not contain any vertices'); } end($this->vertices); return current($this->vertices); }
php
public function getVertexLast() { if (!$this->vertices) { throw new UnderflowException('Does not contain any vertices'); } end($this->vertices); return current($this->vertices); }
[ "public", "function", "getVertexLast", "(", ")", "{", "if", "(", "!", "$", "this", "->", "vertices", ")", "{", "throw", "new", "UnderflowException", "(", "'Does not contain any vertices'", ")", ";", "}", "end", "(", "$", "this", "->", "vertices", ")", ";",...
return last Vertex in this set of Vertices @return Vertex last Vertex in this set of Vertices @throws UnderflowException if set is empty
[ "return", "last", "Vertex", "in", "this", "set", "of", "Vertices" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L170-L178
graphp/graph
src/Set/Vertices.php
Vertices.getVertexMatch
public function getVertexMatch($callbackCheck) { $ret = $this->getVertexMatchOrNull($callbackCheck); if ($ret === null) { throw new UnderflowException('No vertex found'); } return $ret; }
php
public function getVertexMatch($callbackCheck) { $ret = $this->getVertexMatchOrNull($callbackCheck); if ($ret === null) { throw new UnderflowException('No vertex found'); } return $ret; }
[ "public", "function", "getVertexMatch", "(", "$", "callbackCheck", ")", "{", "$", "ret", "=", "$", "this", "->", "getVertexMatchOrNull", "(", "$", "callbackCheck", ")", ";", "if", "(", "$", "ret", "===", "null", ")", "{", "throw", "new", "UnderflowExceptio...
return first Vertex that matches the given callback filter function @param callable $callbackCheck @return Vertex @throws UnderflowException if no Vertex matches the given callback filter function @uses self::getVertexMatchOrNull() @see self::getVerticesMatch() if you want to return *all* Vertices that match
[ "return", "first", "Vertex", "that", "matches", "the", "given", "callback", "filter", "function" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L189-L196
graphp/graph
src/Set/Vertices.php
Vertices.getVerticesOrder
public function getVerticesOrder($orderBy, $desc = false) { if ($orderBy === self::ORDER_RANDOM) { // shuffle the vertex positions $keys = array_keys($this->vertices); shuffle($keys); // re-order according to shuffled vertex positions $vertices = array(); foreach ($keys as $key) { $vertices[$key] = $this->vertices[$key]; } // create iterator for shuffled array (no need to check DESC flag) return new static($vertices); } $callback = $this->getCallback($orderBy); $array = $this->vertices; uasort($array, function (Vertex $va, Vertex $vb) use ($callback, $desc) { $ra = $callback($desc ? $vb : $va); $rb = $callback($desc ? $va : $vb); if ($ra < $rb) { return -1; } elseif ($ra > $rb) { return 1; } else { return 0; } }); return new static($array); }
php
public function getVerticesOrder($orderBy, $desc = false) { if ($orderBy === self::ORDER_RANDOM) { // shuffle the vertex positions $keys = array_keys($this->vertices); shuffle($keys); // re-order according to shuffled vertex positions $vertices = array(); foreach ($keys as $key) { $vertices[$key] = $this->vertices[$key]; } // create iterator for shuffled array (no need to check DESC flag) return new static($vertices); } $callback = $this->getCallback($orderBy); $array = $this->vertices; uasort($array, function (Vertex $va, Vertex $vb) use ($callback, $desc) { $ra = $callback($desc ? $vb : $va); $rb = $callback($desc ? $va : $vb); if ($ra < $rb) { return -1; } elseif ($ra > $rb) { return 1; } else { return 0; } }); return new static($array); }
[ "public", "function", "getVerticesOrder", "(", "$", "orderBy", ",", "$", "desc", "=", "false", ")", "{", "if", "(", "$", "orderBy", "===", "self", "::", "ORDER_RANDOM", ")", "{", "// shuffle the vertex positions", "$", "keys", "=", "array_keys", "(", "$", ...
get new Set of Vertices ordered by given criterium $orderBy Vertex index positions will be left unchanged, so if you call this method on a VerticesMap, it will also return a VerticesMap. @param int $orderBy criterium to sort by. see Vertex::ORDER_ID, etc. @param boolean $desc whether to return biggest first (true) instead of smallest first (default:false) @return Vertices a new Vertices set ordered by the given $orderBy criterium @throws InvalidArgumentException if criterium is unknown @see self::getVertexOrder()
[ "get", "new", "Set", "of", "Vertices", "ordered", "by", "given", "criterium", "$orderBy" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L241-L275
graphp/graph
src/Set/Vertices.php
Vertices.getVerticesIntersection
public function getVerticesIntersection($otherVertices) { $otherArray = self::factory($otherVertices)->getVector(); $vertices = array(); foreach ($this->vertices as $vid => $vertex) { $i = array_search($vertex, $otherArray, true); if ($i !== false) { // remove from other array in order to check for duplicate matches unset($otherArray[$i]); $vertices[$vid] = $vertex; } } return new static($vertices); }
php
public function getVerticesIntersection($otherVertices) { $otherArray = self::factory($otherVertices)->getVector(); $vertices = array(); foreach ($this->vertices as $vid => $vertex) { $i = array_search($vertex, $otherArray, true); if ($i !== false) { // remove from other array in order to check for duplicate matches unset($otherArray[$i]); $vertices[$vid] = $vertex; } } return new static($vertices); }
[ "public", "function", "getVerticesIntersection", "(", "$", "otherVertices", ")", "{", "$", "otherArray", "=", "self", "::", "factory", "(", "$", "otherVertices", ")", "->", "getVector", "(", ")", ";", "$", "vertices", "=", "array", "(", ")", ";", "foreach"...
get intersection of Vertices with given other Vertices The intersection contains all Vertex instances that are present in BOTH this set of Vertices and the given set of other Vertices. Vertex index/keys will be preserved from original array. Duplicate Vertex instances will be kept if the corresponding number of Vertex instances is also found in $otherVertices. @param Vertices|Vertex[] $otherVertices @return Vertices a new Vertices set
[ "get", "intersection", "of", "Vertices", "with", "given", "other", "Vertices" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L291-L308
graphp/graph
src/Set/Vertices.php
Vertices.getVertexOrder
public function getVertexOrder($orderBy, $desc=false) { if (!$this->vertices) { throw new UnderflowException('No vertex found'); } // random order if ($orderBy === self::ORDER_RANDOM) { // just return by random key (no need to check for DESC flag) return $this->vertices[array_rand($this->vertices)]; } $callback = $this->getCallback($orderBy); $ret = NULL; $best = NULL; foreach ($this->vertices as $vertex) { $now = $callback($vertex); if ($ret === NULL || ($desc && $now > $best) || (!$desc && $now < $best)) { $ret = $vertex; $best = $now; } } return $ret; }
php
public function getVertexOrder($orderBy, $desc=false) { if (!$this->vertices) { throw new UnderflowException('No vertex found'); } // random order if ($orderBy === self::ORDER_RANDOM) { // just return by random key (no need to check for DESC flag) return $this->vertices[array_rand($this->vertices)]; } $callback = $this->getCallback($orderBy); $ret = NULL; $best = NULL; foreach ($this->vertices as $vertex) { $now = $callback($vertex); if ($ret === NULL || ($desc && $now > $best) || (!$desc && $now < $best)) { $ret = $vertex; $best = $now; } } return $ret; }
[ "public", "function", "getVertexOrder", "(", "$", "orderBy", ",", "$", "desc", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "vertices", ")", "{", "throw", "new", "UnderflowException", "(", "'No vertex found'", ")", ";", "}", "// random order"...
get first vertex (optionally ordered by given criterium $by) from given array of vertices @param int $orderBy criterium to sort by. see Vertex::ORDER_ID, etc. @param boolean $desc whether to return biggest (true) instead of smallest (default:false) @return Vertex @throws InvalidArgumentException if criterium is unknown @throws UnderflowException if no vertices exist @see self::getVerticesOrder()
[ "get", "first", "vertex", "(", "optionally", "ordered", "by", "given", "criterium", "$by", ")", "from", "given", "array", "of", "vertices" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L320-L345
graphp/graph
src/Set/Vertices.php
Vertices.getMap
public function getMap() { $vertices = array(); foreach ($this->vertices as $vertex) { $vertices[$vertex->getId()] = $vertex; } return $vertices; }
php
public function getMap() { $vertices = array(); foreach ($this->vertices as $vertex) { $vertices[$vertex->getId()] = $vertex; } return $vertices; }
[ "public", "function", "getMap", "(", ")", "{", "$", "vertices", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "vertices", "as", "$", "vertex", ")", "{", "$", "vertices", "[", "$", "vertex", "->", "getId", "(", ")", "]", "=", "$"...
get a mapping array of Vertex ID => Vertex instance and thus remove duplicate vertices @return Vertex[] Vertex ID => Vertex instance @uses Vertex::getId()
[ "get", "a", "mapping", "array", "of", "Vertex", "ID", "=", ">", "Vertex", "instance", "and", "thus", "remove", "duplicate", "vertices" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L375-L382
graphp/graph
src/Set/Vertices.php
Vertices.getIds
public function getIds() { $ids = array(); foreach ($this->vertices as $vertex) { $ids []= $vertex->getId(); } return $ids; }
php
public function getIds() { $ids = array(); foreach ($this->vertices as $vertex) { $ids []= $vertex->getId(); } return $ids; }
[ "public", "function", "getIds", "(", ")", "{", "$", "ids", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "vertices", "as", "$", "vertex", ")", "{", "$", "ids", "[", "]", "=", "$", "vertex", "->", "getId", "(", ")", ";", "}", ...
return array of Vertex IDs @return array
[ "return", "array", "of", "Vertex", "IDs" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L389-L396
graphp/graph
src/Set/Vertices.php
Vertices.getSumCallback
public function getSumCallback($callback) { $callback = $this->getCallback($callback); // return array_sum(array_map($callback, $this->vertices)); $sum = 0; foreach ($this->vertices as $vertex) { $sum += $callback($vertex); } return $sum; }
php
public function getSumCallback($callback) { $callback = $this->getCallback($callback); // return array_sum(array_map($callback, $this->vertices)); $sum = 0; foreach ($this->vertices as $vertex) { $sum += $callback($vertex); } return $sum; }
[ "public", "function", "getSumCallback", "(", "$", "callback", ")", "{", "$", "callback", "=", "$", "this", "->", "getCallback", "(", "$", "callback", ")", ";", "// return array_sum(array_map($callback, $this->vertices));", "$", "sum", "=", "0", ";", "foreach", "...
call given $callback on each Vertex and sum their results @param callable $callback @return number @throws InvalidArgumentException for invalid callbacks @uses self::getCallback()
[ "call", "given", "$callback", "on", "each", "Vertex", "and", "sum", "their", "results" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L464-L475
graphp/graph
src/Set/Vertices.php
Vertices.getCallback
private function getCallback($callback) { if (is_callable($callback)) { if (is_array($callback)) { $callback = function (Vertex $vertex) use ($callback) { return call_user_func($callback, $vertex); }; } return $callback; } static $methods = array( self::ORDER_ID => 'getId', self::ORDER_GROUP => 'getGroup' ); if (!is_int($callback) || !isset($methods[$callback])) { throw new InvalidArgumentException('Invalid callback given'); } $method = $methods[$callback]; return function (Vertex $vertex) use ($method) { return $vertex->$method(); }; }
php
private function getCallback($callback) { if (is_callable($callback)) { if (is_array($callback)) { $callback = function (Vertex $vertex) use ($callback) { return call_user_func($callback, $vertex); }; } return $callback; } static $methods = array( self::ORDER_ID => 'getId', self::ORDER_GROUP => 'getGroup' ); if (!is_int($callback) || !isset($methods[$callback])) { throw new InvalidArgumentException('Invalid callback given'); } $method = $methods[$callback]; return function (Vertex $vertex) use ($method) { return $vertex->$method(); }; }
[ "private", "function", "getCallback", "(", "$", "callback", ")", "{", "if", "(", "is_callable", "(", "$", "callback", ")", ")", "{", "if", "(", "is_array", "(", "$", "callback", ")", ")", "{", "$", "callback", "=", "function", "(", "Vertex", "$", "ve...
get callback/Closure to be called on Vertex instances for given callback identifier @param callable|int $callback @throws InvalidArgumentException @return callable
[ "get", "callback", "/", "Closure", "to", "be", "called", "on", "Vertex", "instances", "for", "given", "callback", "identifier" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Vertices.php#L503-L528
graphp/graph
src/Set/Edges.php
Edges.getIndexEdge
public function getIndexEdge(Edge $edge) { $id = array_search($edge, $this->edges, true); if ($id === false) { throw new OutOfBoundsException('Given edge does NOT exist'); } return $id; }
php
public function getIndexEdge(Edge $edge) { $id = array_search($edge, $this->edges, true); if ($id === false) { throw new OutOfBoundsException('Given edge does NOT exist'); } return $id; }
[ "public", "function", "getIndexEdge", "(", "Edge", "$", "edge", ")", "{", "$", "id", "=", "array_search", "(", "$", "edge", ",", "$", "this", "->", "edges", ",", "true", ")", ";", "if", "(", "$", "id", "===", "false", ")", "{", "throw", "new", "O...
get array index for given Edge @param Edge $edge @throws OutOfBoundsException @return mixed
[ "get", "array", "index", "for", "given", "Edge" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L117-L124
graphp/graph
src/Set/Edges.php
Edges.getEdgeFirst
public function getEdgeFirst() { if (!$this->edges) { throw new UnderflowException('Does not contain any edges'); } reset($this->edges); return current($this->edges); }
php
public function getEdgeFirst() { if (!$this->edges) { throw new UnderflowException('Does not contain any edges'); } reset($this->edges); return current($this->edges); }
[ "public", "function", "getEdgeFirst", "(", ")", "{", "if", "(", "!", "$", "this", "->", "edges", ")", "{", "throw", "new", "UnderflowException", "(", "'Does not contain any edges'", ")", ";", "}", "reset", "(", "$", "this", "->", "edges", ")", ";", "retu...
return first Edge in this set of Edges some algorithms do not need a particular edge, but merely a (random) starting point. this is a convenience function to just pick the first edge from the list of known edges. @return Edge first Edge in this set of Edges @throws UnderflowException if set is empty @see self::getEdgeOrder() if you need to apply ordering first
[ "return", "first", "Edge", "in", "this", "set", "of", "Edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L137-L145
graphp/graph
src/Set/Edges.php
Edges.getEdgeLast
public function getEdgeLast() { if (!$this->edges) { throw new UnderflowException('Does not contain any edges'); } end($this->edges); return current($this->edges); }
php
public function getEdgeLast() { if (!$this->edges) { throw new UnderflowException('Does not contain any edges'); } end($this->edges); return current($this->edges); }
[ "public", "function", "getEdgeLast", "(", ")", "{", "if", "(", "!", "$", "this", "->", "edges", ")", "{", "throw", "new", "UnderflowException", "(", "'Does not contain any edges'", ")", ";", "}", "end", "(", "$", "this", "->", "edges", ")", ";", "return"...
return last Edge in this set of Edges @return Edge last Edge in this set of Edges @throws UnderflowException if set is empty
[ "return", "last", "Edge", "in", "this", "set", "of", "Edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L153-L161
graphp/graph
src/Set/Edges.php
Edges.getEdgeIndex
public function getEdgeIndex($index) { if (!isset($this->edges[$index])) { throw new OutOfBoundsException('Invalid edge index'); } return $this->edges[$index]; }
php
public function getEdgeIndex($index) { if (!isset($this->edges[$index])) { throw new OutOfBoundsException('Invalid edge index'); } return $this->edges[$index]; }
[ "public", "function", "getEdgeIndex", "(", "$", "index", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "edges", "[", "$", "index", "]", ")", ")", "{", "throw", "new", "OutOfBoundsException", "(", "'Invalid edge index'", ")", ";", "}", "ret...
return Edge at given array index @param mixed $index @throws OutOfBoundsException if the given index does not exist @return Edge
[ "return", "Edge", "at", "given", "array", "index" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L170-L176
graphp/graph
src/Set/Edges.php
Edges.getEdgeMatch
public function getEdgeMatch($callbackCheck) { $ret = $this->getEdgeMatchOrNull($callbackCheck); if ($ret === null) { throw new UnderflowException('No edge found'); } return $ret; }
php
public function getEdgeMatch($callbackCheck) { $ret = $this->getEdgeMatchOrNull($callbackCheck); if ($ret === null) { throw new UnderflowException('No edge found'); } return $ret; }
[ "public", "function", "getEdgeMatch", "(", "$", "callbackCheck", ")", "{", "$", "ret", "=", "$", "this", "->", "getEdgeMatchOrNull", "(", "$", "callbackCheck", ")", ";", "if", "(", "$", "ret", "===", "null", ")", "{", "throw", "new", "UnderflowException", ...
return first Edge that matches the given callback filter function @param callable $callbackCheck @return Edge @throws UnderflowException if no Edge matches the given callback filter function @uses self::getEdgeMatchOrNull() @see self::getEdgesMatch() if you want to return *all* Edges that match
[ "return", "first", "Edge", "that", "matches", "the", "given", "callback", "filter", "function" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L187-L194
graphp/graph
src/Set/Edges.php
Edges.getEdgesOrder
public function getEdgesOrder($orderBy, $desc = false) { if ($orderBy === self::ORDER_RANDOM) { // shuffle the edge positions $keys = array_keys($this->edges); shuffle($keys); // re-order according to shuffled edge positions $edges = array(); foreach ($keys as $key) { $edges[$key] = $this->edges[$key]; } // create iterator for shuffled array (no need to check DESC flag) return new static($edges); } $callback = $this->getCallback($orderBy); $array = $this->edges; uasort($array, function (Edge $va, Edge $vb) use ($callback, $desc) { $ra = $callback($desc ? $vb : $va); $rb = $callback($desc ? $va : $vb); if ($ra < $rb) { return -1; } elseif ($ra > $rb) { return 1; } else { return 0; } }); return new static($array); }
php
public function getEdgesOrder($orderBy, $desc = false) { if ($orderBy === self::ORDER_RANDOM) { // shuffle the edge positions $keys = array_keys($this->edges); shuffle($keys); // re-order according to shuffled edge positions $edges = array(); foreach ($keys as $key) { $edges[$key] = $this->edges[$key]; } // create iterator for shuffled array (no need to check DESC flag) return new static($edges); } $callback = $this->getCallback($orderBy); $array = $this->edges; uasort($array, function (Edge $va, Edge $vb) use ($callback, $desc) { $ra = $callback($desc ? $vb : $va); $rb = $callback($desc ? $va : $vb); if ($ra < $rb) { return -1; } elseif ($ra > $rb) { return 1; } else { return 0; } }); return new static($array); }
[ "public", "function", "getEdgesOrder", "(", "$", "orderBy", ",", "$", "desc", "=", "false", ")", "{", "if", "(", "$", "orderBy", "===", "self", "::", "ORDER_RANDOM", ")", "{", "// shuffle the edge positions", "$", "keys", "=", "array_keys", "(", "$", "this...
get new set of Edges ordered by given criterium $orderBy Edge index positions will be left unchanged. @param int $orderBy criterium to sort by. see self::ORDER_WEIGHT, etc. @param boolean $desc whether to return biggest first (true) instead of smallest first (default:false) @return Edges a new Edges set ordered by the given $orderBy criterium @throws InvalidArgumentException if criterium is unknown
[ "get", "new", "set", "of", "Edges", "ordered", "by", "given", "criterium", "$orderBy" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L236-L270
graphp/graph
src/Set/Edges.php
Edges.getEdgeOrder
public function getEdgeOrder($orderBy, $desc=false) { if (!$this->edges) { throw new UnderflowException('No edge found'); } // random order if ($orderBy === self::ORDER_RANDOM) { // just return by random key (no need to check for DESC flag) return $this->edges[array_rand($this->edges)]; } $callback = $this->getCallback($orderBy); $ret = NULL; $best = NULL; foreach ($this->edges as $edge) { $now = $callback($edge); if ($ret === NULL || ($desc && $now > $best) || (!$desc && $now < $best)) { $ret = $edge; $best = $now; } } return $ret; }
php
public function getEdgeOrder($orderBy, $desc=false) { if (!$this->edges) { throw new UnderflowException('No edge found'); } // random order if ($orderBy === self::ORDER_RANDOM) { // just return by random key (no need to check for DESC flag) return $this->edges[array_rand($this->edges)]; } $callback = $this->getCallback($orderBy); $ret = NULL; $best = NULL; foreach ($this->edges as $edge) { $now = $callback($edge); if ($ret === NULL || ($desc && $now > $best) || (!$desc && $now < $best)) { $ret = $edge; $best = $now; } } return $ret; }
[ "public", "function", "getEdgeOrder", "(", "$", "orderBy", ",", "$", "desc", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "edges", ")", "{", "throw", "new", "UnderflowException", "(", "'No edge found'", ")", ";", "}", "// random order", "if...
get first edge ordered by given criterium $orderBy @param int $orderBy criterium to sort by. see self::ORDER_WEIGHT, etc. @param boolean $desc whether to return biggest (true) instead of smallest (default:false) @return Edge @throws InvalidArgumentException if criterium is unknown @throws UnderflowException if no edges exist
[ "get", "first", "edge", "ordered", "by", "given", "criterium", "$orderBy" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L281-L306
graphp/graph
src/Set/Edges.php
Edges.getEdgesDistinct
public function getEdgesDistinct() { $edges = array(); foreach ($this->edges as $edge) { // filter duplicate edges if (!in_array($edge, $edges, true)) { $edges []= $edge; } } return new Edges($edges); }
php
public function getEdgesDistinct() { $edges = array(); foreach ($this->edges as $edge) { // filter duplicate edges if (!in_array($edge, $edges, true)) { $edges []= $edge; } } return new Edges($edges); }
[ "public", "function", "getEdgesDistinct", "(", ")", "{", "$", "edges", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "edges", "as", "$", "edge", ")", "{", "// filter duplicate edges", "if", "(", "!", "in_array", "(", "$", "edge", ",",...
get a new set of Edges where each Edge is distinct/unique @return Edges a new Edges instance
[ "get", "a", "new", "set", "of", "Edges", "where", "each", "Edge", "is", "distinct", "/", "unique" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L324-L335
graphp/graph
src/Set/Edges.php
Edges.getEdgesIntersection
public function getEdgesIntersection($otherEdges) { $otherArray = self::factory($otherEdges)->getVector(); $edges = array(); foreach ($this->edges as $eid => $edge) { $i = array_search($edge, $otherArray, true); if ($i !== false) { // remove from other array in order to check for duplicate matches unset($otherArray[$i]); $edges[$eid] = $edge; } } return new static($edges); }
php
public function getEdgesIntersection($otherEdges) { $otherArray = self::factory($otherEdges)->getVector(); $edges = array(); foreach ($this->edges as $eid => $edge) { $i = array_search($edge, $otherArray, true); if ($i !== false) { // remove from other array in order to check for duplicate matches unset($otherArray[$i]); $edges[$eid] = $edge; } } return new static($edges); }
[ "public", "function", "getEdgesIntersection", "(", "$", "otherEdges", ")", "{", "$", "otherArray", "=", "self", "::", "factory", "(", "$", "otherEdges", ")", "->", "getVector", "(", ")", ";", "$", "edges", "=", "array", "(", ")", ";", "foreach", "(", "...
get intersection of Edges with given other Edges The intersection contains all Edge instances that are present in BOTH this set of Edges and the given set of other Edges. Edge index/keys will be preserved from original array. Duplicate Edge instances will be kept if the corresponding number of Edge instances is also found in $otherEdges. @param Edges|Edge[] $otherEdges @return Edges a new Edges set
[ "get", "intersection", "of", "Edges", "with", "given", "other", "Edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L351-L368
graphp/graph
src/Set/Edges.php
Edges.getSumCallback
public function getSumCallback($callback) { $callback = $this->getCallback($callback); // return array_sum(array_map($callback, $this->edges)); $sum = 0; foreach ($this->edges as $edge) { $sum += $callback($edge); } return $sum; }
php
public function getSumCallback($callback) { $callback = $this->getCallback($callback); // return array_sum(array_map($callback, $this->edges)); $sum = 0; foreach ($this->edges as $edge) { $sum += $callback($edge); } return $sum; }
[ "public", "function", "getSumCallback", "(", "$", "callback", ")", "{", "$", "callback", "=", "$", "this", "->", "getCallback", "(", "$", "callback", ")", ";", "// return array_sum(array_map($callback, $this->edges));", "$", "sum", "=", "0", ";", "foreach", "(",...
call given $callback on each Edge and sum their results @param callable $callback @return number @throws InvalidArgumentException for invalid callbacks @uses self::getCallback()
[ "call", "given", "$callback", "on", "each", "Edge", "and", "sum", "their", "results" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L425-L436
graphp/graph
src/Set/Edges.php
Edges.getCallback
private function getCallback($callback) { if (is_callable($callback)) { if (is_array($callback)) { $callback = function (Edge $edge) use ($callback) { return call_user_func($callback, $edge); }; } return $callback; } static $methods = array( self::ORDER_WEIGHT => 'getWeight', self::ORDER_CAPACITY => 'getCapacity', self::ORDER_CAPACITY_REMAINING => 'getCapacityRemaining', self::ORDER_FLOW => 'getFlow' ); if (!is_int($callback) || !isset($methods[$callback])) { throw new InvalidArgumentException('Invalid callback given'); } $method = $methods[$callback]; return function (Edge $edge) use ($method) { return $edge->$method(); }; }
php
private function getCallback($callback) { if (is_callable($callback)) { if (is_array($callback)) { $callback = function (Edge $edge) use ($callback) { return call_user_func($callback, $edge); }; } return $callback; } static $methods = array( self::ORDER_WEIGHT => 'getWeight', self::ORDER_CAPACITY => 'getCapacity', self::ORDER_CAPACITY_REMAINING => 'getCapacityRemaining', self::ORDER_FLOW => 'getFlow' ); if (!is_int($callback) || !isset($methods[$callback])) { throw new InvalidArgumentException('Invalid callback given'); } $method = $methods[$callback]; return function (Edge $edge) use ($method) { return $edge->$method(); }; }
[ "private", "function", "getCallback", "(", "$", "callback", ")", "{", "if", "(", "is_callable", "(", "$", "callback", ")", ")", "{", "if", "(", "is_array", "(", "$", "callback", ")", ")", "{", "$", "callback", "=", "function", "(", "Edge", "$", "edge...
get callback/Closure to be called on Edge instances for given callback identifier @param callable|int $callback @throws InvalidArgumentException @return callable
[ "get", "callback", "/", "Closure", "to", "be", "called", "on", "Edge", "instances", "for", "given", "callback", "identifier" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Set/Edges.php#L457-L484
graphp/graph
src/Vertex.php
Vertex.removeEdge
public function removeEdge(Edge $edge) { $id = array_search($edge, $this->edges, true); if ($id === false) { throw new InvalidArgumentException('Given edge does NOT exist'); } unset($this->edges[$id]); }
php
public function removeEdge(Edge $edge) { $id = array_search($edge, $this->edges, true); if ($id === false) { throw new InvalidArgumentException('Given edge does NOT exist'); } unset($this->edges[$id]); }
[ "public", "function", "removeEdge", "(", "Edge", "$", "edge", ")", "{", "$", "id", "=", "array_search", "(", "$", "edge", ",", "$", "this", "->", "edges", ",", "true", ")", ";", "if", "(", "$", "id", "===", "false", ")", "{", "throw", "new", "Inv...
remove the given edge from list of connected edges (MUST NOT be called manually) @param Edge $edge @return void @throws InvalidArgumentException if given edge does not exist @private @see Edge::destroy() instead!
[ "remove", "the", "given", "edge", "from", "list", "of", "connected", "edges", "(", "MUST", "NOT", "be", "called", "manually", ")" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L177-L184
graphp/graph
src/Vertex.php
Vertex.hasEdgeTo
public function hasEdgeTo(Vertex $vertex) { $that = $this; return $this->getEdges()->hasEdgeMatch(function (Edge $edge) use ($that, $vertex) { return $edge->isConnection($that, $vertex); }); }
php
public function hasEdgeTo(Vertex $vertex) { $that = $this; return $this->getEdges()->hasEdgeMatch(function (Edge $edge) use ($that, $vertex) { return $edge->isConnection($that, $vertex); }); }
[ "public", "function", "hasEdgeTo", "(", "Vertex", "$", "vertex", ")", "{", "$", "that", "=", "$", "this", ";", "return", "$", "this", "->", "getEdges", "(", ")", "->", "hasEdgeMatch", "(", "function", "(", "Edge", "$", "edge", ")", "use", "(", "$", ...
check whether this vertex has a direct edge to given $vertex @param Vertex $vertex @return boolean @uses Edge::hasVertexTarget()
[ "check", "whether", "this", "vertex", "has", "a", "direct", "edge", "to", "given", "$vertex" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L193-L200
graphp/graph
src/Vertex.php
Vertex.getEdgesOut
public function getEdgesOut() { $that = $this; return $this->getEdges()->getEdgesMatch(function (Edge $edge) use ($that) { return $edge->hasVertexStart($that); }); }
php
public function getEdgesOut() { $that = $this; return $this->getEdges()->getEdgesMatch(function (Edge $edge) use ($that) { return $edge->hasVertexStart($that); }); }
[ "public", "function", "getEdgesOut", "(", ")", "{", "$", "that", "=", "$", "this", ";", "return", "$", "this", "->", "getEdges", "(", ")", "->", "getEdgesMatch", "(", "function", "(", "Edge", "$", "edge", ")", "use", "(", "$", "that", ")", "{", "re...
get set of all outgoing Edges attached to this vertex @return Edges
[ "get", "set", "of", "all", "outgoing", "Edges", "attached", "to", "this", "vertex" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L229-L236
graphp/graph
src/Vertex.php
Vertex.getEdgesIn
public function getEdgesIn() { $that = $this; return $this->getEdges()->getEdgesMatch(function (Edge $edge) use ($that) { return $edge->hasVertexTarget($that); }); }
php
public function getEdgesIn() { $that = $this; return $this->getEdges()->getEdgesMatch(function (Edge $edge) use ($that) { return $edge->hasVertexTarget($that); }); }
[ "public", "function", "getEdgesIn", "(", ")", "{", "$", "that", "=", "$", "this", ";", "return", "$", "this", "->", "getEdges", "(", ")", "->", "getEdgesMatch", "(", "function", "(", "Edge", "$", "edge", ")", "use", "(", "$", "that", ")", "{", "ret...
get set of all ingoing Edges attached to this vertex @return Edges
[ "get", "set", "of", "all", "ingoing", "Edges", "attached", "to", "this", "vertex" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L243-L250
graphp/graph
src/Vertex.php
Vertex.getEdgesTo
public function getEdgesTo(Vertex $vertex) { $that = $this; return $this->getEdges()->getEdgesMatch(function (Edge $edge) use ($that, $vertex) { return $edge->isConnection($that, $vertex); }); }
php
public function getEdgesTo(Vertex $vertex) { $that = $this; return $this->getEdges()->getEdgesMatch(function (Edge $edge) use ($that, $vertex) { return $edge->isConnection($that, $vertex); }); }
[ "public", "function", "getEdgesTo", "(", "Vertex", "$", "vertex", ")", "{", "$", "that", "=", "$", "this", ";", "return", "$", "this", "->", "getEdges", "(", ")", "->", "getEdgesMatch", "(", "function", "(", "Edge", "$", "edge", ")", "use", "(", "$",...
get set of Edges FROM this vertex TO the given vertex @param Vertex $vertex @return Edges @uses Edge::hasVertexTarget()
[ "get", "set", "of", "Edges", "FROM", "this", "vertex", "TO", "the", "given", "vertex" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L259-L266
graphp/graph
src/Vertex.php
Vertex.getVerticesEdge
public function getVerticesEdge() { $ret = array(); foreach ($this->edges as $edge) { if ($edge->hasVertexStart($this)) { $ret []= $edge->getVertexToFrom($this); } else { $ret []= $edge->getVertexFromTo($this); } } return new Vertices($ret); }
php
public function getVerticesEdge() { $ret = array(); foreach ($this->edges as $edge) { if ($edge->hasVertexStart($this)) { $ret []= $edge->getVertexToFrom($this); } else { $ret []= $edge->getVertexFromTo($this); } } return new Vertices($ret); }
[ "public", "function", "getVerticesEdge", "(", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "edges", "as", "$", "edge", ")", "{", "if", "(", "$", "edge", "->", "hasVertexStart", "(", "$", "this", ")", ")", ...
get set of adjacent Vertices of this vertex (edge FROM or TO this vertex) If there are multiple parallel edges between the same Vertex, it will be returned several times in the resulting Set of Vertices. If you only want unique Vertex instances, use `getVerticesDistinct()`. @return Vertices @uses Edge::hasVertexStart() @uses Edge::getVerticesToFrom() @uses Edge::getVerticesFromTo()
[ "get", "set", "of", "adjacent", "Vertices", "of", "this", "vertex", "(", "edge", "FROM", "or", "TO", "this", "vertex", ")" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L292-L304
graphp/graph
src/Vertex.php
Vertex.getVerticesEdgeTo
public function getVerticesEdgeTo() { $ret = array(); foreach ($this->getEdgesOut() as $edge) { $ret []= $edge->getVertexToFrom($this); } return new Vertices($ret); }
php
public function getVerticesEdgeTo() { $ret = array(); foreach ($this->getEdgesOut() as $edge) { $ret []= $edge->getVertexToFrom($this); } return new Vertices($ret); }
[ "public", "function", "getVerticesEdgeTo", "(", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getEdgesOut", "(", ")", "as", "$", "edge", ")", "{", "$", "ret", "[", "]", "=", "$", "edge", "->", "getVertexToFr...
get set of all Vertices this vertex has an edge to If there are multiple parallel edges to the same Vertex, it will be returned several times in the resulting Set of Vertices. If you only want unique Vertex instances, use `getVerticesDistinct()`. @return Vertices @uses Vertex::getEdgesOut() @uses Edge::getVerticesToFrom()
[ "get", "set", "of", "all", "Vertices", "this", "vertex", "has", "an", "edge", "to" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L317-L325
graphp/graph
src/Vertex.php
Vertex.getVerticesEdgeFrom
public function getVerticesEdgeFrom() { $ret = array(); foreach ($this->getEdgesIn() as $edge) { $ret []= $edge->getVertexFromTo($this); } return new Vertices($ret); }
php
public function getVerticesEdgeFrom() { $ret = array(); foreach ($this->getEdgesIn() as $edge) { $ret []= $edge->getVertexFromTo($this); } return new Vertices($ret); }
[ "public", "function", "getVerticesEdgeFrom", "(", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getEdgesIn", "(", ")", "as", "$", "edge", ")", "{", "$", "ret", "[", "]", "=", "$", "edge", "->", "getVertexFro...
get set of all Vertices that have an edge TO this vertex If there are multiple parallel edges from the same Vertex, it will be returned several times in the resulting Set of Vertices. If you only want unique Vertex instances, use `getVerticesDistinct()`. @return Vertices @uses Vertex::getEdgesIn() @uses Edge::getVerticesFromTo()
[ "get", "set", "of", "all", "Vertices", "that", "have", "an", "edge", "TO", "this", "vertex" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L338-L346
graphp/graph
src/Vertex.php
Vertex.destroy
public function destroy() { foreach ($this->getEdges()->getEdgesDistinct() as $edge) { $edge->destroy(); } $this->graph->removeVertex($this); }
php
public function destroy() { foreach ($this->getEdges()->getEdgesDistinct() as $edge) { $edge->destroy(); } $this->graph->removeVertex($this); }
[ "public", "function", "destroy", "(", ")", "{", "foreach", "(", "$", "this", "->", "getEdges", "(", ")", "->", "getEdgesDistinct", "(", ")", "as", "$", "edge", ")", "{", "$", "edge", "->", "destroy", "(", ")", ";", "}", "$", "this", "->", "graph", ...
destroy vertex and all edges connected to it and remove reference from graph @uses Edge::destroy() @uses Graph::removeVertex()
[ "destroy", "vertex", "and", "all", "edges", "connected", "to", "it", "and", "remove", "reference", "from", "graph" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Vertex.php#L354-L360
graphp/graph
src/Graph.php
Graph.createVertex
public function createVertex($id = NULL, $returnDuplicate = false) { // no ID given if ($id === NULL) { $id = $this->getNextId(); } if ($returnDuplicate && $this->vertices->hasVertexId($id)) { return $this->vertices->getVertexId($id); } return new Vertex($this, $id); }
php
public function createVertex($id = NULL, $returnDuplicate = false) { // no ID given if ($id === NULL) { $id = $this->getNextId(); } if ($returnDuplicate && $this->vertices->hasVertexId($id)) { return $this->vertices->getVertexId($id); } return new Vertex($this, $id); }
[ "public", "function", "createVertex", "(", "$", "id", "=", "NULL", ",", "$", "returnDuplicate", "=", "false", ")", "{", "// no ID given", "if", "(", "$", "id", "===", "NULL", ")", "{", "$", "id", "=", "$", "this", "->", "getNextId", "(", ")", ";", ...
create a new Vertex in the Graph @param int|NULL $id new vertex ID to use (defaults to NULL: use next free numeric ID) @param boolean $returnDuplicate normal operation is to throw an exception if given id already exists. pass true to return original vertex instead @return Vertex (chainable) @throws InvalidArgumentException if given vertex $id is invalid @throws OverflowException if given vertex $id already exists and $returnDuplicate is not set @uses Vertex::getId()
[ "create", "a", "new", "Vertex", "in", "the", "Graph" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L66-L77
graphp/graph
src/Graph.php
Graph.createVertexClone
public function createVertexClone(Vertex $originalVertex) { $id = $originalVertex->getId(); if ($this->vertices->hasVertexId($id)) { throw new RuntimeException('Id of cloned vertex already exists'); } $newVertex = new Vertex($this, $id); // TODO: properly set attributes of vertex $newVertex->getAttributeBag()->setAttributes($originalVertex->getAttributeBag()->getAttributes()); $newVertex->setBalance($originalVertex->getBalance()); $newVertex->setGroup($originalVertex->getGroup()); return $newVertex; }
php
public function createVertexClone(Vertex $originalVertex) { $id = $originalVertex->getId(); if ($this->vertices->hasVertexId($id)) { throw new RuntimeException('Id of cloned vertex already exists'); } $newVertex = new Vertex($this, $id); // TODO: properly set attributes of vertex $newVertex->getAttributeBag()->setAttributes($originalVertex->getAttributeBag()->getAttributes()); $newVertex->setBalance($originalVertex->getBalance()); $newVertex->setGroup($originalVertex->getGroup()); return $newVertex; }
[ "public", "function", "createVertexClone", "(", "Vertex", "$", "originalVertex", ")", "{", "$", "id", "=", "$", "originalVertex", "->", "getId", "(", ")", ";", "if", "(", "$", "this", "->", "vertices", "->", "hasVertexId", "(", "$", "id", ")", ")", "{"...
create a new Vertex in this Graph from the given input Vertex of another graph @param Vertex $originalVertex @return Vertex new vertex in this graph @throws RuntimeException if vertex with this ID already exists
[ "create", "a", "new", "Vertex", "in", "this", "Graph", "from", "the", "given", "input", "Vertex", "of", "another", "graph" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L86-L99
graphp/graph
src/Graph.php
Graph.createGraphCloneEdgeless
public function createGraphCloneEdgeless() { $graph = new Graph(); $graph->getAttributeBag()->setAttributes($this->getAttributeBag()->getAttributes()); // TODO: set additional graph attributes foreach ($this->getVertices() as $originalVertex) { $vertex = $graph->createVertexClone($originalVertex); // $graph->vertices[$vid] = $vertex; } return $graph; }
php
public function createGraphCloneEdgeless() { $graph = new Graph(); $graph->getAttributeBag()->setAttributes($this->getAttributeBag()->getAttributes()); // TODO: set additional graph attributes foreach ($this->getVertices() as $originalVertex) { $vertex = $graph->createVertexClone($originalVertex); // $graph->vertices[$vid] = $vertex; } return $graph; }
[ "public", "function", "createGraphCloneEdgeless", "(", ")", "{", "$", "graph", "=", "new", "Graph", "(", ")", ";", "$", "graph", "->", "getAttributeBag", "(", ")", "->", "setAttributes", "(", "$", "this", "->", "getAttributeBag", "(", ")", "->", "getAttrib...
create new clone/copy of this graph - copy all attributes and vertices, but do NOT copy edges using this method is faster than creating a new graph and calling createEdgeClone() yourself @return Graph
[ "create", "new", "clone", "/", "copy", "of", "this", "graph", "-", "copy", "all", "attributes", "and", "vertices", "but", "do", "NOT", "copy", "edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L108-L119
graphp/graph
src/Graph.php
Graph.createGraphCloneEdges
public function createGraphCloneEdges($edges) { $graph = $this->createGraphCloneEdgeless(); foreach ($edges as $edge) { $graph->createEdgeClone($edge); } return $graph; }
php
public function createGraphCloneEdges($edges) { $graph = $this->createGraphCloneEdgeless(); foreach ($edges as $edge) { $graph->createEdgeClone($edge); } return $graph; }
[ "public", "function", "createGraphCloneEdges", "(", "$", "edges", ")", "{", "$", "graph", "=", "$", "this", "->", "createGraphCloneEdgeless", "(", ")", ";", "foreach", "(", "$", "edges", "as", "$", "edge", ")", "{", "$", "graph", "->", "createEdgeClone", ...
create new clone/copy of this graph - copy all attributes and vertices. but only copy all given edges @param Edges|Edge[] $edges set or array of edges to be cloned @return Graph @uses Graph::createGraphCloneEdgeless() @uses Graph::createEdgeClone() for each edge to be cloned
[ "create", "new", "clone", "/", "copy", "of", "this", "graph", "-", "copy", "all", "attributes", "and", "vertices", ".", "but", "only", "copy", "all", "given", "edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L129-L137
graphp/graph
src/Graph.php
Graph.createGraphCloneVertices
public function createGraphCloneVertices($vertices) { $verticesKeep = Vertices::factory($vertices); $graph = $this->createGraphClone(); foreach ($graph->getVertices()->getMap() as $vid => $vertex) { if (!$verticesKeep->hasVertexId($vid)) { $vertex->destroy(); } } return $graph; }
php
public function createGraphCloneVertices($vertices) { $verticesKeep = Vertices::factory($vertices); $graph = $this->createGraphClone(); foreach ($graph->getVertices()->getMap() as $vid => $vertex) { if (!$verticesKeep->hasVertexId($vid)) { $vertex->destroy(); } } return $graph; }
[ "public", "function", "createGraphCloneVertices", "(", "$", "vertices", ")", "{", "$", "verticesKeep", "=", "Vertices", "::", "factory", "(", "$", "vertices", ")", ";", "$", "graph", "=", "$", "this", "->", "createGraphClone", "(", ")", ";", "foreach", "("...
create a new clone/copy of this graph - copy all attributes and given vertices and its edges @param Vertices $vertices set of vertices to keep @return Graph @uses Graph::createGraphClone() to create a complete clone @uses Vertex::destroy() to remove unneeded vertices again
[ "create", "a", "new", "clone", "/", "copy", "of", "this", "graph", "-", "copy", "all", "attributes", "and", "given", "vertices", "and", "its", "edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L158-L170
graphp/graph
src/Graph.php
Graph.createEdgeCloneInternal
private function createEdgeCloneInternal(Edge $originalEdge, $ia, $ib) { $ends = $originalEdge->getVertices()->getIds(); // get start vertex from old start vertex id $a = $this->getVertex($ends[$ia]); // get target vertex from old target vertex id $b = $this->getVertex($ends[$ib]); if ($originalEdge instanceof EdgeDirected) { $newEdge = $a->createEdgeTo($b); } else { // create new edge between new a and b $newEdge = $a->createEdge($b); } // TODO: copy edge attributes $newEdge->getAttributeBag()->setAttributes($originalEdge->getAttributeBag()->getAttributes()); $newEdge->setWeight($originalEdge->getWeight()); $newEdge->setFlow($originalEdge->getFlow()); $newEdge->setCapacity($originalEdge->getCapacity()); return $newEdge; }
php
private function createEdgeCloneInternal(Edge $originalEdge, $ia, $ib) { $ends = $originalEdge->getVertices()->getIds(); // get start vertex from old start vertex id $a = $this->getVertex($ends[$ia]); // get target vertex from old target vertex id $b = $this->getVertex($ends[$ib]); if ($originalEdge instanceof EdgeDirected) { $newEdge = $a->createEdgeTo($b); } else { // create new edge between new a and b $newEdge = $a->createEdge($b); } // TODO: copy edge attributes $newEdge->getAttributeBag()->setAttributes($originalEdge->getAttributeBag()->getAttributes()); $newEdge->setWeight($originalEdge->getWeight()); $newEdge->setFlow($originalEdge->getFlow()); $newEdge->setCapacity($originalEdge->getCapacity()); return $newEdge; }
[ "private", "function", "createEdgeCloneInternal", "(", "Edge", "$", "originalEdge", ",", "$", "ia", ",", "$", "ib", ")", "{", "$", "ends", "=", "$", "originalEdge", "->", "getVertices", "(", ")", "->", "getIds", "(", ")", ";", "// get start vertex from old s...
create new clone of the given edge between adjacent vertices @param Edge $originalEdge original edge from old graph @param int $ia index of start vertex @param int $ib index of end vertex @return Edge new edge in this graph @uses Edge::getVertices() @uses Graph::getVertex() @uses Vertex::createEdge() to create a new undirected edge if given edge was undrected @uses Vertex::createEdgeTo() to create a new directed edge if given edge was directed @uses Edge::getWeight() @uses Edge::setWeight() @uses Edge::getFlow() @uses Edge::setFlow() @uses Edge::getCapacity() @uses Edge::setCapacity()
[ "create", "new", "clone", "of", "the", "given", "edge", "between", "adjacent", "vertices" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L214-L236
graphp/graph
src/Graph.php
Graph.createVertices
public function createVertices($n) { $vertices = array(); if (is_int($n) && $n >= 0) { for ($id = $this->getNextId(), $n += $id; $id < $n; ++$id) { $vertices[$id] = new Vertex($this, $id); } } elseif (is_array($n)) { // array given => check to make sure all given IDs are available (atomic operation) foreach ($n as $id) { if (!is_int($id) && !is_string($id)) { throw new InvalidArgumentException('All Vertex IDs have to be of type integer or string'); } elseif ($this->vertices->hasVertexId($id)) { throw new OverflowException('Given array of Vertex IDs contains an ID that already exists. Given IDs must be unique'); } elseif (isset($vertices[$id])) { throw new InvalidArgumentException('Given array of Vertex IDs contain duplicate IDs. Given IDs must be unique'); } // temporary marker to check for duplicate IDs in the array $vertices[$id] = false; } // actually create all requested vertices foreach ($n as $id) { $vertices[$id] = new Vertex($this, $id); } } else { throw new InvalidArgumentException('Invalid number of vertices given. Must be non-negative integer or an array of Vertex IDs'); } return new Vertices($vertices); }
php
public function createVertices($n) { $vertices = array(); if (is_int($n) && $n >= 0) { for ($id = $this->getNextId(), $n += $id; $id < $n; ++$id) { $vertices[$id] = new Vertex($this, $id); } } elseif (is_array($n)) { // array given => check to make sure all given IDs are available (atomic operation) foreach ($n as $id) { if (!is_int($id) && !is_string($id)) { throw new InvalidArgumentException('All Vertex IDs have to be of type integer or string'); } elseif ($this->vertices->hasVertexId($id)) { throw new OverflowException('Given array of Vertex IDs contains an ID that already exists. Given IDs must be unique'); } elseif (isset($vertices[$id])) { throw new InvalidArgumentException('Given array of Vertex IDs contain duplicate IDs. Given IDs must be unique'); } // temporary marker to check for duplicate IDs in the array $vertices[$id] = false; } // actually create all requested vertices foreach ($n as $id) { $vertices[$id] = new Vertex($this, $id); } } else { throw new InvalidArgumentException('Invalid number of vertices given. Must be non-negative integer or an array of Vertex IDs'); } return new Vertices($vertices); }
[ "public", "function", "createVertices", "(", "$", "n", ")", "{", "$", "vertices", "=", "array", "(", ")", ";", "if", "(", "is_int", "(", "$", "n", ")", "&&", "$", "n", ">=", "0", ")", "{", "for", "(", "$", "id", "=", "$", "this", "->", "getNe...
create the given number of vertices or given array of Vertex IDs @param int|array $n number of vertices to create or array of Vertex IDs to create @return Vertices set of Vertices created @uses Graph::getNextId()
[ "create", "the", "given", "number", "of", "vertices", "or", "given", "array", "of", "Vertex", "IDs" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L245-L276
graphp/graph
src/Graph.php
Graph.addVertex
public function addVertex(Vertex $vertex) { if (isset($this->verticesStorage[$vertex->getId()])) { throw new OverflowException('ID must be unique'); } $this->verticesStorage[$vertex->getId()] = $vertex; }
php
public function addVertex(Vertex $vertex) { if (isset($this->verticesStorage[$vertex->getId()])) { throw new OverflowException('ID must be unique'); } $this->verticesStorage[$vertex->getId()] = $vertex; }
[ "public", "function", "addVertex", "(", "Vertex", "$", "vertex", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "verticesStorage", "[", "$", "vertex", "->", "getId", "(", ")", "]", ")", ")", "{", "throw", "new", "OverflowException", "(", "'ID mu...
adds a new Vertex to the Graph (MUST NOT be called manually!) @param Vertex $vertex instance of the new Vertex @return void @private @see self::createVertex() instead!
[ "adds", "a", "new", "Vertex", "to", "the", "Graph", "(", "MUST", "NOT", "be", "called", "manually!", ")" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L326-L332
graphp/graph
src/Graph.php
Graph.removeEdge
public function removeEdge(Edge $edge) { try { unset($this->edgesStorage[$this->edges->getIndexEdge($edge)]); } catch (OutOfBoundsException $e) { throw new InvalidArgumentException('Invalid Edge does not exist in this Graph'); } }
php
public function removeEdge(Edge $edge) { try { unset($this->edgesStorage[$this->edges->getIndexEdge($edge)]); } catch (OutOfBoundsException $e) { throw new InvalidArgumentException('Invalid Edge does not exist in this Graph'); } }
[ "public", "function", "removeEdge", "(", "Edge", "$", "edge", ")", "{", "try", "{", "unset", "(", "$", "this", "->", "edgesStorage", "[", "$", "this", "->", "edges", "->", "getIndexEdge", "(", "$", "edge", ")", "]", ")", ";", "}", "catch", "(", "Ou...
remove the given edge from list of connected edges (MUST NOT be called manually!) @param Edge $edge @return void @throws InvalidArgumentException if given edge does not exist (should not ever happen) @private @see Edge::destroy() instead!
[ "remove", "the", "given", "edge", "from", "list", "of", "connected", "edges", "(", "MUST", "NOT", "be", "called", "manually!", ")" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L356-L364
graphp/graph
src/Graph.php
Graph.removeVertex
public function removeVertex(Vertex $vertex) { try { unset($this->verticesStorage[$this->vertices->getIndexVertex($vertex)]); } catch (OutOfBoundsException $e) { throw new InvalidArgumentException('Invalid Vertex does not exist in this Graph'); } }
php
public function removeVertex(Vertex $vertex) { try { unset($this->verticesStorage[$this->vertices->getIndexVertex($vertex)]); } catch (OutOfBoundsException $e) { throw new InvalidArgumentException('Invalid Vertex does not exist in this Graph'); } }
[ "public", "function", "removeVertex", "(", "Vertex", "$", "vertex", ")", "{", "try", "{", "unset", "(", "$", "this", "->", "verticesStorage", "[", "$", "this", "->", "vertices", "->", "getIndexVertex", "(", "$", "vertex", ")", "]", ")", ";", "}", "catc...
remove the given vertex from list of known vertices (MUST NOT be called manually!) @param Vertex $vertex @return void @throws InvalidArgumentException if given vertex does not exist (should not ever happen) @private @see Vertex::destroy() instead!
[ "remove", "the", "given", "vertex", "from", "list", "of", "known", "vertices", "(", "MUST", "NOT", "be", "called", "manually!", ")" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L375-L383
graphp/graph
src/Graph.php
Graph.getEdgeClone
public function getEdgeClone(Edge $edge) { // Extract endpoints from edge $vertices = $edge->getVertices()->getVector(); return $this->getEdgeCloneInternal($edge, $vertices[0], $vertices[1]); }
php
public function getEdgeClone(Edge $edge) { // Extract endpoints from edge $vertices = $edge->getVertices()->getVector(); return $this->getEdgeCloneInternal($edge, $vertices[0], $vertices[1]); }
[ "public", "function", "getEdgeClone", "(", "Edge", "$", "edge", ")", "{", "// Extract endpoints from edge", "$", "vertices", "=", "$", "edge", "->", "getVertices", "(", ")", "->", "getVector", "(", ")", ";", "return", "$", "this", "->", "getEdgeCloneInternal",...
Extracts edge from this graph @param Edge $edge @return Edge @throws UnderflowException if no edge was found @throws OverflowException if multiple edges match
[ "Extracts", "edge", "from", "this", "graph" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L393-L399
graphp/graph
src/Graph.php
Graph.getEdgeCloneInverted
public function getEdgeCloneInverted(Edge $edge) { // Extract endpoints from edge $vertices = $edge->getVertices()->getVector(); return $this->getEdgeCloneInternal($edge, $vertices[1], $vertices[0]); }
php
public function getEdgeCloneInverted(Edge $edge) { // Extract endpoints from edge $vertices = $edge->getVertices()->getVector(); return $this->getEdgeCloneInternal($edge, $vertices[1], $vertices[0]); }
[ "public", "function", "getEdgeCloneInverted", "(", "Edge", "$", "edge", ")", "{", "// Extract endpoints from edge", "$", "vertices", "=", "$", "edge", "->", "getVertices", "(", ")", "->", "getVector", "(", ")", ";", "return", "$", "this", "->", "getEdgeCloneIn...
Extracts inverted edge from this graph @param Edge $edge @return Edge @throws UnderflowException if no edge was found @throws OverflowException if multiple edges match
[ "Extracts", "inverted", "edge", "from", "this", "graph" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Graph.php#L409-L415