setlocale and getlocale in lumen 5.6 - php

I was trying to localize my application and in the middleware, I am getting the locale from the request object. Now I need to access this outside the controller while running a job.
As from the documentation, I can see that the app() can hold this data. But app()->setLocale() and app()->getLocale() is not working for me in lumen 5.6.
Ant help will be much appreciable.

Finally, I found the answer. There is a translator object in the framework and you have to use the following code to set a locale
app('translator')->setLocale($locale);
and to get a locale in anywhere in the application using
app('translator')->getLocale();

Related

Laravel 5.3 Slack integration

I need to get access to Slack's Event API from my Laravel 5.3 application. I have installed vluzrmos's package from GitHub, but I can't get it to work properly. I ran through all the steps in the installation, but when I try to do SlackUser::lists() in my Controller I get an error like this:
Non-static method Vluzrmos\SlackApi\Contracts\SlackUser::lists() cannot be called statically, assuming $this from incompatible context.
Could you help? Thanks
Assuming you have configured the providers & aliases correctly (in config/app.php), you need to add:
use SlackUser;
to the top of your class, and then call:
SlackUser::lists();
Please post your usage of SlackUser::lists(); if this doesn't solve your issue.

How to call CLI from a controller on ZF2

Our system is written in ZF2. I'm trying to call a ZFTool console command programmatically, if there's a way to do that. All documentation I have found so far points to call a Controller action from CLI, instead of CLI programmatically from a controller.
If there's no default way to do this, a workaround would be fine as long as it's testable. Thanks in advance.
PS: I'm new to ZF2, I come from Laravel where you have a facade class to execute commands from a controller class Artisan::call('my:command').

Using Laravel Facades with UserFrosting

Have recently starting using UserFrosting to as part of a project and I'm having some problems using Facades within UserFrosting and would appreciate some help if possible.
I am attempting to use the File facade from within a UserFrosting controller to create a folder on the local filesystem using the following code
use Illuminate\Support\Facades\File;
......
$directoryCreated = File::makeDirectory($directoryPath);
However at runtime i get the following error
PHP Fatal error: Call to a member function makeDirectory() on null in /var/www/test-app/userfrosting/vendor/illuminate/support/Facades/Facade.php on line 210
It seems that the UserFrosting app does not recognise the File facade (or any other facacde - i also tried Storage) and it has not been registered with the app.
Is it possible to use the facade classes with UserFrosting?
If so do I have to register them somewhere within the UserFrosting app config?
Any direction pointers would be greatly appreciated.
Thanks in advance!
From the Facade documentation:
Laravel "facades" serve as "static proxies" to underlying classes in the service container...
So, it looks like Laravel's facades depend on Laravel's service container. You can read more about how Laravel sets up the default facades here: https://www.sitepoint.com/how-laravel-facades-work-and-how-to-use-them-elsewhere/#how-laravel-aliases-the-facades
Unfortunately, UserFrosting does not use Laravel's service container. Rather, it uses Slim, which has its own service container. In Slim v2 (which UF 0.3.1 uses), the Slim application itself is the service container.
You can define services for UF in initialize.php. So, you might try something like:
$app->filesystem = new \Illuminate\Filesystem\Filesystem();
Then later, you can use the filesystem service like:
$app->filesystem->makeDirectory($directoryPath);
You could try to use Slim's container to allow the Facade to resolve its accessor (it will use array access on the container to resolve it). You would have to make sure that the binding the facade uses exists. You can take a look at the Service Provider that corresponds to the service you want to use to know how its setting up the binding.
The File facade is accessing the binding 'files' (Illuminate\Filesystem\Filesystem).
\Illuminate\Support\Facades\Facade::setFacadeApplication($container);
\Illuminate\Support\Facades\File::makeDirectory(...);
Its worth a shot, but its mostly the binding that is being resolved that is important.

Luracast Restler in CodeIgniter

I am trying to put in Restler as part of my CI Library. I wonder if this is possible with Restler because I'm getting Server Error. Should I just separate Restler folder to my CI folder (which works right now)?
I want to integrate it to my CI so I can access the models e.g for authentication, getting user data...etc. instead of creating another config file and model classes.
I have invested a lot of time trying to find some workaround to make Restler work with CI but no luck.
Thanks!
I don't think there's an easy way to integrate Restler into CI, you would have to totally rework the CI routing class.
I would recommend that you instead go with Phil Sturgeon's excellent REST server for CI, which is a pretty simple to put into your existing CI application.

Codeigniter use Codeigniter models from outside script

There was a great post that applied to CI 1.7.2 about using CI models outside CI. It worked like a charm.
http://codeigniter.com/wiki/Calling_CI_models_from_outside_script/
Then I upgraded to 2.0 and the code written in the above post was no longer applicable. I am having a hard time trying to get this to work in 2.0. The Config.php file is no longer in the libraries folder in addition to the Language.php and Model.php files.
Does anyone have an idea of how to port this to 2.0 ?
I only need the models. I was using them in an incoming email extension to our application and using the CI models that we had written saved a lot of time. Any help would be greatly appreciated. . .
I have no idea what this package does, or what issues you're having (forgot to say?), but in 2.0 you need to be looking in the "core" directory rather than the "codeigniter" directory.

Categories