Phalcon 4.0 setting up Session - session

I am trying to make an session in my phalcon project, version 4.0 but I am getting this error while creating an session.
Class 'Phalcon\Session\Adapter\Files' not found
$di->setShared('session',function(){
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
If someone knows a method in which I can create an session please let me know!

this seemed to work for me
$di->setShared('session',function(){
$session = new Phalcon\Session\Manager();
$files = new Phalcon\Session\Adapter\Stream( [
'savePath' => '/tmp',
]);
$session->setAdapter($files)->start();
return $session;
});

Phalcon\Session\Adapter\Files class was renamed to Phalcon\Session\Adapter\Stream in Phalcon 4.0.0
check the documentation for other issues you could run into if you recently upgraded
if you copied that code from the documentation then its for Phalcon 3.4.x

Related

why Call to undefined method Srmklive\PayPal\Services\PayPal::setExpressCheckout()

i try implement the paypal pay on my project, i using the srmklive/paypal v3 and and stamen giving this error
Call to undefined method Srmklive\PayPal\Services\PayPal::setExpressCheckout()
use Srmklive\PayPal\Services\PayPal as PayPalClient;
$provider = new PayPalClient;
$response = $provider->setExpressCheckout($data);
$response = $provider->setExpressCheckout($data, true);
return redirect($response['paypal_link']);
tried to look for ams solutions so far nothing if someone can help me thank you
may be due to mismatch of version.
try using this in composer.json
srmklive/paypal: "~1.0"

Laravel + Twilio SDK: Class 'Services_Twilio_Twiml' not found

I new to Laravel and newer to Twilio.
I have a working laravel 5.4 server installed w/ Composer. I installed the Twilio SDK in the root directory of my Twilio project w/ Composer.
I receive the following error when loading some basic code from the "Getting Started with Twilio and the Laravel framework for PHP" tutorial.
Class 'Services_Twilio_Twiml' not found
I really don't know what to do now.
Does anyone have any suggestions?
Route::match(array('GET', 'POST'), '/incoming', function()
{
$twiml = new Services_Twilio_Twiml();
$twiml->say('Hello - your app just answered the phone.
Neat, eh?', array('voice' => 'alice'));
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
});
Twilio developer evangelist here.
I think you're trying to call the old version of the Twilio PHP library there.
To use TwiML with version 5 of the PHP library you would use the Twilio\Twiml object, like this:
Route::match(array('GET', 'POST'), '/incoming', function()
{
$twiml = new Twilio\Twiml;
$twiml->say('Hello - your app just answered the phone.
Neat, eh?', array('voice' => 'alice'));
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
});
There are a bunch of Twilio and Laravel tutorials available here that might help you too.
Let me know if that helps at all.

Dynamic callback url laravel

I tried to make my callback url dynamic because I'm configuring socialite in a multi auth system. I tried to use the socialiteproviders/manager as below:
$clientId = env($provider."_client_id");
$clientSecret = env($provider."_client_secret");
$redirectUrl = "the url i want";
$config = new \SocialiteProviders\Manager\Config($clientId,$clientSecret,$redirectUrl);
return Socialite::with($provider)->setConfig($config)->redirect();
but it says:
Call to undefined method Laravel\Socialite\Two\FacebookProvider::setConfig()
when trying to login with facebook.
Can someone please help me? Thank you.
I could reproduce and found a solution. The code you provided was outdated, and I found other instances of it here: https://laravel.io/forum/07-28-2016-dynamic-callback-url-laravel-socialite
By default, Socialite will get the provider config in services.php by passing the $providerName = facebook
So your code now becomes:
// The services.php config will return null, fix it by using: strtoupper()
$clientId = env(strtoupper($provider . "_client_id"));
$clientSecret = env(strtoupper($provider . "_client_secret"));
$redirectUrl = "/the-url-i-want";
// ->redirect() acts as a closure, without it, you'll get an error like:
// "Serialization of 'Closure' is not allowed"
$user = Socialite::with($provider)->redirect();
return redirect()->to($redirectUrl)->with(['user', $user]);
More info on redirecting with session data:
https://laravel.com/docs/6.x/redirects#redirecting-with-flashed-session-data

How to register a user via json from ionic app to symfony2

How can I register a user from an ionic app via json at my backend.
My backend is build with symfony2 and fos userbundle.
I implemented authentication/authorization via json web token which works seamless.
But I don't know how to register a user and write him through my user entity to the database.
Can anyone give my a approach on hopw to realize this or much better anyone has a little example for this issue.
thanks in advance
bambamboole
edit:
i've created a repository # github:
https://github.com/bambamboole/symfony-jwt
Here a simple example to register a user from an AJAX call using FOSRest and FOSUser bundles :
public function postUserAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$parameters = $request->request->all();
$user = new User();
$user->setUsername($parameters["username"]);
$user->setEmail($parameters["mail"]);
$user->setPlainPassword($parameters["password"]);
$user->setEnabled(false);
$user->setFirstname($parameters["firstname"]);
$user->setLastname($parameters["lastname"]);
$tokenGenerator = $this->get('fos_user.util.token_generator');
$token = $tokenGenerator->generateToken();
$user->setConfirmationToken($token);
$em->persist($user);
$em->flush();
$this->get('fos_user.mailer')->sendConfirmationEmailMessage($user);
$view = View::create()
->setStatusCode(200)
->setData($user);
return $this->get('fos_rest.view_handler')->handle($view);
}
Hope it will help you.

How do get Phalcon Session from the DI in a standalone class

I have a class that I have created in my Phalcon project. I want to get the session service from the DI so that I can check if a variable is set.
I have tried:
$di = Phalcon\DI::getDefault();
echo $di->get("session")->get("user_id");
exit;
However it comes back saying A session had already been started - ignoring session_start()
use Phalcon\Mvc\Model\Resultset\Simple, Phalcon\Mvc\User\Plugin;
class JsonReturnObject extends Plugin
My session service is registered like this:
<?php
use Phalcon\Mvc\View;
use Phalcon\DI\FactoryDefault;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\Model\Metadata\Memory as MetaData;
use Phalcon\Session\Adapter\Files as SessionAdapter;
use Phalcon\Flash\Session as FlashSession;
use Phalcon\Events\Manager as EventsManager;
//setup the dependency injection
$di = new FactoryDefault();
//setup the session
$di->set('session', function() {
$session = new SessionAdapter();
$session->start();
return $session;
});
Any help would be appreciated.
Try registering the session as not a shared component like this:
$di->set(
'session',
function () {
$session = new \Phlacon\Session\Adapter\Files();
$session->start();
return $session;
}
);
Note the third parameter is not true on the $di->set()
Alternatively use $di->set() instead of $di->setShared()
The fix was to set the service to shared using setShared.

Resources