I'm digging through the Laravel Session module code, to learn how the file driver works. What confuses me is where / how the session ID is stored / persisted. I cannot find anywhere where the class Illuminate\Session\Store is instantiated with an $id (third parameter). What am I missing?
See https://github.com/laravel/framework/blob/master/src/Illuminate/Session/Store.php
Store is instantiated in this class https://github.com/laravel/framework/blob/master/src/Illuminate/Session/SessionManager.php
Related
I'm trying to extend an existing application without modifying its source code.
The application has a named route called wizard-add.
Is there a way to register \MyPackage\MyMiddleware with the existing route?
I tried attaching it via Route::getRoutes()->getByName('wizard-add')->middleware(\MyPackage\MyMiddleware::class); but since packages are registered before the routes are read, Route::getRoutes() returns an empty collection.
Thank you!
Since I didn't find a way to solve this, I extended the app's controllers and put my logic inside.
namespace MyPackage\Controllers;
use App\Controllers\WizardController;
class MyPackageWizardController extends WizardController { ... }
and then in my service provider's register() method:
$this->app->bind(WizardController::class, MyPackageWizardController::class);
So everytime the app attempts to instantiate WizardController, it instantiates MyPackageWizardController instead. I don't know if there are any drawbacks but so far this has been working perfectly for me.
I started with Laravel 7 a few weeks ago. It happened to me multiple times that after reading about a topic on the Laravel website, I wanted to check the details of a function, for example:
Illuminate\Support\Facades\Route::group()
So I went to the Laravel API, and could find the Route facade, but not the group function.
What am I doing wrong? Where do you check for example the exact signature of a function?
Thanks!
The method group in Route::group() is inherited from another class, RegistrarGroup.
See the docblock method in the source file, vendor/laravel/framework/src/Illuminate/Support/Facades/Route.php:
#method static \Illuminate\Routing\Router|\Illuminate\Routing\RouteRegistrar group(\Closure|string|array $attributes, \Closure|string $routes)
so, this is what you look for in the API documentation:
https://laravel.com/api/7.x/Illuminate/Contracts/Routing/Registrar.html#method_group
That is because a Facade, by definition, is only an 'interface' to the methods exponed by another object, so you will not find the actual methods available by visiting the facade code.
Usually you can find the actual class that a facade resolves to (when not mocked) by checking the docblock in the source code and navigate to that class.
A very useful tool to overcome this problem and provide autocompletion (and inspection) for facades on your IDE is the package https://github.com/barryvdh/laravel-ide-helper
I am able to successfully record changes to classes, and return what has been changed (not including many-to-many). However, I am unable to revert back any change using the built-in new transitionTo() method.
I get the following error on all classes:
Expected Auditable type App\XYZ, got XYZ instead
I have all of my morphable classes (which are all I am using for tracking audits) attached correctly within AppServiceProvider in a morphmap like so:
\Illuminate\Database\Eloquent\Relations\Relation::morphMap([
'Employee' => \App\Employee::class,
];
All classes work correctly with all other Laravel morphTo methods.
The auditable code looks like it is tripping the error in line 467 of the Auditable class:
if (!$this instanceof $audit->auditable_type) {}
It doesn't appear to be looking to the map for any of the morphed classes. Or, I could be totally missing something of course!
Any help on how to get this to work using the auditing method -- has anyone gotten this to work with standard morph classes? (It will of course revert the class manually by looping on the old fields and saving the object).
Using Laravel 5.5 and the latest version (5.0) of Laravel-Auditing.
Sent a note to the developer - this was in fact a bug. Vendor code was needed to include morphMapped objects.
Developer at Laravel Auditing responded within an hour and had a fix a few hours later. I can confirm this is now functioning as expected. Outstanding support.
When a 404 override caused by nonexistent action (only action, not controller) is being handled by Codeigniter, the datamapper fails to load, thus causing any database functionality impossible.
My usage case is: I want to register data about who/when/where encountered a 404 on the site.
Version info: codeigniter 2.1.0; datamapper 1.8.2
I figured the problem is in the way datamapper "extends" the db class. The file that defines the name of the db class to use is only included once, thus when the codeigniter object is re-constructed, the name remains un-overridden. To fix this, at your own expense, you have to hack the datamapper files.
File "application/third_party/datamapper/system/DB.php" after line 143:
// load Datamappers DB interceptor class
require_once(APPPATH.'third_party/datamapper/system/DB_driver.php');
put these lines:
// HACK to make datamapper load correctly after codeigniter has been reconstructed in
// cases of invalid actions (404 overrides)
$driver = 'DM_DB_Driver';
I'm using Symfony 1.4 and Doctrine 1.2. I need to get the session ID inside an action.
I'm using doctrine session storage and that works fine. I'm also using sfDoctrineGuardPlugin and am able to get and set session variables in the user according to recommended practice, using code like this:
$this->getUser()->setAttribute('variable_name', $value);
$value = $this->getUser()->getAttribute('variable_name');
But how do I get the session id of the current user?
It seems like you can't access the sfStorage from the user object. The sfSessionStorage stores the user data in the session...
So the only way I currently see is calling the 'native' session_id().
If you want to it perfectly you should extends the sfSessionStorage adding a method to retrieve the session id. Then assign this storage to the user, and you would be able to call $this->getUser()->getStorage()->getSessionId();.