/** * Initialize the Laravel framework. */ private function initialize() { // Store a reference to the database object // so the database connection can be reused during tests $oldDb = null; if ($this->app['db'] && $this->app['db']->connection()) { $oldDb = $this->app['db']; } // The module can login a user with the $I->amLoggedAs() method, // but this is not persisted between requests. Store a reference // to the logged in user to simulate this. $loggedInUser = null; if ($this->app['auth'] && $this->app['auth']->check()) { $loggedInUser = $this->app['auth']->user(); } $this->app = $this->kernel = $this->loadApplication(); $this->app->make('Illuminate\\Contracts\\Http\\Kernel')->bootstrap(); // Set the base url for the Request object $url = $this->app['config']->get('app.url', 'http://localhost'); $this->app->instance('request', Request::createFromBase(SymfonyRequest::create($url))); if ($oldDb) { $this->app['db'] = $oldDb; Model::setConnectionResolver($this->app['db']); } // If there was a user logged in restore this user. // Also reload the user object from the user provider to prevent stale user data. if ($loggedInUser) { $refreshed = $this->app['auth']->getProvider()->retrieveById($loggedInUser->getAuthIdentifier()); $this->app['auth']->setUser($refreshed ?: $loggedInUser); } $this->module->setApplication($this->app); }
function it_should_run(Application $application, ApiValidator $validator, IApiControllerGenerator $apiControllerGenerator) { $application->make('Jdecano\\Api\\ApiValidator')->willReturn($validator); $validator->validate()->willReturn(null); $application->make('Jdecano\\Api\\IApiControllerGenerator')->willReturn($apiControllerGenerator); $apiControllerGenerator->make('User')->willReturn(null); }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->app = $this->getLaravel(); $this->config = $this->app->make('config'); $options = $this->processOptions(); $options['extensions'] = 'php'; $options['colors'] = $this->getOutput()->isDecorated(); $command = $this->buildCommand($this->binPath . '/phpcs', $options); $this->info('Running PHP Code Sniffer...'); $this->info($command); passthru($command, $exitCode); $this->info('Done.'); if (!$this->option('no-interaction') && $exitCode !== 0) { $answer = $this->ask('Try to automatically fix issues? [Yn]', 'y'); if (strtolower($answer) == 'n') { $this->info('Declined fixes.'); return $exitCode; } // Code beautifier takes all the same options (except for colors). unset($options['colors']); $command = $this->buildCommand($this->binPath . '/phpcbf', $options); $this->info('Running PHP Code Beautifier...'); $this->info($command); passthru($command, $exitCode); $this->info('Done.'); } return $exitCode; }
/** * Instanciate and execute all functions as blade extends * * @param Application $app The current application */ public static function attach(Application $app) { /** @var \Illuminate\View\Compilers\BladeCompiler $blade */ $blade = $app->make('blade.compiler'); $config = $app->make('config'); $class = new static(); if (!isset($class->directivesFile)) { $class->directivesFile = __DIR__ . '/../directives.php'; } $blacklist = isset($class->blacklist) ? $class->blacklist : $config->get('blade_extensions.blacklist'); $directives = isset($class->directives) ? $class->directives : $app->make('files')->getRequire($class->directivesFile); $overrides = isset($class->overrides) ? $class->overrides : $config->get('blade_extensions.overrides', []); foreach ($overrides as $method => $override) { if (!isset($directives[$method])) { continue; } if (isset($override['pattern'])) { $directives[$method]['pattern'] = $override['pattern']; } if (isset($override['replacement'])) { $directives[$method]['replacement'] = $override['replacement']; } } foreach ($directives as $name => $directive) { $method = 'directive' . ucfirst($name); if (is_array($blacklist) && in_array($name, $blacklist, true) || !method_exists($class, $method)) { continue; } $blade->extend(function ($value) use($class, $method, $directive, $app, $blade) { return $class->{$method}($value, $directive['pattern'], $directive['replacement'], $app, $blade); }); } }
public function process(LocalezeRequest $request) { $username = $this->app->make('config')->get('laravel-localeze::username'); $password = $this->app->make('config')->get('laravel-localeze::password'); $response = $this->soap->query(["origination" => $this->setupOrigination($username, $password), "transId" => 1, "serviceId" => $this->serviceId, "elements" => $request->elements, "serviceKeys" => $request->serviceKeys]); return new LocalezeResponse($response); }
public function testRegister() { $provider = new InlinerServiceProvider($this->app); $provider->register(); $this->assertTrue($this->app->bound('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner')); $this->assertInstanceOf('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner', $this->app->make('Chromabits\\Illuminated\\Contracts\\Inliner\\StyleInliner')); }
public function __construct(DatabaseManager $db, Application $app, Config $config) { $this->app = $app; $this->config = $config; $this->db = $db; $this->roleModel = $this->app->make($this->config->get('laravel-rbac.roleModel')); }
/** * @param $method * @param $resourceName * @param $uri * @param $inputs * @param $key * @param $signature * @throws APIException * @return mixed */ public function call($method, $resourceName, $uri, $inputs, $key, $signature) { // Get resource data containing: action and arguments $resourceData = ResourceData::make($uri, $method); // If can't get resource by name from the respoitory throw an exception because resource doesn't exists if (!($resource = $this->app->make('Lifeentity\\Api\\ResourceRepository')->getByName($resourceName))) { throw new APIException("We can't find this resource in our application: {{$resourceName}}"); } // Get application by the api key if (!($application = $this->app->make('Lifeentity\\Api\\APIApplication')->byApiKey($key)->first())) { throw new APIPermissionException("The api key is incorrect."); } // Check signature if (!$application->checkSignature($signature)) { throw new APIPermissionException("The api signature is incorrect."); } // Check if this application has permissions to access this resource and action if (!$application->checkPermissions($resource->name(), $resourceData->getAction())) { throw new APIPermissionException("You don't have permissions to request `{$resourceData->getAction()}` on this resource: {{$resource->name()}}"); } // Set inputs for this resource $resource->setInputs(new InputData($inputs)); // Now every thing is ready, call this resource return $resource->call($resourceData); }
/** * Execute the console command. * * @throws \Bmartel\Transient\Exception\InvalidObjectTypeException * @return mixed */ public function fire() { // If user provided a class as an argument, // ensure its a valid class which implments \Bmartel\Transient\TransientPropertyInterface. if ($class = $this->argument('modelClass')) { // Parse the class $model = $this->inputParser->parse($class); $modelType = $this->app->make($model); if (!$modelType instanceof TransientPropertyInterface) { throw new InvalidObjectTypeException('Class does not implement \\Bmartel\\Transient\\TransientPropertyInterface'); } } // If user provided property options, parse them into an array for querying. if ($properties = $this->option('properties')) { $transientProperties = $this->inputParser->parseProperties($properties); } $result = null; // Determine what parameters to base the transient removal on. if (isset($transientProperties) && isset($modelType)) { $result = $this->transient->deleteByModelProperty($modelType, $transientProperties); } elseif (isset($modelType)) { $result = $this->transient->deleteByModelType($modelType); } elseif (isset($transientProperties)) { $result = $this->transient->deleteByProperty($transientProperties); } else { $result = $this->transient->deleteAll(); } $propertiesName = str_plural('property', $result); // Report the result of the command $this->info("All done! Removed {$result} transient {$propertiesName}."); }
/** * @param Post $post * * @return string */ public function renderFromPost(Post $post) { $post = $this->app->make('MyBB\\Core\\Presenters\\Post', [$post]); $message = $post->content; // TODO: MarkdownQuoteRenderer return "> {$message}\n\n"; }
/** * @param $command * @return mixed */ public function execute($command) { $validator = $this->commandTranslator->toCommandValidator($command); if (class_exists($validator)) { $this->app->make($validator)->validate($command); } return $this->commandBus->execute($command); }
/** * @test * @covers Cocur\Slugify\Bridge\Laravel\SlugifyServiceProvider::register() */ public function registerRegistersTheServiceProvider() { $this->provider->register(); // the service provider is deferred, so this forces it to load $this->app->make('slugify'); $this->assertArrayHasKey('slugify', $this->app); $this->assertInstanceOf('Cocur\\Slugify\\Slugify', $this->app['slugify']); }
/** * @param $contents */ private function write($contents) { $config = $this->app->make('Illuminate\\Config\\Repository'); $routesFile = $config->get('api::paths.routes_file'); $handler = fopen($routesFile, 'a'); fwrite($handler, $contents); fclose($handler); }
/** * Constructor. * * @param Application $app */ public function __construct(Application $app) { $this->app = $app; $this->httpKernel = $this->app->make('Illuminate\\Contracts\\Http\\Kernel'); $this->httpKernel->bootstrap(); $this->app->boot(); parent::__construct($this); }
/** * Handle the event. * * @param $event * * @return mixed */ public function handle($event) { // Check to see if a handler exists for this event // If the handler does exist, resolve it from the IoC container and call it's fire() method if ($handler = $this->getHandler($event)) { $this->app->make($handler)->fire($event); } }
/** * @param \Illuminate\Foundation\Application $app */ public function boot($app) { $this->urlRepository = $app->make('CoandaCMS\\Coanda\\Urls\\Repositories\\UrlRepositoryInterface'); $this->user = $app->make('CoandaCMS\\Coanda\\Users\\UserManager'); $this->user->updateLastSeen(); $this->loadAttributes(); $this->loadSearchProvider(); $this->loadHistoryListener(); }
/** * @return \MyBB\Core\Moderation\ModerationInterface[] */ public function moderations() { $moderations = $this->moderations->getForContent(new Post()); $decorated = []; $presenter = $this->app->make('autopresenter'); foreach ($moderations as $moderation) { $decorated[] = $presenter->decorate($moderation); } return $decorated; }
/** * Returns the model set in auth config * * @return mixed Instantiated object of the 'auth.model' class */ public function model() { if (!$this->model) { $this->model = $this->app->make('config')->get('auth.model'); } if ($this->model) { return $this->app->make($this->model); } throw new \Exception("Wrong model specified in config/auth.php", 639); }
/** * Start the application * * @return void * * @throws ApplicationRunningException If an application has already been started / initialised and running */ public function startApplication() { if ($this->hasApplicationBeenStarted()) { throw new ApplicationRunningException(sprintf('Application has already been started. Please stop the application, before invoking start!')); } $this->refreshApplication(); if (!$this->factory) { $this->factory = $this->app->make(Factory::class); } }
/** * Execute all registered decorators * * @param object $command * @return null */ protected function executeDecorators($command) { foreach ($this->decorators as $className) { $instance = $this->app->make($className); if (!$instance instanceof CommandBus) { $message = 'The class to decorate must be an implementation of Laracasts\\Commander\\CommandBus'; throw new InvalidArgumentException($message); } $instance->execute($command); } }
/** * Return a parser instance from its name. * * @param string $name * @return \Kowali\Formatting\Parsers\ParserContract */ public function getParserInstance($name) { if (!array_key_exists($name, $this->parsers)) { throw new Exceptions\FormatterNotFoundException("No formater found for {$name}"); } $parser = $this->parsers[$name]; if (is_string($parser)) { $parser = $this->app->make($parser); } return $parser; }
/** * Setup the application environment. * * @param \Illuminate\Foundation\Application $app * @return void */ protected function getEnvironmentSetUp($app) { $config = $app->make('config'); $config->set('cache.driver', 'array'); $config->set('database.default', 'sqlite'); $config->set('database.connections.sqlite', ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '']); $config->set('mail.driver', 'log'); $config->set('session.driver', 'array'); #$app->call('command.migrate'); $app->make('mailer')->pretend(true); }
/** * Execute all registered decorators * * @param object $query * * @return null */ protected function executeDecorators($query) { foreach ($this->decorators as $className) { $instance = $this->app->make($className); if (!$instance instanceof QueryBus) { $message = 'The class to decorate must be an implementation of SMGladkovskiy\\Querier\\QueryBus'; throw new InvalidArgumentException($message); } $instance->executeQuery($query); } }
public function fields() { $profileFields = $this->getWrappedObject()->getProfileFields()->get(); $profileFields = $profileFields->sortBy('display_order'); $decorated = []; $decorator = $this->app->make('autopresenter'); foreach ($profileFields as $profileField) { $decorated[] = $decorator->decorate($profileField); } return $decorated; }
function it_can_trigger_decorators_before_calling_the_handler(Application $app, CommandStub $command, CommandTranslator $translator, CommandHandlerStub $handler) { $translator->toCommandHandler($command)->willReturn('CommandHandler'); $app->make('CommandHandler')->willReturn($handler); $handler->handle($command)->shouldBeCalled(); // If we specify a decorator before calling execute(), that decorator should be // resolved out of the container and executed first. $decorator = 'spec\\Laracasts\\Commander\\CommandBusDecoratorStub'; $app->make($decorator)->shouldBeCalled()->willReturn(new CommandBusDecoratorStub()); $this->decorate($decorator)->execute($command); }
/** * @param Post $post * * @return string */ public function renderFromPost(Post $post) { $post = $this->app->make('MyBB\\Core\\Presenters\\Post', [$post]); $message = $post->content; $slapUsername = $post->author->name; $message = preg_replace('#(>|^|\\r|\\n)/me ([^\\r\\n<]*)#i', "\\1* {$slapUsername} \\2", $message); $slap = trans('parser::parser.slap'); $withTrout = trans('parser::parser.withTrout'); $message = preg_replace('#(>|^|\\r|\\n)/slap ([^\\r\\n<]*)#i', "\\1* {$slapUsername} {$slap} \\2 {$withTrout}", $message); $message = preg_replace("#\\[attachment=([0-9]+?)\\]#i", '', $message); return "[quote='" . e($post->author->name) . "' pid='{$post->id}' dateline='" . $post->created_at->getTimestamp() . "']\n{$message}\n[/quote]\n\n"; }
/** * Define environment setup. * * @param \Illuminate\Foundation\Application $app * * @return void */ protected function getEnvironmentSetUp($app) { // Set Testing Configuration $app['config']->set('database.default', 'testbench'); $app['config']->set('database.connections.testbench', ['driver' => 'sqlite', 'database' => __DIR__ . '/_data/database.sqlite', 'prefix' => '']); $app['config']->set('mail.pretend', true); $app['config']->set('mail.from', ['from' => '*****@*****.**', 'name' => null]); // Temporary Repository Bindings // Bind the Transaction Repository $app->bind('SRLabs\\Groundwork\\Repositories\\Transactions\\TransactionRepositoryInterface', function ($app) { return new EloquentTransactionRepository(new Transaction(), $app->make('cache.store'), $app->make('events'), $app->make('log')); }); }
/** * Constructor. * * @param Application $app */ public function __construct(Application $app) { $this->app = $app; $this->config = $app->make('config'); $this->cache = $app->make('cache'); $this->request = $app->make('request'); $this->localeModel = $app->make($this->getConfigLocaleModel()); $this->translationModel = $app->make($this->getConfigTranslationModel()); // Set the default locale to the current application locale $this->setLocale($this->getConfigDefaultLocale()); // Set the cache time from the configuration $this->setCacheTime($this->getConfigCacheTime()); }
/** * Attempt to refresh the defined attachments on a particular model. * * @throws InvalidClassException * * @param string $class * @param string $attachments */ public function refresh($class, $attachments) { if (!method_exists($class, 'hasAttachedFile')) { throw new InvalidClassException("Invalid class: the {$class} class is not currently using Stapler.", 1); } $models = $this->app->make($class)->all(); if ($attachments) { $attachments = explode(',', str_replace(', ', ',', $attachments)); $this->processSomeAttachments($models, $attachments); } else { $this->processAllAttachments($models); } }
/** * Magic method to call widget instances. * * @param string $signature * @param array $parameters * @return mixed */ public function __call($signature, $parameters) { $parameters = $this->flattenParameters($parameters); $className = studly_case($signature); $namespace = $this->determineNamespace($className); $widgetClass = $namespace . '\\' . $className; $widget = $this->app->make($widgetClass); if ($widget instanceof Widget === false) { throw new InvalidWidgetException(); } $widget->registerParameters($parameters); return $widget->handle(); }