I want to use https://github.com/HelloFax/hellosign-php-sdk in Yii2 project so I followed following step
1 ) updated composer.json with "hellosign/hellosign-php-sdk": "3.*#dev" in require section
2) run composer update in CMD (I work with window 7)
so it downloaded required libraries (hellosign-php-sdk and libary) in vendor
3 ) include following code in controller file
$client = new HelloSign\Client('df754dd564e52fb2891a60eb2fea777b5320397********');
$response = $client->getSignatureRequest('f6197945000616b383d4752*****');
if ($response->isComplete()) {
echo 'All signers have signed this request.';
} else {
foreach ($response->getSignatures() as $signature) {
echo $signature->getStatusCode() . "\n";
}
}
Error
Unable to find 'app\controllers\HelloSign\Client' in file: C:\wamp\www\yii2hellosign/controllers/HelloSign/Client.php. Namespace missing?
How to solve this issue, any help ?
the library use psr-0 autoload, so you need to prepend classname with \ , like this:
$client = new \HelloSign\Client('...');
Related
I have installed dsiddharth2/php-zxing into laravel project.
After that, I write sample code:
<?php
use PHPZxing\PHPZxingDecoder;
$decoder = new PHPZxingDecoder();
$data = $decoder->decode('https://internationalbarcodes.com/wp-content/uploads/sites/95/2013/09/07-EAN-13-Standard-1.jpg');
if($data instanceof PHPZxing\ZxingImage) {
print_r($data);
}
?>
And it gives error:
File/Folder does not exist.
Can you please help how can I add above library into laravel project.
I am new to yii2 and I have created a form, however it is showing the following error while loading the page:
Unknown Method – yii\base\UnknownMethodException
Calling unknown method: yii\web\Request::post()
The code in studController
public function actionStudform()
{
$data = Stud::find()->asArray()->all();
$model = new Stud;
if(($model->load(Yii::$app->request->post())) && $model->validate())
{
echo "validate";
}
else
{
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
}
ok
i also faced that problem and i had sorted out also
in yii2 you have to check that if form is posted or not ?
if form posted then you have to fetch data or print data
try my code it working in my case with same error
public function actionStudform()
{
$data = Stud::find()->asArray()->all();
$model = new Stud;
$request = Yii::$app->request;
if($request->isPost)
{
if(($model->load($request->post)) && $model->validate())
{
print_r($request->post['Stud']);
}
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
else
{
return $this->render('studform',['model'=>$model,'data'=>$data]);
}
}
Check namespace use Yii in your controller
OR
I think this is again the composer dependency resolver doing unexpected things:
you require yiisoft/yii2 in your composer.json but do not have the composer asset plugin installed.
then the dependency resolver does not find packages with vendor bower-asset so it looks for other versions of yiisoft/yii2 that do not have conflict
The result is to install the beta version of yii2 to be installed
The correct solution as already mentioned is to install the composer-asset-plugin:
php composer.phar global require "fxp/composer-asset-plugin:1.0.*#dev"
I wanna give all my website authors a possiblity to post their articles on our facebook page without having go give them admin access to it.
So i created a simple form, where the author types in: URL, URL to image, message
On submit, this form will send a ajax request to facebook.php where the magic "should" happen.
The first problem occurs at "require_once".
It's not possible to require all 4 files without having an error.
If i get rid of the facebook exception, then everything works except the request itself.
There seems to be an PHP Error, because i get no ajax response at all.
session_start();
require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/FacebookSession.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/FacebookRequest.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/GraphObject.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/sys/facebook/FacebookRequestException.php');
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;
$message = safe($_POST["message"]);
$url = safe($_POST["url"]);
$image = safe($_POST["image"]);
if($message == "" OR $url == "" OR $image == ""){
echo "incomplete";
return;
}
FacebookSession::setDefaultApplication('{APP ID}','{APP SECRET}');
$session = new FacebookSession('{Page Access Token}');
if($session) {
try {
$response = (new FacebookRequest(
$session, 'POST', '/{Page ID}/feed', array(
'message' => $message,
'link' => $url,
'picture' => $image
)
))->execute()->getGraphObject();
echo "Posted with id: " . $response->getProperty('id');
} catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
} else {
echo "No Session available!";
}
Update: June, 27 2014, The SDK now comes with a built-in autoloader for those who can't use composer.
require __DIR__ . '/path/to/facebook-php-sdk-v4/autoload.php';
If that doesn't automatically find the path for you, you can define it with FACEBOOK_SDK_V4_SRC_DIR.
define('FACEBOOK_SDK_V4_SRC_DIR', '/path/to/facebook-php-sdk-v4/src/Facebook/');
require __DIR__ . '/path/to/facebook-php-sdk-v4/autoload.php';
The internals of the SDK rely on several other classes that you're not including. That's why autoloading is really important here.
Autoloading With Composer
The best way to do this is to install composer. And add the SDK in a composer.json file to the root of your project.
{
"require" : {
"facebook/php-sdk-v4" : "4.0.*"
}
}
Then run composer install from the command line where the composer.json file is. Then include the autoloader at the top of your script.
require_once __DIR__ . '/vendor/autoload.php';
Manual Autoloading
An alternative way to autoload these files is to replace your require_once's at the top with this solution from rm-vanda:
function facebookLoader($class) {
require "/path/to/facebook-php-sdk-v4-master/src/" . str_replace("\\", "/", $class) . ".php";
}
spl_autoload_register("facebookLoader");
Here I got my solution fixing on updating the Facebook Graph SDK, I do apologize for the short answer.
I updated, php.ini file and enabled, the fileinfo extension by uncommenting
;extension=fileinfo
Removing the ; tag to
extension=fileinfo
Then do the command,
composer update
Credits: StackOverflow, Bing, and Google search.
Warning: I'm using, Laravel, Wnmp as a local webserver.
Note: This comment may require revisions.
How can get filesystem path of composer package?
composer.json example:
{
"require" : {
"codeception/codeception" : "#stable",
"willdurand/geocoder": "*"
}
}
example:
$composer->getPath("\Geocoder\HttpAdapter\HttpAdapterInterface");
and return it as:
"/home/me/public_html/vendor/willdurand/geocoder/src/Geocoder/HttpAdapter"
All of this is based on the assumption that you are actually talking about packages and not classes (which are mentioned in the example but are not asked for in the question).
If you have the Composer object, you can get the path of the vendor directory from the Config object:
$vendorPath = $composer->getConfig()->get('vendor-dir');
$vendorPath should now contain /home/me/public_html/vendor/.
It shouldn't be too hard to construct the rest of the path from there, as you already have the package name.
If this feels too flaky or you don't want to write the logic, there is another solution. You could fetch all packages, iterate until you find the right package and grab the path from it:
$repositoryManager = $composer->getRepositoryManager();
$installationManager = $composer->getInstallationManager();
$localRepository = $repositoryManager->getLocalRepository();
$packages = $localRepository->getPackages();
foreach ($packages as $package) {
if ($package->getName() === 'willdurand/geocoder') {
$installPath = $installationManager->getInstallPath($package);
break;
}
}
$installPath should now contain /home/me/public_html/vendor/willdurand/geocoder
Try ReflectionClass::getFileName - Gets the filename of the file in which the class has been defined.
http://www.php.net/manual/en/reflectionclass.getfilename.php
Example:
$reflector = new ReflectionClass("\Geocoder\HttpAdapter\HttpAdapterInterface");
echo $reflector->getFileName();
Or you may use this:
$loader = require './vendor/autoload.php';
echo $loader->findFile("\Geocoder\HttpAdapter\HttpAdapterInterface");
The first method try to load class and return loaded class path. The second method return path from composer database without class autoload.
Here is my solution to get the vendor path without using the $composer object :
<?php
namespace MyPackage;
use Composer\Autoload\ClassLoader;
class MyClass
{
private function getVendorPath()
{
$reflector = new \ReflectionClass(ClassLoader::class);
$vendorPath = preg_replace('/^(.*)\/composer\/ClassLoader\.php$/', '$1', $reflector->getFileName() );
if($vendorPath && is_dir($vendorPath)) {
return $vendorPath . '/';
}
throw new \RuntimeException('Unable to detect vendor path.');
}
}
Not sure if the following is the correct way for this because composer is changing so fast.
If you run this command:
php /path/to/composer.phar dump-autoload -o
it will create a classmap array in this file
vender/composer/autoload_classmap.php
with this format "classname" => filepath.
So to find filepath of a given class is simple. If you create the script in your project's root folder, you can do this:
$classmap = require('vender/composer/autoload_classmap.php');
$filepath = $classmap[$classname]?: null;
I'm trying to write some code to track dependencies. Is there a way to programatically detect if a PEAR package has been installed? I'm thinking something like:
if ($some_pear_api->isPackageInstalled('FooPack')) {
echo 'FooPack is installed!';
} else {
echo 'FooPack is not installed. :(';
}
I know you can simply detect if the class file for that package exists, but I mostly want to know if PEAR has that installed because sometimes some libraries provide other means of including their code (e.g. PHPUnit has a pear channel as well as a git repo.).
Thanks for the help!
You need to use the PEAR_Registry class to do this (which is what the PEAR script itself uses).
Read Adam Harvey's blog post "pear -> list" from 3 years ago - all the details/examples you need are there.
include 'PEAR/Registry.php';
$reg = new PEAR_Registry;
foreach ($reg->listPackages() as $package) {
print "$package\n";
}
If you need this to check for specific versions of each package, then you could base something on the following example, which I provided in a comment to that blog entry:
<?php
require 'PEAR/Registry.php';
$reg = new PEAR_Registry;
define("NAME", 0);
define("VERSION", 1);
$packages = array(
array("PEAR", "1.6.2"),
array("Date", "1.4.7"),
array("Date_Holidays", "0.17.1"),
array("Validate_IE", "0.3.1")
);
foreach ($packages as $package) {
$pkg = $reg->getPackage($package[NAME]);
$version = $pkg->getVersion();
echo "{$package[NAME]} – {$package[VERSION]} – ";
echo version_compare($version, $package[VERSION], '>=') ? 'OK': 'BAD', "\n";
}
?>
If you need to copy and paste this, then it might be best for you to use the version at https://gist.github.com/kenguest/1671361.
You can use Pear/Infos packageInstalled to answer this:
<?php
require_once 'PEAR/Info.php';
$res = PEAR_Info::packageInstalled('FooPack');
if ($res) {
print "Package FooPack is installed \n";
} else {
print "Package FooPack is not yet installed \n";
}
?>
Why not just include the package and see if the class exists?
// Supress Errors. Checking is done below.
#require_once 'PHP/UML.php';
if(!class_exists('PHP_UML'))
{
throw new Exception('PHP_UML is not installed. Please call `pear install PHP_UML` from the command line',1);
}
// Code to use PHP_UML below...
$uml = new PHP_UML();