How to add adLDAP as library to Laravel 4 - php

How i can add adLDAP library to LARAVEL 4 ?
http://adldap.sourceforge.net/

That library does not offer a composer.json file yet, you you have to create the necessary information yourself.
I have created a sample file that successfully downloaded something that looks good, but I haven't used the code.
{
"require": {
"adldap/adldap": "4.0.4"
},
"repositories" : [
{
"type": "package",
"package": {
"name" : "adldap/adldap",
"version": "4.0.4",
"dist": {
"url": "http://sourceforge.net/projects/adldap/files/adLDAP/adLDAP_4.0.4/adLDAP_4.0.4r2.zip/download",
"type": "zip"
},
"source": {
"url":"https://svn.code.sf.net/p/adldap/code/",
"type": "svn",
"reference": "tags/v4.0.4/"
},
"autoload": {
"classmap": ["src/"]
}
}
}
]
}
You'd have to create one repositories entry per version you are about to use (one entry is enough if you don't plan do something fancy). I created the entry for the most recent version 4.0.4 - if there is an update, you have to change the version tags everywhere.
The require entry should be added to whatever you are already using.
The distribution URL is a rough guess by following the download link to the ZIP file offered on Sourceforge, bypassing any ad-filled download page. It might stop working unexpectedly. If you delete the whole dist section, you will checkout from the original SVN repository instead, which might be slower than downloading and unpacking a ZIP file.
After that, you are all set with the Composer part. The remaining thing is to include Composer autoloading in the Laravel bootstrapping (you might already have that done), and then enjoy the LDAP classes.

Anyone coming across this in the future, adLDAP has a composer file now and can easily be autoloaded.
"require": {
"adldap/adldap": "4.0.*"
},
Then load the library in your controller:
$ldap = new \adLDAP\adLDAP($config);

Related

Composer autoload doesn't work regardless of whatever I do

I have a project, and I need some packages, so I reorganized the project to use PSR-4.
Here's my composer.json:
{
"name": "me/production",
"type": "project",
"authors": [
{
"name": "Me",
"email": "me#me.com"
}
],
"config": {
"platform": {
"php": "5.6.1"
}
},
"autoload": {
"psr-4": {
"API\\": "api/"
}
},
"require": {
"nesbot/carbon": "^2.25"
},
}
it doesn't work in my scripts. But, here's the real kicker: I do require_once __DIR__ . '/vendor/autoload.php'; in my php console, and it doesn't work either. I have triple and quadruple checked the path, the autoload is there.
What do I mean by "doesn't work"? the autoload requires successfully. It allows me to use libraries. BUT actual instantiations result in a
Class not found error.
Not only for my classes in the API namespace, which are namespaced in the top of the file and are exactly in the folder they're suppose to be, but I also CANNOT instantiate Carbon. I can use Carbon\Carbon but any attempt to instantiate will fail.
Interestingly, instantiation of \Carbon\Carbon directly does not fail.
What's going on? This is weird.
Thank you in advance.
EDIT: I tried redumping the autoloader, I also tried removing the vendor folder and reinstalling. All to no avail.
EDIT: May be worth mentioning I downgraded carbon to ^1.21 because carbon 2 doesnt support php 5.6. But it still doesn't work.
EDIT: It happens with my API namespace as well, here's an example using my implementation of the Instagram API:
use \API\Insta;
php > var_dump(new Insta);
PHP Fatal error: Class 'Insta' not found in php shell code on line 1
php > var_dump(new \API\Insta);
object(API\Insta)#3 (1) {
["ig_token"]=>
string(51) "A_VALID_TOKEN"
}
php >
EDIT: The problem solved itself, it has now mutated into one I care very little about: I can use everything but not in the php console. I am not sure what fixed it.
As you found out, nesbot/carbon, version 2.25 requires at least PHP v7.1.8.
Just having a use statement doesn't check anything, instead it creates a local alias that can be used. If you try to use something that does not exist, only then would it fail.
Please clarify that you have the following directory structure:
./composer.json
./composer.lock
./Api/Insta.php
and in the file Api/Insta.php:
namespace API; // this is your top namespace name
use Carbon/Carbon; // etc
class Insta { ... }
Having the namespace different to the directory name can lead to confusion.
There will also be the index.php/front-controller that pulls in the vendor/autoload.php file and presumably runs the framework.

Add any SDK to Laravel 5.x

I'm trying to add this SDK in my Laravel 5.4 application. I downloaded and installed it in app/resources/assets and guessing that I can use it in controllers as:
require_once '[ruta/payu-php-sdk]/lib/PayU.php';
The SDK have some Eviromental variables and Keys.
What do you think is the better approach for this type of SDK in laravel?
I'd suggest using Omnipay, it's a well supported library the has integrations for many different gateways, including PayU. This library is framework agnostic, so you won't need to change your code should you need to change payment gateways.
You can use composer to add these libraries:
"require": {
"omnipay/omnipay": "~2.0",
"omnipay/payu": "~2.0"
}
This way you don't have to keep track of requires.
Edit: To add any type of library that doesn't use composer already, You could manually tell composer to autoload file(s).
For your case, there should be a section in your composer.json called autoload, here's what you could add:
...
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
},
"files": [
"ruta/payu-php-sdk/lib/PayU.php"
]
},
...
This should make the SDK available throughout the application.

Autoload PHPExcel 1.0 in Symfony 2.6

We added PHPExcel to composer by adding the following
To repositories:
{
"type": "package",
"package": {
"name": "PHPOffice/PHPExcel",
"version": "1.9",
"source": {
"url": "https://github.com/PHPOffice/PHPExcel.git",
"type": "git",
"reference": "1.9"
},
"autoload": {
"psr-0": {
"PHPExcel": "src/"
}
}
}
To require:
"PHPOffice/PHPExcel": "1.9.*"
In our code:
use PHPExcel\IOFactory;
...
$file = $request->get('file');
$inputFileType = IOFactory::identify($file);
The error we get is:
Attempted to load class "IOFactory" from namespace "PHPExcel".
Did you forget a "use" statement for another namespace?
The namespace looks right (https://github.com/PHPOffice/PHPExcel/blob/1.9/src/PhpSpreadsheet/IOFactory.php).
Use of the 1.9 branch is not recommended. It isn't completely converted yet to use namespaces, and is subject to significant code change. Nor is it backward compatible with the official 1.8 branch, and the changes are not yet documented, and also subject to further major changes as we modify the code to take advantage of the newer features of PHP.
The official release branch is still 1.8
Just because the 1.8 branch exists on github, doesn't mean that it's working code. I store it there so that it's available for shared development, and as a security (rather than keeping it all on my development laptop) in case I get run over by a bus tomorrow.
I have not used 1.9. Glad to see that they are moving to namespaces. That said, you might be better off sticking with 1.8 just for stability.
In any event, 1.9 relies on psr-4. Try adding this to your composer.json file:
"autoload": {
"psr-4": {
"PHPExcel\\": "src/PhpSpreadsheet"
}
}
Then rebuilding the composer generated autoload.php file.

Removing or renaming swift in laravel

The error I am getting is
file: "/var/www/html/goalline/swiftmailer333/Swift.php" line: 32
message: "Cannot redeclare class Swift" type:
"Symfony\Component\Debug\Exception\FatalErrorException"
I have a need to remove Swift from Laravel as it conflicts with functions form a legacy application that my Laravel app needs to call.
How can I do this? Whether I should is irrelevant I have to use those functions from the legacy application.
I've tried commenting
'Mail' => 'Illuminate\Support\Facades\Mail',
and 'Illuminate\Mail\MailServiceProvider' but that didn't work.
You'll have to namespace your Swift class:
<?php
namespace YourApp;
class Swift {
}
Then use it this way:
$swift = new YourApp\Swift;
Another possibility is to create a nasty hack to remove it from your Laravel installation, but to do that you'll have to create a repository of your own and use your repository in your composer.json file:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/yourusername/swiftmailer"
}
],
"require": {
"swiftmailer/swiftmailer": "dev-master"
}
}
Your repository can pretty much be a copy of swiftmailer's which you basically remove every file except the composer.json.

Clone git repository via composer

guys!
I simply want to clone repository via composer. But unfortunately - i can't.
My composer.json looks like:
{
"repositories": [
{
"type": "vcs",
"url": "https://bitbucket.org/yuriikrevnyi/bitrix-teil-framework"
}
],
"require": {
"mockery/mockery": "dev-master#dev",
"phpunit/phpunit": "3.7.*"
}
}
But its not going to work.
So, couldnt you help me a little bit?
And there is one more question. How to 'clone' private repo with composer? Lets say, we have same repo - https://bitbucket.org/yuriikrevnyi/bitrix-teil-framework. And admin password is - PASSWORD
So, how the composer.json should look now?
Thanks!
The respositories section is only to define packages that are not present in the packagist.org database, but it is present on a 'source control'.
So, it is like you tell composer in your composer.json that there is a package which is source controlled, and here are the details where you get it from, by defining url .. etc.
But that is not enough, because that is only definition and not consuming (downloading) the package. In order to do so, you need to add it to your require section as well.
{
"repositories": [
{
"type": "vcs",
"url": "https://bitbucket.org/yuriikrevnyi/bitrix-teil-framework"
}
],
"require": {
"mockery/mockery": "dev-master#dev",
"phpunit/phpunit": "3.7.*",
"yuriikrevnyi/bitrix-teil-framework": "*"
}
}
In your posted composer.json you are stating multiple facts.
You state that the software this composer.json belongs to requires the packages named "mockery/mockery" and "phpunit/phpunit".
You also state that there is some repository existing that might contain some software.
What you are not stating is that Composer should clone that repository - and you cannot do this with Composer. Composer will by default only know about packages registered at packagist.org, and additionally will look into any declared repository to see which software is in there in case that software is required.
So without having another composer.json in that repository hosted at Bitbucket, nothing will happen. Also, without requiring the software that is hosted there, nothing will happen.
Your problem description is missing the most important parts to help ypu better:
Describe what you were doing.
Describe the expected result.
Describe the actual result and how it differs from the expected result.
What you are describing is roughly point 1 (could have more details), your words "it does not work" fails to describe point 3, and point 2 is missing alltogether.

Categories