I am trying to use this API: https://github.com/CommsCenter/name-com-php-sdk/blob/next-8.0/README.md
I says to run this command:
composer require commscenter/name-com-php-sdk
However, that command doesn’t work.
I was able to get it to work by creating a composer.json file in the root directory of my project that contained the following code:
{
"minimum-stability": "dev",
"require": {
"commscenter/name-com-php-sdk": "dev-master"
}
}
But when it runs, it creates a vendor/ folder, with the following structure:
05/01/2024 10:32 PM 771 autoload.php
05/01/2024 10:32 PM <DIR> commscenter
05/01/2024 10:32 PM <DIR> composer
05/01/2024 10:32 PM <DIR> guzzlehttp
05/01/2024 10:32 PM <DIR> pckg-app
05/01/2024 10:32 PM <DIR> psr
05/01/2024 10:32 PM <DIR> ralouphie
05/01/2024 10:32 PM <DIR> symfony
So the code I want appears to be in /vendor/commscenter/name-com-php-sdk
I’m guessing the other stuff are dependencies used by that code. But how do I use this?
Like, i’m in index.php, and I want to instantiate an instance of the NameCom class. I have no idea what to do. I’m used to like using require to include the .php file that defines the class. But here the instructions:
Instalation
Install package with composer
$ composer require commscenter/name-com-php-sdk
Usage
Standalone
Instantiate new OpenCodeNameComApi
class and pass endpoint
, username
and token
.
Pckg framework
Add provider OpenCodeNameComProviderNameCom
and auto resolve Api
object.
$api = resolve(OpenCodeNameComProviderNameCom::class)
Endpoints
Domain
$api->domain()->checkAvailability('yourdomain.com');
$api->domain()->register('yourdomain.com');
I have no idea how the composer autoloaders work. I wanted to use this API to make using the name.com API easier, but it is just a REST api – I think tomorrow I will just sit down and try to use the API without this wrapper. I’m not sure how adding a 4 year old wrapper and a half dozen dependencies to a RESET api will make it easier to use.
Still, IF I got this to work, $api->domain()->checkAvailability(‘yourdomain.com’); is a super clean api call.
I wish name.com would offer both a REST API and a PHP SDK that offered class wrappers. Then you could just:
require(“name.com.php”);
$name_com_api = new name_com_api(file_get_contents(“api.key”), “username”, “sandbox”);
if($name_com_api ->domain()->checkAvailability(“test.com”) === false)…
Can someone explain how you are supposed to use these composer files?
I tried:
require(“vendor/autoload.php”);
$api = resolve(OpenCodeNameComProviderNameCom::class);
I just get “call to undefined function resolve”.
Trent Tompkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.