How to use Facebook PHP SDK with Zend Framework 2 - facebook-php-sdk

I want to be able to use the Facebook PHP SDK with the new ZEND Framework 2 platform. How to do it?
Zend Framework 2 is quite different as previous version ZF1.
When I try the standard PHP in the main application controller IndexController':
require_once("facebook.php");
class IndexController extends AbstractActionController
{
public $facebook;
public function __construct() {
$this->facebook = new Facebook(array(
'appId' => 'appId',
'secret' => 'secret_key'
));
}
/*
...
*/
}
I get following error: Fatal error: Cannot redeclare class Facebook in /../module/Application/src/Application/Controller/Facebook.php on line 160

According to that error message the problem is that you now have two classes called Facebook in that namespace. Try ensuring you only have one class called Facebook.

I had the same problem when I needed to include the Facebook SDK in a ZF2 application.
You don't need to use any additional modules for FB SDK integration. The trick is to include the facebook library with ClassMapAutoloader, e.g.:
array(
'Facebook' => 'vendor/FB/facebook.php',
)
Detailed instructions are here

I can't help you specifically on the difference between ZF1 & ZF2 but a simple search in google gave me this result, I think because ZF autoloads classes and you tried to require it again they are in conflict.

Related

phpunit testable livewire fails with Undefined array key "fingerprint"

When trying a test that came with Laravel and Jetstream/Livewire libraries, I get an undefined array key "fingerprint" error message
Undefined array key "fingerprint"
at vendor/livewire/livewire/src/Testing/TestableLivewire.php:181
public function pretendWereSendingAComponentUpdateRequest($message, $payload)
{
$result = $this->callEndpoint('POST', '/livewire/message/'.$this->componentName, [
'fingerprint' => $this->payload['fingerprint'],
'serverMemo' => $this->payload['serverMemo'],
'updates' => [['type' => $message, 'payload' => $payload]],
]);
This happens for any out of the box feature tests that ship with Laravel9 with Jetstream when used against my project.
Here is one example that fails at the Livewire::test.... line.
The user is created and authenticating without issue and confirmed in other phpunit tests.
class BrowserSessionsTest extends TestCase
{
use RefreshDatabase;
public function test_other_browser_sessions_can_be_logged_out(): void
{
$this->actingAs($user = User::factory()->create());
Livewire::test(LogoutOtherBrowserSessionsForm::class)
->set('password', $user->password)
->call('logoutOtherBrowserSessions')
->assertSuccessful();
}
}
I stood up a fresh Laravel 9 project which works and began inserting various areas from my project into the fresh project as a way of hopefully identifying the issue. Session parameters, events, migrations, factories, models, were not the issue as it continued to work in the fresh project.
One thing I noticed is that the generic routes are not accepted in my project within he test cases. I have to insert 'https://realtor.host' in front of every test route (e.g. $response = $this->get('https://realtor.host/register');
I was curious if it was not evaluating the livewire route and I tried to add my domain into the vendor's livewire component in which the test still failed and that did not cause it to work.
Any ideas on where else I can look?

Cannot autowire argument $article : Symfony 5

I'am currenty face to this error when i try to get my article page : Cannot autowire argument $article of "App\Controller\HomeController::show()": it references class "App\Entity\Article" but no such service exists.
I just created a very new small symfony 5 application :
The code in my controller is :
/**
* #Route("/show/{id}", name="show")
*/
public function show(Article $article): Response
{
if(!$article) {
return $this->redirectToRoute('home');
}
return $this->render('show/index.html.twig', [
'article' => $article,
]);
}
I'am following a tutorial on Udemy and i guess that i did the same thing than the former. Maybe version difference ?
Thanks in advance for your helps.
Thierry
The error you have is saying that it cannot find the auto-wire path to your entity. Using the Symfony installer will automatically configure parts like this for you.
The main part which auto-wires the Entity to the Dependency Injection layer is through Doctrine configuration and the Symfony ParamConverter found as part of the SensioFrameworkExtraBundle.
The ParamConverter has a lot of options to be able to convert parameters inside of the #Route into an Entity. Using your example above we see that Symfony will internally call ArticleRepository->findOneById($id) and return the result to your controller.
EDIT: Removed all mentions of Doctrine configurations. The errors that are displayed when Doctrine is not auto-wiring are different.
Same problem here (with attributs instead of annotations) on Symfony 5
I have even tried to explicite ParamConverter and Entity:
#[Route('/article/{id}/editer', name: 'edit_article', requirements: ["id" => "\d+"], methods: ['GET','POST'])]
#[ParamConverter('id', options: ['mapping' => ['id' => 'id']])]
#[Entity('article', expr: 'repository.findOneBySlug(id)')]
public function editArticle(Article $article, Request $request,
CategoryRepository $categoryRepository, EntityManagerInterface $manager): Response
{
dump($article); die;
}
but i have got the error message:
Cannot autowire argument $id of "App\Controller\DefaultController::editArticle()":
it references class "App\Entity\Article" but no such service exists.
Although there is:
use App\Entity\Article;
And the solution like #nico-haase said is to install this bundle
composer require sensio/framework-extra-bundle

Trying to add social media links to Drupal website

I'm trying to add social media icons to my drupal website and followed this guide to try and install them. The module seems to install fine, however when I try to configure it to add different links on clicking save it brings me to a webpage that simply says The website encountered an unexpected error. Please try again later.
I've tried uninstalling/reinstalling the plugin and that didn't seem to do anything. Are there some permissions I'm missing in my set up? I'm pretty much brand new to drupal
Edit: The url of the error is admin/structure/block/manage/socialmedialinks?destination=/node
and some of the error log:
TypeError: Argument 2 passed to Egulias\EmailValidator\EmailValidator::isValid() must implement interface Egulias\EmailValidator\Validation\EmailValidation, bool given,
It seems the social_media_links drupal module version 8.x-2.6 has a bug when it checks the validity of email addresses.
There is an issue in the module's issue queue for it HERE.
There is a patch attached to the issue (attached below):
diff --git a/src/Plugin/SocialMediaLinks/Platform/Email.php b/src/Plugin/SocialMediaLinks/Platform/Email.php
index 007e59f..2926d47 100755
--- a/src/Plugin/SocialMediaLinks/Platform/Email.php
+++ b/src/Plugin/SocialMediaLinks/Platform/Email.php
## -4,7 +4,6 ## namespace Drupal\social_media_links\Plugin\SocialMediaLinks\Platform;
use Drupal\social_media_links\PlatformBase;
use Drupal\Core\Form\FormStateInterface;
-use Egulias\EmailValidator\EmailValidator;
use Drupal\Core\Url;
/**
## -29,9 +28,9 ## class Email extends PlatformBase {
*/
public static function validateValue(array &$element, FormStateInterface $form_state, array $form) {
if (!empty($element['#value'])) {
- $validator = new EmailValidator();
+ $validator = \Drupal::service('email.validator');
- if (!$validator->isValid($element['#value'], TRUE)) {
+ if (!$validator->isValid($element['#value'])) {
$form_state->setError($element, t('The entered email address is not valid.'));
}
}

Add Google APIs Client Library in symfony 3

I want to install the "Google APIs Client Library" in my symfony 3 project, but I don't know how to use it.
I install the library from "https://github.com/googleapis/google-api-php-client#download-the-release" with this command:
composer require google/apiclient:"^2.0"
Next, I try adding namespace in AppKernel.php file, "bundles" array, but I dont know what namespace is or where can I find the namespace. Then I receive this error every time:
Attempted to load class "Google_Client" from namespace "AppBundle\Controller".
This is my small function:
/**
* #Route("/api/oAuth/login", name="api_oauth_login")
*/
public function oAuthLoginAction(Request $request)
{
$client = new Google_Client();
$client->setApplicationName("My Application");
$client->setDeveloperKey("MY_SIMPLE_API_KEY");
}
Can anyone help me with this library integration?
The library don't use a namespace so you should refer to the class with a trailing slash before the classname as example:
$client = new \Google_Client();

Zend\Permissions\Rbac\Role Error 500 when try to instantiate object

I'm trying to implement a RBAC in my project, but I can't instantiate Rbac class.
My code:
<?php
namespace Login\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Permissions\Rbac\Rbac;
use Zend\Permissions\Rbac\Role;
class TesteController extends AbstractActionController {
public function indexAction() {
$role = new Role('teste');
die('=== FIM ===');
}
}
When I comment the Role line it shows "=== FIM ===", but when it isn't commented it gives 500 error.
I already check the module struct in vendor and it's alright.
Do I need to do anything else when I install a vendor module via composer to zend 3 recognize it?
The error was cause by my php version that doesn't accept return type declarations. The Rbac module is full of it.

Resources