Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PhpSoda without Composer #1

Closed
mmkbennani opened this issue Jul 11, 2015 · 6 comments
Closed

Use PhpSoda without Composer #1

mmkbennani opened this issue Jul 11, 2015 · 6 comments
Labels

Comments

@mmkbennani
Copy link

Hi,
I want to use the PHP PhpSoda library in my own project how can i add SodaClient in my index.php file

When i add "use allejo\Socrata\SodaClient;" and i instantiate $sc = new SodaClient("http://opendata.socrata.com"); it's give me the error ( ! ) Fatal error: Class 'allejo\Socrata\SodaClient' not found in C:\wamp\www\Socrata\PhpSoda\tests\index.php on line 6
Call Stack

Time Memory Function Location

1 0.0010 131408 {main}( ) ..\index.php:0
how can i resolve it please?

@mmkbennani mmkbennani changed the title Use Php in own project Use PhpSoda in own project Jul 11, 2015
@allejo
Copy link
Owner

allejo commented Jul 11, 2015

To narrow down the issue, I'd need a bit more information.

  1. Are you using Composer in your project?
  2. Are you using an autoloader (e.g. Autoload) in your project to automatically include all of the PhpSoda files in your project so you may access its classes?
  3. Are you manually include'ing the necessary PhpSoda classes so you may access its classes?

@mmkbennani
Copy link
Author

Excuse me.

I don't know how to use the php libray!!

How to use sodaclient?

Is there a concret example?

Best regards.
Le 11 juil. 2015 17:26, "Vladimir Jimenez" notifications@github.com a
écrit :

To narrow down the issue, I'd need a bit more information.

  1. Are you using Composer https://getcomposer.org/ in your project?
  2. Are you using an autoloader (e.g. Autoload
    https://github.com/theseer/Autoload) in your project to
    automatically include all of the PhpSoda files in your project so you may
    access its classes?
  3. Are you manually include'ing the necessary PhpSoda classes so you
    may access its classes?


Reply to this email directly or view it on GitHub
#1 (comment).

@allejo
Copy link
Owner

allejo commented Jul 11, 2015

It seems you're trying to use the library without Composer handling the autoloading of classes nor are you using an autoloader, which isn't really supported because better practices exist. To solve this, you're going to need have an autoloader to handle files. I've generated an autoload.php file below and you need to put this file inside of the src folder inside of PhpSoda.

Your file structure would look like this:

|- Socrata
   |- PhpSoda
      |- src
         - autoload.php
    - index.php

PhpSoda/src/autoload.php

<?php
// @codingStandardsIgnoreFile
// @codeCoverageIgnoreStart
// this is an autogenerated file - do not edit
function autoloadb1fb9576f6a44a390729a4572cbb3669($class) {
    static $classes = null;
    if ($classes === null) {
        $classes = array(
            'allejo\\socrata\\converters\\converter' => '/Converters/Converter.php',
            'allejo\\socrata\\converters\\csvconverter' => '/Converters/CsvConverter.php',
            'allejo\\socrata\\exceptions\\curlexception' => '/Exceptions/CurlException.php',
            'allejo\\socrata\\exceptions\\filenotfoundexception' => '/Exceptions/FileNotFoundException.php',
            'allejo\\socrata\\exceptions\\httpexception' => '/Exceptions/HttpException.php',
            'allejo\\socrata\\exceptions\\invalidresourceexception' => '/Exceptions/InvalidResourceException.php',
            'allejo\\socrata\\exceptions\\sodaexception' => '/Exceptions/SodaException.php',
            'allejo\\socrata\\sodaclient' => '/SodaClient.php',
            'allejo\\socrata\\sodadataset' => '/SodaDataset.php',
            'allejo\\socrata\\soqlorderdirection' => '/SoqlOrderDirection.php',
            'allejo\\socrata\\soqlquery' => '/SoqlQuery.php',
            'allejo\\socrata\\utilities\\stringutilities' => '/Utilities/StringUtilities.php',
            'allejo\\socrata\\utilities\\urlquery' => '/Utilities/UrlQuery.php'
        );
    }
    $cn = strtolower($class);
    if (isset($classes[$cn])) {
        require dirname(__FILE__) . $classes[$cn];
    }
}
spl_autoload_register('autoloadb1fb9576f6a44a390729a4572cbb3669');
// @codeCoverageIgnoreEnd

Then, in your index.php file you will need to include the autoload file and then you'll be able to use the namespace.

index.php

<?php

include("PhpSoda/src/autoload.php");

use allejo\Socrata\SodaClient;

$sc = new SodaClient("http://opendata.socrata.com");

@mmkbennani
Copy link
Author

Hi Sir

Thats work very gooood

Thanks a lot :)

2015-07-11 22:36 GMT+00:00 Vladimir Jimenez notifications@github.com:

It seems you're trying to use the library without Composer handling the
autoloading of classes nor are you using an autoloader. To solve this,
you're gonna need have an autoloader to handle files. I've generated an
autoload.php file below and you need to put this file inside of the src
folder inside of PhpSoda.

Your file structure would look like this:

|- Socrata
|- PhpSoda
|- src
- autoload.php
- index.php

PhpSoda/src/autoload.php

'/Converters/Converter.php', 'allejo\socrata\converters\csvconverter' => '/Converters/CsvConverter.php', 'allejo\socrata\exceptions\curlexception' => '/Exceptions/CurlException.php', 'allejo\socrata\exceptions\filenotfoundexception' => '/Exceptions/FileNotFoundException.php', 'allejo\socrata\exceptions\httpexception' => '/Exceptions/HttpException.php', 'allejo\socrata\exceptions\invalidresourceexception' => '/Exceptions/InvalidResourceException.php', 'allejo\socrata\exceptions\sodaexception' => '/Exceptions/SodaException.php', 'allejo\socrata\sodaclient' => '/SodaClient.php', 'allejo\socrata\sodadataset' => '/SodaDataset.php', 'allejo\socrata\soqlorderdirection' => '/SoqlOrderDirection.php', 'allejo\socrata\soqlquery' => '/SoqlQuery.php', 'allejo\socrata\utilities\stringutilities' => '/Utilities/StringUtilities.php', 'allejo\socrata\utilities\urlquery' => '/Utilities/UrlQuery.php' ); } $cn = strtolower($class); if (isset($classes[$cn])) { require dirname(**FILE**) . $classes[$cn]; }}spl_autoload_register('autoloadb1fb9576f6a44a390729a4572cbb3669');// @codeCoverageIgnoreEnd Then, in your index.php file you will need to include the autoload file and then you'll be able to use the namespace. _index.php_

KELLA BENNANI Mohamed El-Mekki

Ingénieur d’état Système d'Information Géographique (SIG)

E.H.T.P

Tel : (00212) 655-252-062

@allejo
Copy link
Owner

allejo commented Jul 12, 2015

No problem!

@allejo allejo closed this as completed Jul 12, 2015
@allejo allejo changed the title Use PhpSoda in own project Use PhpSoda without Composer Jul 12, 2015
@allejo
Copy link
Owner

allejo commented Jul 19, 2015

PhpSoda is now also distributed as a Phar file which can be used as a simple include or require in a PHP script.

Take a look at the wiki article which also contains an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants