sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
public function is()
{
$patterns = func_get_args();
$name = $this->currentRouteName();
foreach ($patterns as $pattern) {
if (Str::is($pattern, $this->currentRouteName())) {
return true;
}
}
return false;
} | Alias for the "currentRouteNamed" method.
@param mixed string
@return bool | entailment |
public function currentRouteNamed($name)
{
if (! is_null($route = $this->current())) {
return ($route->getName() == $name);
}
return false;
} | Determine if the current route matches a given name.
@param string $name
@return bool | entailment |
public function currentRouteAction()
{
if (! is_null($route = $this->current())) {
$action = $route->getAction();
return isset($action['controller']) ? $action['controller'] : null;
}
} | Get the current route action.
@return string|null | entailment |
public function getRegistrar()
{
if (isset($this->registrar)) {
return $this->registrar;
}
return $this->registrar = new ResourceRegistrar($this);
} | Get a Resource Registrar instance.
@return \Nova\Routing\ResourceRegistrar | entailment |
public function handle()
{
if (! $this->confirmToProceed()) {
return;
}
$this->prepareDatabase();
$slug = $this->argument('slug');
if (! empty($slug)) {
if (! $this->packages->exists($slug)) {
return $this->error('Package does not exist.');
}
if ($this->packages->isEnabled($slug)) {
return $this->migrate($slug);
}
return $this->error('Nothing to migrate.');
}
if ($this->option('force')) {
$packages = $this->packages->all();
} else {
$packages = $this->packages->enabled();
}
foreach ($packages as $package) {
$this->comment('Migrating the Package: ' .$package['name']);
$this->migrate($package['slug']);
}
} | Execute the console command.
@return mixed | entailment |
protected function migrate($slug)
{
if (! $this->packages->exists($slug)) {
return $this->error('Package does not exist.');
}
$path = $this->getMigrationPath($slug);
//
$pretend = $this->input->getOption('pretend');
$this->migrator->run($path, $pretend, $slug);
//
foreach ($this->migrator->getNotes() as $note) {
if (! $this->option('quiet')) {
$this->line($note);
}
}
if ($this->option('seed')) {
$this->call('package:seed', array('slug' => $slug, '--force' => true));
}
} | Run migrations for the specified Package.
@param string $slug
@return mixed | entailment |
protected function getMigrationPath($slug)
{
$package = $this->packages->where('slug', $slug);
$path = $this->packages->resolveClassPath($package);
return $path .'Database' .DS .'Migrations' .DS;
} | Get migration directory path.
@param string $slug
@return string | entailment |
protected function resolveAndHandle(array $payload)
{
list($class, $method) = Str::parseCallback($payload['job'], 'handle');
$this->instance = $this->resolve($class);
call_user_func(array($this->instance, $method), $this, $payload['data']);
} | Resolve and fire the job handler method.
@param array $payload
@return void | entailment |
public function resolveName()
{
$payload = json_decode($this->getRawBody(), true);
//
$name = $payload['job'];
// When the job is a Closure.
if ($name == 'Nova\Queue\CallQueuedClosure@call') {
return 'Closure';
}
// When the job is a Handler.
else if ($name == 'Nova\Queue\CallQueuedHandler@call') {
return Arr::get($payload, 'data.commandName', $name);
}
// When the job is an Event.
else if ($name == 'Nova\Events\CallQueuedHandler@call') {
$className = Arr::get($payload, 'data.class');
$method = Arr::get($payload, 'data.method');
return $className .'@' .$method;
}
return $name;
} | Get the resolved name of the queued job class.
@return string | entailment |
protected function registerAssetDispatcher()
{
$this->app->singleton('assets.dispatcher', function ($app)
{
$dispatcher = new AssetDispatcher($app);
// Register the route for assets from main assets folder.
$dispatcher->route('assets/(.*)', function (Request $request, $path) use ($dispatcher)
{
$basePath = $this->app['config']->get('routing.assets.path', base_path('assets'));
$path = $basePath .DS .str_replace('/', DS, $path);
return $dispatcher->serve($path, $request);
});
// Register the route for assets from Packages, Modules and Themes.
$dispatcher->route('packages/([^/]+)/([^/]+)/(.*)', function (Request $request, $vendor, $package, $path) use ($dispatcher)
{
$namespace = $vendor .'/' .$package;
if (is_null($packagePath = $dispatcher->getPackagePath($namespace))) {
return new Response('File Not Found', 404);
}
$path = $packagePath .str_replace('/', DS, $path);
return $dispatcher->serve($path, $request);
});
// Register the route for assets from Vendor.
$dispatcher->route('vendor/(.*)', function (Request $request, $path) use ($dispatcher)
{
$paths = $dispatcher->getVendorPaths();
if (! Str::startsWith($path, $paths)) {
return new Response('File Not Found', 404);
}
$path = BASEPATH .'vendor' .DS .str_replace('/', DS, $path);
return $dispatcher->serve($path, $request);
});
return $dispatcher;
});
} | Register the Assets Dispatcher.
@return void | entailment |
public function with($line)
{
if ($line instanceof Action) {
$this->action($line->text, $line->url);
} else if (is_null($this->actionText)) {
$this->introLines[] = $this->format($line);
} else {
$this->outroLines[] = $this->format($line);
}
return $this;
} | Add a line of text to the notification.
@param \Nova\Notifications\Action|string|array $line
@return $this | entailment |
protected function format($line)
{
if (is_array($line)) {
return implode(' ', array_map('trim', $line));
}
$lines = preg_split('/\\r\\n|\\r|\\n/', $line);
return trim(implode(' ', array_map('trim', $lines)));
} | Format the given line of text.
@param string|array $line
@return string | entailment |
public function createResponse(int $code = 200, string $reasonPhrase = '') : ResponseInterface
{
$body = (new StreamFactory)
->createStream();
return (new Response)
->withStatus($code, $reasonPhrase)
->withBody($body);
} | {@inheritDoc} | entailment |
public function run(Container $container)
{
if ($this->description && $this->withoutOverlapping && ! $this->mutex->create($this)) {
return;
}
register_shutdown_function(function ()
{
$this->removeMutex();
});
parent::callBeforeCallbacks($container);
try {
$response = $container->call($this->callback, $this->parameters);
}
finally {
$this->removeMutex();
parent::callAfterCallbacks($container);
}
return $response;
} | Run the given event.
@param \Nova\Container\Container $container
@return mixed
@throws \Exception | entailment |
public function handle()
{
$this->cache->driver($this->option('store'))->forget($key = $this->argument('key'));
$this->info('The [' .$key .'] key has been removed from the cache.');
} | Execute the console command.
@return void | entailment |
public function markAsRead()
{
if (is_null($this->read_at)) {
$this->forceFill(array(
'read_at' => $this->freshTimestamp()
));
$this->save();
}
} | Mark the notification as read.
@return void | entailment |
public function register($name, $controller, array $options = array())
{
// If the resource name contains a slash, we will assume the developer wishes to
// register these resource routes with a prefix so we will set that up out of
// the box so they don't have to mess with it. Otherwise, we will continue.
if (Str::contains($name, '/')) {
$this->prefixedResource($name, $controller, $options);
return;
}
// We need to extract the base resource from the resource name. Nested resources
// are supported in the framework, but we need to know what name to use for a
// place-holder on the route wildcards, which should be the base resources.
$segments = explode('.', $name);
$base = $this->getResourceWildcard(
last($segments)
);
$methods = $this->getResourceMethods($this->resourceDefaults, $options);
foreach ($methods as $method) {
$method = 'addResource' .ucfirst($method);
call_user_func(array($this, $method), $name, $base, $controller, $options);
}
} | Route a resource to a controller.
@param string $name
@param string $controller
@param array $options
@return void | entailment |
protected function getNestedResourceUri(array $segments)
{
// We will spin through the segments and create a place-holder for each of the
// resource segments, as well as the resource itself. Then we should get an
// entire string for the resource URI that contains all nested resources.
return implode('/', array_map(function ($segment)
{
$name = $this->getResourceWildcard($segment);
return $segment .'/{' .$name .'}';
}, $segments));
} | Get the URI for a nested resource segment array.
@param array $segments
@return string | entailment |
protected function getResourceAction($resource, $controller, $method, $options)
{
$name = $this->getResourceName($resource, $method, $options);
return array('as' => $name, 'uses' => $controller .'@' .$method);
} | Get the action array for a resource route.
@param string $resource
@param string $controller
@param string $method
@param array $options
@return array | entailment |
protected function getResourceName($resource, $method, $options)
{
if (isset($options['names'][$method])) {
return $options['names'][$method];
}
// If a global prefix has been assigned to all names for this resource, we will
// grab that so we can prepend it onto the name when we create this name for
// the resource action. Otherwise we'll just use an empty string for here.
$prefix = isset($options['as']) ? $options['as'] .'.' : '';
if (! $this->router->hasGroupStack()) {
return $prefix .$resource .'.' .$method;
}
return $this->getGroupResourceName($prefix, $resource, $method);
} | Get the name for a given resource.
@param string $resource
@param string $method
@param array $options
@return string | entailment |
protected function getGroupResourceName($prefix, $resource, $method)
{
$group = trim(
str_replace('/', '.', $this->router->getLastGroupPrefix()), '.'
);
if (empty($group)) {
return trim("{$prefix}{$resource}.{$method}", '.');
}
return trim("{$prefix}{$group}.{$resource}.{$method}", '.');
} | Get the resource name for a grouped resource.
@param string $prefix
@param string $resource
@param string $method
@return string | entailment |
protected function addResourceUpdate($name, $base, $controller, $options)
{
$this->addPutResourceUpdate($name, $base, $controller, $options);
return $this->addPatchResourceUpdate($name, $base, $controller);
} | Add the update method for a resourceful route.
@param string $name
@param string $base
@param string $controller
@param array $options
@return void | entailment |
protected function addPutResourceUpdate($name, $base, $controller, $options)
{
$uri = $this->getResourceUri($name) .'/{' .$base .'}';
$action = $this->getResourceAction($name, $controller, 'update', $options);
return $this->router->put($uri, $action);
} | Add the update method for a resourceful route.
@param string $name
@param string $base
@param string $controller
@param array $options
@return \Nova\Routing\Route | entailment |
protected function addPatchResourceUpdate($name, $base, $controller)
{
$uri = $this->getResourceUri($name) .'/{' .$base .'}';
$this->router->patch($uri, $controller.'@update');
} | Add the update method for a resourceful route.
@param string $name
@param string $base
@param string $controller
@return void | entailment |
protected function resolveByPath($filePath)
{
$this->data['filename'] = $this->makeFileName($filePath);
$this->data['namespace'] = $this->getBaseNamespace() .'\\' .$this->getNamespace($filePath);
$this->data['className'] = basename($filePath);
} | Resolve Container after getting file path.
@param string $filePath
@return array | entailment |
protected function formatContent($content)
{
$searches = array(
'{{filename}}',
'{{namespace}}',
'{{className}}',
);
$replaces = array(
$this->data['filename'],
$this->data['namespace'],
$this->data['className'],
);
return str_replace($searches, $replaces, $content);
} | Replace placeholder text with correct values.
@return string | entailment |
protected function getStubContent($stubName)
{
$content = $this->files->get(__DIR__ .DS .'stubs' .DS .$stubName);
return $this->formatContent($content);
} | Get stub content by key.
@param int $key
@return string | entailment |
public function make($view, $data = array(), $mergeData = array())
{
if (isset($this->aliases[$view])) $view = $this->aliases[$view];
$path = $this->finder->find($view);
if (is_null($path) || ! is_readable($path)) {
throw new BadMethodCallException("File path [$path] does not exist");
}
$data = array_except(
array_merge($mergeData, $this->parseData($data)), array('__data', '__path')
);
$this->callCreator(
$view = new View($this, $this->getEngineFromPath($path), $view, $path, $data)
);
return $view;
} | Create a View instance
@param string $path
@param mixed $data
@param array $mergeData
@return \Nova\View\View | entailment |
public function fetch($view, $data = array(), Closure $callback = null)
{
unset($data['__path'], $data['__path']);
return $this->make($view, $data)->render($callback);
} | Create a View instance and return its rendered content.
@return string | entailment |
public function getEngineFromPath($path)
{
$extension = $this->getExtension($path);
$engine = $this->extensions[$extension];
return $this->engines->resolve($engine);
} | Get the appropriate View Engine for the given path.
@param string $path
@return \Nova\View\Engines\EngineInterface | entailment |
protected function getExtension($path)
{
$extensions = array_keys($this->extensions);
return array_first($extensions, function($key, $value) use ($path)
{
return ends_with($path, $value);
});
} | Get the extension used by the view file.
@param string $path
@return string | entailment |
public function creator($views, $callback)
{
$creators = array();
foreach ((array) $views as $view) {
$creators[] = $this->addViewEvent($view, $callback, 'creating: ');
}
return $creators;
} | Register a view creator event.
@param array|string $views
@param \Closure|string $callback
@return array | entailment |
protected function addViewEvent($view, $callback, $prefix = 'composing: ', $priority = null)
{
if ($callback instanceof Closure) {
$this->addEventListener($prefix.$view, $callback, $priority);
return $callback;
} else if (is_string($callback)) {
return $this->addClassEvent($view, $callback, $prefix, $priority);
}
} | Add an event for a given view.
@param string $view
@param \Closure|string $callback
@param string $prefix
@param int|null $priority
@return \Closure | entailment |
protected function addEventListener($name, $callback, $priority = null)
{
if (is_null($priority)) {
$this->events->listen($name, $callback);
} else {
$this->events->listen($name, $callback, $priority);
}
} | Add a listener to the event dispatcher.
@param string $name
@param \Closure $callback
@param int $priority
@return void | entailment |
public function startSection($section, $content = '')
{
if (! empty($content)) {
$this->extendSection($section, $content);
} else if (ob_start()) {
$this->sectionStack[] = $section;
}
} | Start injecting content into a section.
@param string $section
@param string $content
@return void | entailment |
public function appendSection()
{
$last = array_pop($this->sectionStack);
if (isset($this->sections[$last])) {
$this->sections[$last] .= ob_get_clean();
} else {
$this->sections[$last] = ob_get_clean();
}
return $last;
} | Stop injecting content into a section and append it.
@return string | entailment |
public function retrieveFirstByCategorySlug($categorySlug)
{
$query = $this->createQueryBuilder('q')
->join('q.category', 'c')
->where('c.slug = :categorySlug')
->andWhere('q.isActive = :isActive')
->andWhere('q.publishAt <= :publishAt')
->andWhere('(q.expiresAt IS NULL OR q.expiresAt >= :expiresAt)')
->orderBy('q.rank', 'ASC')
->setMaxResults(1)
->getQuery();
$query->setParameter('categorySlug', $categorySlug);
$query->setParameter('isActive', true);
$query->setParameter('publishAt', date('Y-m-d H:i:s'));
$query->setParameter('expiresAt', date('Y-m-d H:i:s'));
return $query->getOneOrNullResult();
} | @param string $categorySlug
@return Question|null | entailment |
public function retrieveMostRecent($max)
{
$query = $this->createQueryBuilder('q')
->join('q.category', 'c')
->where('q.isActive = :isActive')
->andWhere('q.publishAt <= :publishAt')
->andWhere('(q.expiresAt IS NULL OR q.expiresAt >= :expiresAt)')
->orderBy('q.publishAt', 'DESC')
->setMaxResults($max)
->getQuery();
$query->setParameter('isActive', true);
$query->setParameter('publishAt', date('Y-m-d H:i:s'));
$query->setParameter('expiresAt', date('Y-m-d H:i:s'));
return $query->getResult();
} | @param int $max
@return DoctrineCollection|null | entailment |
public function retrieveByQuery($searchQuery, $max, $whereFields = array('headline', 'body'))
{
$sql = array();
foreach ($whereFields as $field ) {
$sql[] = 'q.' . $field . ' like :searchQuery';
}
$where = implode (' or ', $sql);
$query = $this->createQueryBuilder('q')
->join('q.category', 'c')
->where($where)
->andWhere('q.isActive = :isActive')
->andWhere('q.publishAt <= :publishAt')
->andWhere('(q.expiresAt IS NULL OR q.expiresAt >= :expiresAt)')
->orderBy('q.publishAt', 'DESC')
->setMaxResults($max)
->getQuery();
$query->setParameter('searchQuery', '%'. $searchQuery . '%');
$query->setParameter('isActive', true);
$query->setParameter('publishAt', date('Y-m-d H:i:s'));
$query->setParameter('expiresAt', date('Y-m-d H:i:s'));
return $query->getResult();
} | @param string $searchQuery
@param int $max
@param array $whereFields
@return DoctrineCollection|null | entailment |
public function retrieveByPartialHeadline($query)
{
$query = $this->createQueryBuilder('q')
->select('q.id, q.headline')
->where('q.headline LIKE :query')
->orderBy('q.publishAt', 'DESC')
->setParameter('query','%'.$query.'%')
->getQuery();
return $query->getArrayResult();
} | used for autocomplete in admin
@param string $query
@return array | entailment |
function jsonSerialize()
{
$result = [
'force_reply' => $this->forceReply
];
if ($this->selective !== null) {
$result['selective'] = $this->selective;
}
return $result;
} | Specify data which should be serialized to JSON | entailment |
public function call($class)
{
$this->resolve($class)->run();
if (isset($this->command)) {
$this->command->getOutput()->writeln("<info>Seeded:</info> $class");
}
} | Seed the given connection from the given path.
@param string $class
@return void | entailment |
public function handle()
{
$id = $this->argument('id');
$events = collect($this->schedule->events())->filter(function ($event) use ($id)
{
return ($event->mutexName() == $id);
});
$events->each(function ($event)
{
$event->callAfterCallbacks($this->container);
});
} | Execute the console command.
@return void | entailment |
public function handle()
{
$package = $this->input->getArgument('package');
$proceed = $this->confirmToProceed('Config Already Published!', function() use ($package)
{
return $this->publisher->alreadyPublished($package);
});
if (! $proceed) return;
$this->publisher->publishPackage($package);
$this->output->writeln('<info>Configuration published for package:</info> '.$package);
} | Execute the console command.
@return void | entailment |
public function handle()
{
$rows = array();
foreach ($this->container['queue.failer']->all() as $failed)
{
$rows[] = $this->parseFailedJob((array) $failed);
}
if (count($rows) == 0)
{
return $this->info('No failed jobs!');
}
$this->table(array('ID', 'Connection', 'Queue', 'Class', 'Failed At'), $rows);
} | Execute the console command.
@return void | entailment |
protected function parseFailedJob(array $failed)
{
$row = array_values(array_except($failed, array('payload')));
array_splice($row, 3, 0, array_get(json_decode($failed['payload'], true), 'job'));
return $row;
} | Parse the failed job row.
@param array $failed
@return array | entailment |
protected function createSmtpDriver()
{
$config = $this->app['config']['mail'];
// The Swift SMTP transport instance will allow us to use any SMTP backend
// for delivering mail such as Sendgrid, Amazon SES, or a custom server
// a developer has available. We will just pass this configured host.
$transport = SmtpTransport::newInstance(
$config['host'], $config['port']
);
if (isset($config['encryption'])) {
$transport->setEncryption($config['encryption']);
}
// Once we have the transport we will check for the presence of a username
// and password. If we have it we will set the credentials on the Swift
// transporter instance so that we'll properly authenticate delivery.
if (isset($config['username'])) {
$transport->setUsername($config['username']);
$transport->setPassword($config['password']);
}
return $transport;
} | Create an instance of the SMTP Swift Transport driver.
@return \Swift_SmtpTransport | entailment |
public function boot()
{
$session = $this->app['session'];
if (! $session->has('language')) {
$cookie = $this->app['request']->cookie(PREFIX .'language', null);
$locale = $cookie ?: $this->app['config']->get('app.locale');
$session->set('language', $locale);
} else {
$locale = $session->get('language');
}
$this->app['language']->setLocale($locale);
} | Bootstrap the application events.
@return void | entailment |
public function call(Job $job, array $data)
{
$payload = $this->crypt->decrypt(
$data['closure']
);
$closure = unserialize($payload);
call_user_func($closure, $job);
} | Fire the Closure based queue job.
@param \Nova\Queue\Job $job
@param array $data
@return void | entailment |
protected function runCommandInBackground(Container $container)
{
$this->callBeforeCallbacks($container);
$process = new Process($this->buildCommand(), base_path(), null, null, null);
$process->disableOutput();
$process->run();
} | Run the command in the background.
@param \Nova\Container\Container $container
@return void | entailment |
public function buildCommand()
{
$command = $this->compileCommand();
if (! is_null($this->user) && ! windows_os()) {
return 'sudo -u ' .$this->user .' -- sh -c \'' .$command .'\'';
}
return $command;
} | Build the command string.
@return string | entailment |
protected function compileCommand()
{
$output = ProcessUtils::escapeArgument($this->output);
$redirect = $this->shouldAppendOutput ? ' >> ' : ' > ';
if (! $this->runInBackground) {
return $this->command .$redirect .$output .' 2>&1';
}
$delimiter = windows_os() ? '&' : ';';
$phpBinary = ProcessUtils::escapeArgument(
with(new PhpExecutableFinder)->find(false)
);
$forgeBinary = defined('FORGE_BINARY') ? ProcessUtils::escapeArgument(FORGE_BINARY) : 'forge';
$finished = $phpBinary .' ' .$forgeBinary .' schedule:finish ' . ProcessUtils::escapeArgument($this->mutexName());
return '(' .$this->command .$redirect .$output .' 2>&1 ' .$delimiter .' ' .$finished .') > '
. ProcessUtils::escapeArgument($this->getDefaultOutput()) .' 2>&1 &';
} | Build a command string with mutex.
@return string | entailment |
public function isDue(Application $app)
{
if (! $this->runsInMaintenanceMode() && $app->isDownForMaintenance()) {
return false;
}
return $this->expressionPasses() && $this->filtersPass($app) && $this->runsInEnvironment($app->environment());
} | Determine if the given event should run based on the Cron expression.
@param \Nova\Foundation\Application $app
@return bool | entailment |
public function emailOutputTo($addresses, $onlyIfOutputExists = false)
{
$this->ensureOutputIsBeingCapturedForEmail();
if (! is_array($addresses)) {
$addresses = array($addresses);
}
return $this->then(function (Mailer $mailer) use ($addresses, $onlyIfOutputExists)
{
$this->emailOutput($mailer, $addresses, $onlyIfOutputExists);
});
} | E-mail the results of the scheduled operation.
@param array|mixed $addresses
@param bool $onlyIfOutputExists
@return $this
@throws \LogicException | entailment |
public function routeNotificationFor($driver)
{
$method = 'routeNotificationFor'. Str::studly($driver);
if (method_exists($this, $method)) {
return call_user_func(array($this, $method));
}
// No custom method for routing the notifications.
else if ($driver == 'database') {
return $this->notifications();
}
// Finally, we will accept only the mail driver.
else if ($driver != 'mail') {
return null;
}
// If the email field is like: [email protected]
if (preg_match('/^\w+@\w+\.local$/s', $this->email) === 1) {
return Config::get('mail.from.address');
}
return $this->email;
} | Get the notification routing information for the given driver.
@param string $driver
@return mixed | entailment |
public function push($filename, LoggerInterface $logger)
{
$key = basename($filename);
$resource = fopen($filename, 'r');
$logger->info(sprintf('Uploading %s to: %s', $filename, $this->getName()));
$this->filesystem->putStream($key, $resource);
return $this->get($key);
} | {@inheritdoc} | entailment |
public function get($key)
{
return new Backup(
$key,
$this->filesystem->getSize($key),
\DateTime::createFromFormat('U', $this->filesystem->getTimestamp($key))
);
} | {@inheritdoc} | entailment |
public function all()
{
$backups = array();
foreach ($this->filesystem->listContents() as $metadata) {
if ('file' !== $metadata['type']) {
continue;
}
$backups[] = new Backup(
$metadata['path'],
$metadata['size'],
\DateTime::createFromFormat('U', $metadata['timestamp'])
);
}
return new BackupCollection($backups);
} | {@inheritdoc} | entailment |
public function handle()
{
$group = $this->input->getArgument('group');
if (is_null($group)) {
return $this->publish();
}
$groups = explode(',', $group);
foreach($groups as $group) {
$this->publish($group);
}
} | Execute the console command.
@return void | entailment |
protected function publish($group = null)
{
$paths = ServiceProvider::pathsToPublish($group);
if (empty($paths)) {
if (is_null($group)) {
return $this->comment("Nothing to publish.");
}
return $this->comment("Nothing to publish for group [{$group}].");
}
foreach ($paths as $from => $to) {
if ($this->files->isFile($from)) {
$this->publishFile($from, $to);
} else if ($this->files->isDirectory($from)) {
$this->publishDirectory($from, $to);
} else {
$this->error("Can't locate path: <{$from}>");
}
}
if (is_null($group)) {
return $this->info("Publishing complete!");
}
$this->info("Publishing complete for group [{$group}]!");
} | Publish the assets for a given group name.
@param string|null $group
@return void | entailment |
protected function publishFile($from, $to)
{
if ($this->files->exists($to) && ! $this->option('force')) {
return;
}
$directory = dirname($to);
if (! $this->files->isDirectory($directory)) {
$this->files->makeDirectory($directory, 0755, true);
}
$this->files->copy($from, $to);
$this->status($from, $to, 'File');
} | Publish the file to the given path.
@param string $from
@param string $to
@return void | entailment |
protected function publishDirectory($from, $to)
{
$this->copyDirectory($from, $to);
$this->status($from, $to, 'Directory');
} | Publish the directory to the given directory.
@param string $from
@param string $to
@return void | entailment |
public function copyDirectory($directory, $destination)
{
if (! $this->isDirectory($directory)) {
return false;
}
if (! $this->files->isDirectory($destination)) {
$this->makeDirectory($destination, 0777, true);
}
$items = new FilesystemIterator($directory, FilesystemIterator::SKIP_DOTS);
foreach ($items as $item) {
$target = $destination .DS .$item->getBasename();
if ($item->isDir()) {
if (! $this->copyDirectory($item->getPathname(), $target)) {
return false;
}
continue;
}
// The current item is a file.
if ($this->files->exists($target) && ! $this->option('force')) {
continue;
} else if (! $this->files->copy($item->getPathname(), $target)) {
return false;
}
}
return true;
} | Copy a directory from one location to another.
@param string $directory
@param string $destination
@param bool $force
@return bool | entailment |
protected function status($from, $to, $type)
{
$from = str_replace(base_path(), '', realpath($from));
$to = str_replace(base_path(), '', realpath($to));
$this->output->writeln('<info>Copied '.$type.'</info> <comment>['.$from.']</comment> <info>To</info> <comment>['.$to.']</comment>');
} | Write a status message to the console.
@param string $from
@param string $to
@param string $type
@return void | entailment |
protected function registerUserResolver()
{
$this->app->bind('Nova\Auth\UserInterface', function ($app)
{
$callback = $app['auth']->userResolver();
return call_user_func($callback);
});
} | Register a resolver for the authenticated user.
@return void | entailment |
protected function registerAccessGate()
{
$this->app->singleton('Nova\Auth\Access\GateInterface', function ($app)
{
return new Gate($app, function() use ($app)
{
$callback = $app['auth']->userResolver();
return call_user_func($callback);
});
});
} | Register the access gate service.
@return void | entailment |
public function publish($package, $source)
{
$destination = $this->publishPath .str_replace('/', DS, "/Packages/{$package}");
$this->makeDestination($destination);
return $this->files->copyDirectory($source, $destination);
} | Publish view files from a given path.
@param string $package
@param string $source
@return void | entailment |
public function publishPackage($package, $packagePath = null)
{
$source = $this->getSource($package, $packagePath ?: $this->packagePath);
return $this->publish($package, $source);
} | Publish the view files for a package.
@param string $package
@param string $packagePath
@return void | entailment |
protected function requestMonkey($apiCall, $payload, $export = false)
{
$payload['apikey'] = $this->config['api_key'];
if ($export) {
$url = $this->dataCenter . $apiCall;
} else {
$url = $this->dataCenter . '2.0/' . $apiCall;
}
$curl = $this->prepareCurl();
$browser = new Browser($curl);
$payload = json_encode($payload);
$headers = array(
"Accept" => "application/json",
"Content-type" => "application/json"
);
$response = $browser->post($url, $headers, $payload);
return $response->getContent();
} | Prepare the curl request
@param string $apiCall the API call function
@param array $payload Parameters
@param boolean $export indicate wether API used is Export API or not
@return array | entailment |
protected function getMigrationPath()
{
$path = $this->input->getOption('path');
// First, we will check to see if a path option has been defined. If it has
// we will use the path relative to the root of this installation folder
// so that migrations may be run for any path within the applications.
if (! is_null($path)) {
return $this->container['path.base'] .DS .$path;
}
return $this->container['path'] .DS .'Database' .DS .'Migrations';
} | Get the path to the migration directory.
@return string | entailment |
public function handle()
{
$this->hasOrCreateDirectory('App');
$this->recursive_copy($this->from_directory , $this->to_directory);
$this->info('ADR architecture has been set');
} | Execute the console command.
@return mixed | entailment |
public static function supported($key, $cipher)
{
$length = mb_strlen($key, '8bit');
return ((($cipher === 'AES-128-CBC') && ($length === 16)) || (($cipher === 'AES-256-CBC') && ($length === 32)));
} | Determine if the given key and cipher combination is valid.
@param string $key
@param string $cipher
@return bool | entailment |
public function encrypt($value)
{
$iv = Str::randomBytes($this->getIvSize());
$value = \openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);
if ($value === false) {
throw new EncryptException('Could not encrypt the data.');
}
$mac = $this->hash($iv = base64_encode($iv), $value);
return base64_encode(json_encode(compact('iv', 'value', 'mac')));
} | Encrypt the given value.
@param string $value
@return string
@throws \Encryption\EncryptException | entailment |
protected function validMac(array $payload)
{
$bytes = Str::randomBytes(16);
$calcMac = hash_hmac('sha256', $this->hash($payload['iv'], $payload['value']), $bytes, true);
return Str::equals(hash_hmac('sha256', $payload['mac'], $bytes, true), $calcMac);
} | Determine if the MAC for the given payload is valid.
@param array $payload
@return bool
@throws \RuntimeException | entailment |
public function buildResult($photos)
{
$result = [];
foreach ($photos as $photoData) {
$result[] = new UserProfilePhotos($photoData);
}
return $result;
} | @param array $result
@return UserProfilePhotos[] | entailment |
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$token = $this->securityContext->getToken();
if (!$token) {
return new Response();
}
$subject = $this->actionManager->findOrCreateComponent($token->getUser(), $token->getUser()->getId());
$entries = $this->timelineManager->getTimeline($subject, [
'page' => 1,
'max_per_page' => $blockContext->getSetting('max_per_page'),
'type' => TimelineInterface::TYPE_TIMELINE,
'context' => $blockContext->getSetting('context'),
'filter' => $blockContext->getSetting('filter'),
'group_by_action' => $blockContext->getSetting('group_by_action'),
'paginate' => $blockContext->getSetting('paginate'),
]);
return $this->renderPrivateResponse($blockContext->getTemplate(), [
'context' => $blockContext,
'settings' => $blockContext->getSettings(),
'block' => $blockContext->getBlock(),
'entries' => $entries,
], $response);
} | {@inheritdoc} | entailment |
public function configureSettings(OptionsResolver $resolver)
{
$resolver->setDefaults([
'max_per_page' => 10,
'title' => null,
'translation_domain' => null,
'icon' => 'fa fa-clock-o fa-fw',
'class' => null,
'template' => '@SonataTimeline/Block/timeline.html.twig',
'context' => 'GLOBAL',
'filter' => true,
'group_by_action' => true,
'paginate' => true,
]);
} | {@inheritdoc} | entailment |
public function setData($data = array())
{
if ($data instanceof JsonableInterface) {
$this->data = $data->toJson($this->jsonOptions);
} else {
$this->data = json_encode($data, $this->jsonOptions);
}
return $this->update();
} | {@inheritdoc} | entailment |
protected function buildDictionary(Collection $models)
{
foreach ($models as $model) {
$morphType = $this->morphType;
if (isset($model->{$morphType})) {
$type = $model->{$morphType};
$key = $model->getAttribute($this->foreignKey);
$this->dictionary[$type][$key][] = $model;
}
}
} | Build a dictionary with the models.
@param \Nova\Database\ORM\Collection $models
@return void | entailment |
protected function getResultsByType($type)
{
$instance = $this->createModelByType($type);
$key = $instance->getKeyName();
$query = $instance->newQuery();
$query = $this->useWithTrashed($query);
return $query->whereIn($key, $this->gatherKeysByType($type)->all())->get();
} | Get all of the relation results for a type.
@param string $type
@return \Nova\Database\ORM\Collection | entailment |
protected function gatherKeysByType($type)
{
$foreign = $this->foreignKey;
//
$results = $this->dictionary[$type];
return BaseCollection::make($results)->map(function($models) use ($foreign)
{
$model = head($models);
return $model->{$foreign};
})->unique();
} | Gather all of the foreign keys for a given type.
@param string $type
@return array | entailment |
public function withTrashed()
{
$this->withTrashed = true;
$this->query = $this->useWithTrashed($this->query);
return $this;
} | Fetch soft-deleted model instances with query
@return $this | entailment |
protected function useWithTrashed(Builder $query)
{
if ($this->withTrashed && $query->getMacro('withTrashed') !== null) {
return $query->withTrashed();
}
return $query;
} | Return trashed models with query if told so
@param \Nova\Database\ORM\Builder $query
@return \Nova\Database\ORM\Builder | entailment |
protected function matchOneOrMany(array $models, Collection $results, $relation, $type)
{
$dictionary = $this->buildDictionary($results);
foreach ($models as $model) {
$key = $model->getAttribute($this->localKey);
if (isset($dictionary[$key])) {
$value = $this->getRelationValue($dictionary, $key, $type);
$model->setRelation($relation, $value);
}
}
return $models;
} | Match the eagerly loaded results to their many parents.
@param array $models
@param \Nova\Database\ORM\Collection $results
@param string $relation
@param string $type
@return array | entailment |
public function save(Model $model)
{
$model->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
return $model->save() ? $model : false;
} | Attach a model instance to the parent model.
@param \Nova\Database\ORM\Model $model
@return \Nova\Database\ORM\Model | entailment |
public function create(array $attributes)
{
$instance = $this->related->newInstance($attributes);
$instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
$instance->save();
return $instance;
} | Create a new instance of the related model.
@param array $attributes
@return \Nova\Database\ORM\Model | entailment |
public function createMany(array $records)
{
$instances = array();
foreach ($records as $record) {
$instances[] = $this->create($record);
}
return $instances;
} | Create an array of new instances of the related model.
@param array $records
@return array | entailment |
public function update(array $attributes)
{
if ($this->related->usesTimestamps()) {
$attributes[$this->relatedUpdatedAt()] = $this->related->freshTimestamp();
}
return $this->query->update($attributes);
} | Perform an update on all the related models.
@param array $attributes
@return int | entailment |
public function join($table, $one, $operator = null, $two = null, $type = 'inner', $where = false)
{
if ($one instanceof Closure) {
$this->joins[] = new JoinClause($type, $table);
call_user_func($one, end($this->joins));
} else {
$join = new JoinClause($type, $table);
$this->joins[] = $join->on(
$one, $operator, $two, 'and', $where
);
}
return $this;
} | Add a join clause to the query.
@param string $table
@param string $one
@param string $operator
@param string $two
@param string $type
@param bool $where
@return $this | entailment |
public function joinWhere($table, $one, $operator, $two, $type = 'inner')
{
return $this->join($table, $one, $operator, $two, $type, true);
} | Add a "join where" clause to the query.
@param string $table
@param string $one
@param string $operator
@param string $two
@param string $type
@return \Nova\Database\Query\Builder|static | entailment |
public function leftJoinWhere($table, $one, $operator, $two)
{
return $this->joinWhere($table, $one, $operator, $two, 'left');
} | Add a "join where" clause to the query.
@param string $table
@param string $one
@param string $operator
@param string $two
@return \Nova\Database\Query\Builder|static | entailment |
public function rightJoinWhere($table, $one, $operator, $two)
{
return $this->joinWhere($table, $one, $operator, $two, 'right');
} | Add a "right join where" clause to the query.
@param string $table
@param string $one
@param string $operator
@param string $two
@return \Nova\Database\Query\Builder|static | entailment |
public function whereNested(Closure $callback, $boolean = 'and')
{
$query = $this->newQuery();
$query->from($this->from);
call_user_func($callback, $query);
return $this->addNestedWhereQuery($query, $boolean);
} | Add a nested where statement to the query.
@param \Closure $callback
@param string $boolean
@return \Nova\Database\Query\Builder|static | entailment |
public function whereExists(Closure $callback, $boolean = 'and', $not = false)
{
$type = $not ? 'NotExists' : 'Exists';
$query = $this->newQuery();
//
call_user_func($callback, $query);
$this->wheres[] = compact('type', 'operator', 'query', 'boolean');
$this->mergeBindings($query);
return $this;
} | Add an exists clause to the query.
@param \Closure $callback
@param string $boolean
@param bool $not
@return $this | entailment |
public function whereDate($column, $operator, $value, $boolean = 'and')
{
return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean);
} | Add a "where date" statement to the query.
@param string $column
@param string $operator
@param int $value
@param string $boolean
@return \Nova\Database\Query\Builder|static | entailment |
public function whereDay($column, $operator, $value, $boolean = 'and')
{
return $this->addDateBasedWhere('Day', $column, $operator, $value, $boolean);
} | Add a "where day" statement to the query.
@param string $column
@param string $operator
@param int $value
@param string $boolean
@return \Nova\Database\Query\Builder|static | entailment |
public function whereMonth($column, $operator, $value, $boolean = 'and')
{
return $this->addDateBasedWhere('Month', $column, $operator, $value, $boolean);
} | Add a "where month" statement to the query.
@param string $column
@param string $operator
@param int $value
@param string $boolean
@return \Nova\Database\Query\Builder|static | entailment |
public function whereYear($column, $operator, $value, $boolean = 'and')
{
return $this->addDateBasedWhere('Year', $column, $operator, $value, $boolean);
} | Add a "where year" statement to the query.
@param string $column
@param string $operator
@param int $value
@param string $boolean
@return \Nova\Database\Query\Builder|static | entailment |
protected function addDynamic($segment, $connector, $parameters, $index)
{
$bool = strtolower($connector);
$this->where(Str::snake($segment), '=', $parameters[$index], $bool);
} | Add a single dynamic where clause statement to the query.
@param string $segment
@param string $connector
@param array $parameters
@param int $index
@return void | entailment |
public function groupBy()
{
foreach (func_get_args() as $arg) {
$this->groups = array_merge((array) $this->groups, is_array($arg) ? $arg : [$arg]);
}
return $this;
} | Add a "group by" clause to the query.
@param array|string $column,...
@return $this | entailment |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.