mb_substr() undefined Facebook canvas - Heroku server - php

The problem is that when I open the facebook canvas. I get this error. "call to undefined function mb_substr"
The solution that most people suggest is to put "ext-mbstring" as a require. I did that in different way's. This is what I have now:
{
"require" : {
"silex/silex": "~1.3",
"monolog/monolog": "~1.7",
"twig/twig": "^1.19",
"symfony/twig-bridge": "^2.7"
},
"require-dev": {
"heroku/heroku-buildpack-php": "*"
},
"require": {
"ext-mbstring": "*"
}
}
This does not work for me. I have also checked the php info of my heroku server.
This is the output. As you can see the mbstring is set.
What I at last think the problem could be is the php version. Facebook wants a version that's higher than 5.4. I am using version 5.6.15.
So that shouldn't be the problem either.
Anyone knows what I missed?

Since it's a JSON object and require is the property key, I don't think you can just add a second property with the same key. Try to add the dependency to the first require property.
{
"require" : {
"php": ">=5.6.0",
"ext-mbstring": "*",
"silex/silex": "~1.3",
"monolog/monolog": "~1.7",
"twig/twig": "^1.19",
"symfony/twig-bridge": "^2.7"
},
...

Don't forget to run composer update after you make changes to composer.json.

Related

Composer won't install due to strange syntax in composer.json: "package/package": "other-package as x.xx.x"

This composer.json file won't install due to an inline alias. This line appears to be the culprit:
"jms/serializer": "xsd2php-dev as 0.18.0",
I'm not sure what this is trying to do. Is it trying to replace the jms/serializer with xsd2php-dev at version 0.18.0?
Here is the full file:
{
"require": {
"jsanc623/phpbenchtime": "dev-master",
"gte451f/phalcon-json-api-package": "dev-master",
"soundasleep/html2text": "~0.2",
"phpmailer/phpmailer": "~5.2",
"php": ">=5.2.0",
"ext-curl": "*",
"jms/serializer": "xsd2php-dev as 0.18.0",
"robmorgan/phinx": "^0.5.3",
"aws/aws-sdk-php": "^3.19"
},
"require-dev": {
"codeception/codeception": "*",
"flow/jsonpath": "dev-master",
"goetas/xsd2php": "2.*#dev",
"goetas/xsd-reader": "2.*#dev"
},
"repositories": [{
"type": "vcs",
"url": "https://github.com/goetas/serializer.git"
}]
}
Composer version 1.10.19
here is an example of my error I get:
$ composer
[UnexpectedValueException]
Invalid version string "xsd2php-dev" in "xsd2php-dev as 0.18.0", the alias source must be an exact version, if it is a branch name you should prefix it with dev-
As per #rob006:
Try change it to dev-xsd2php as 0.18.0 - non-version-like branches should be prefixed by dev, not suffixed.
"jms/serializer": "xsd2php-dev as 0.18.0",
to
"jms/serializer": "dev-xsd2php as 0.18.0",

Adding a composer package to Laravel 5

"require": {
"infusionsoft/php-sdk": "^1.2",
"laravel/lumen-framework": "5.1.*",
"vlucas/phpdotenv": "~1.0",
"barryvdh/laravel-debugbar": "^2.2",
"goaop/framework": "^2.0",
"php-http/httplug": "^1.1",
"infusionsoft/old-php-isdk": "*"
},
I'm trying to use the "infusionsoft/old-php-isdk" which is in the packagist composer repository but it's not specific to Laravel. I'm using an order controller and it's code that I picked up from another developer so he references the current (and working) "infusionsoft/php-sdk" as the following
"use infusionsoft\infusionsoft;"
What namespace do I call it if it has no namespace from the package?
Here's the original link to the composer package.
https://packagist.org/packages/infusionsoft/old-php-isdk
Am I missing something? Do I need to assign it a namespace? What and where would I put it?

How to use one github repository as a vendor library, with file overrides from my own repository

I am using the Fuel PHP SDK for Marketing Cloud and there are some changes I'd like to make. Since I am also using Heroku, the repository is refreshed on every git push I make.
I need to modify a few files, but since the repo is refreshed on every push, my changes will get overwritten. Is there a way to copy these files into my own repo, declare that as a dependency after the other repo, and override the files in the main repo with my updated files?
For example, the file I want to update is named ET_Get.php. I could update it directly, but then it will be overwritten on every push. I want to duplicate that file out, make some changes, and I want the repo to use that file, not the repo's own file.
My composer.json looks like this
{
"require": {
"salesforce-mc/fuel-sdk-php": "1.3.0",
"guzzlehttp/guzzle": "~6.0",
"ext-soap": "*",
"php": "7.1.28",
"ext-mcrypt": "*",
"twig/twig": "^2.0",
"firebase/php-jwt":">=5.0.0"
},
"autoload": {
"psr-4": {
"FuelSdk\\": "custom-classes",
"Pardot\\": "custom-classes"
}
}
}
So I was thinking I could just create my own repo after the salesforce-mc repo, and have my files override those.
{
"require": {
"salesforce-mc/fuel-sdk-php": "1.3.0",
"salesforce-mc/custom": "1.0",
"guzzlehttp/guzzle": "~6.0",
"ext-soap": "*",
"php": "7.1.28",
"ext-mcrypt": "*",
"twig/twig": "^2.0",
"firebase/php-jwt":">=5.0.0"
},
"autoload": {
"psr-4": {
"FuelSdk\\": "custom-classes",
"Pardot\\": "custom-classes"
}
}
}
Is this possible? It doesn't have to be a separate repo. Any way that I can simply have my own overrides would be fine.
I know I could fork the repo, and use my fork as a dependency, but that seems like overkill...
You can make the call server side using a library such as cURL
Which will work fine if it's an API that responds with some json or xml.
If their page renders something like a html thank you page, you would have to parse that to ensure it worked and then render your own.
If that's the case and you are making a GET call to ExactTargets site, then you could probably just do a header redirect.
If you do have to POST data, then you could also render a new form that is just a "Submit" button, that contains all the data in hidden fields. It would basically be the same as if you submitted to them to begin with.
Hope that helps
This turned out to be exactly what I needed.
https://mnapoli.fr/overriding-dependencies-with-composer/
Use forked repo on github via composer as dependency
All I had to do was fork the original repo, make my changes, then use my repo in the composer.json like below:
{
"require": {
"salesforce-mc/fuel-sdk-php": "1.3.0",
"guzzlehttp/guzzle": "~6.0",
"ext-soap": "*",
"php": "7.1.28",
"ext-mcrypt": "*",
"twig/twig": "^2.0",
"firebase/php-jwt":">=5.0.0"
},
"repositories":[
{
"type":"git",
"url": "https://github.com/user/forked-project.git"
}
],
"autoload": {
"psr-4": {
"FuelSdk\\": "custom-classes",
"Pardot\\": "custom-classes"
}
}
}

How do I include a library / API into my Behat project that was added by Composer?

Apparently version 4 of PHPUnit now uses Composer to autoload, which means that the usual means of including PHPUnit in Behat version 2:
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
Doesn't work. I was hoping that /vendor/autoload.php in my Behat folder would include it but it seems like it's not the case.
I guess what I'm asking is what is the general way in which I can include into my code a library that was added by Composer?
You can successfully use default /vendor/autoload.php to both load your libraries and your code. It's hard to say exactly what might be wrong without further details, but make sure your composer dependencies are updated and then simply require the composer's authoload.php. The composer.json should look similar to:
{
"require": {
"behat/behat": "dev-master",
"behat/mink": "dev-master",
"behat/mink-extension": "dev-master",
"behat/mink-browserkit-driver": "dev-master",
"behat/mink-goutte-driver": "dev-master",
"behat/mink-selenium2-driver": "dev-master",
"phpunit/dbunit": "*",
"phpunit/phpunit": "*",
},
"autoload": {
"psr-0": {
"": "./src/"
}
}
}
You can include it in your context hook (this is Behat 3 example though):
/**
* #beforeSuite
*/
public static function setUpSuite()
{
require_once './vendor/autoload.php';
}

How do I load the Paypal SDK into Silex?

I'm having some trouble. I'm using Silex, and I'm trying to load the Paypal SDK into it. I think my issue is related to my understanding of Silex, which is why I'm posting it here.
My Setup
Paypal's developer website says to add a few lines to the composer file (PHP tab). So, I've done that. My new composer file looks like so (the last four entries were those suggested by Paypal):
{
"require": {
"silex/silex": "1.0.*#dev",
"symfony/browser-kit": "2.1.*",
"symfony/console": "2.1.*",
"symfony/css-selector": "2.1.*",
"symfony/dom-crawler": "2.1.*",
"symfony/filesystem": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/form": "2.1.*",
"symfony/locale": "2.1.*",
"symfony/process": "2.1.*",
"symfony/security": "2.1.*",
"symfony/serializer": "2.1.*",
"symfony/translation": "2.1.*",
"symfony/validator": "2.1.*",
"symfony/monolog-bridge": "2.1.*",
"symfony/twig-bridge": "2.1.*",
"monolog/monolog": ">=1.0.0,<1.2-dev",
"twig/twig": ">=1.2.0,<2.0-dev",
"doctrine/dbal": ">=2.2.0,<2.4.0-dev",
"swiftmailer/swiftmailer": "4.1.*",
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
"paypal/rest-api-sdk-php" : "0.7.*"
}
}
Then, I ran composer update, and it updated everything. I checked in the vendor folder, and a paypal folder had been created and seemed to be good to go.
The Problem
Unfortunately, even though I've done the above steps, it still isn't working. I'm following the beginners steps outlined on Paypal's website, it seems that one of the Paypal classes can't be located.
The line that causes the error is taken directly from the "beginners steps" page linked to above. For quick reference, I'll provide it below as well:
$cred = new OAuthTokenCredential("AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd","EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX", $sdkConfig);
Unfortunately that line causes an error that says:
Fatal error: Class 'OAuthTokenCredential' not found in ...
Summed up...
The problem seems to be that Silex isn't loading--or making available--the class OAuthTokenCredential. What do I do?
Thanks Laurynas MaliĊĦauskas and user2930475 for this answer (in the comments of my post).
Looks like I had neglected to put a line such as:
use PayPal\Auth;
in my app.php file.
Once added, I also needed to change my new class line to this:
$cred = new PayPal\Auth\OAuthTokenCredential("AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd","EL1tVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX", $sdkConfig);
Note that I have all of my controllers actually in the app.php file.
Actually, you don't need to add anything to app.php at all. Just do this:
use PayPal\Auth\OAuthTokenCredential.php;
class YourController{
public function myAction(){
// ...
$cred = new OAuthTokenCredential("AQkquB...","EL1tVx...", $sdkConfig);
// ...
}
}
You should never need to modify app.php just to use a class.

Categories