mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-04-13 12:02:17 +02:00
fix the autoloader
This commit is contained in:
parent
ccbf8553ac
commit
c852326dbd
19
readme.md
19
readme.md
@ -8,22 +8,18 @@ Faker requires PHP >= 5.3.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
Require the Faker autoloader to use Faker in a script
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require_once '/path/to/src/autoload.php';
|
||||
```
|
||||
|
||||
Or use your own autoloader (ex: Symfony2 ClassLoader) to autoload the Faker namespace.
|
||||
|
||||
Use `Faker\Factory::create()` to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want.
|
||||
|
||||
```php
|
||||
<?php
|
||||
$faker = Faker\Factory::create(); // $faker is a Faker\Generator instance
|
||||
// require the Faker autoloader
|
||||
require_once '/path/to/Faker/src/autoload.php';
|
||||
// alternatively, use another PSR-0 compliant autoloader (like the Symfony2 ClassLoader for instance)
|
||||
|
||||
// use the factory to create a Faker\Generator instance
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
// generate data by accessing properties
|
||||
echo $faker->name;
|
||||
// 'Lucy Cechtelar';
|
||||
echo $faker->address;
|
||||
@ -263,6 +259,7 @@ The following script generates a valid XML document:
|
||||
|
||||
```php
|
||||
<?php
|
||||
require_once '/path/to/Faker/src/autoload.php';
|
||||
$generator = Faker\Factory::create();
|
||||
?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
@ -38,14 +38,8 @@ class Factory
|
||||
|
||||
protected static function findProviderClassname($provider, $locale = '')
|
||||
{
|
||||
$providerName = $locale ? sprintf('Provider\%s\%s', $locale, $provider) : sprintf('Provider\%s', $provider);
|
||||
$providerClass = 'Faker\\' . $providerName;
|
||||
if (class_exists($providerClass)) {
|
||||
return $providerClass;
|
||||
}
|
||||
$providerClassPath = __DIR__ . '/' . str_replace('\\', '/', $providerName) . '.php';
|
||||
if (file_exists($providerClassPath)) {
|
||||
require $providerClassPath;
|
||||
$providerClass = 'Faker\\' . ($locale ? sprintf('Provider\%s\%s', $locale, $provider) : sprintf('Provider\%s', $provider));
|
||||
if (class_exists($providerClass, true)) {
|
||||
return $providerClass;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Simple autoload that follow the PHP Standards Recommendation #0 (PSR-0)
|
||||
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations.
|
||||
/**
|
||||
* Simple autoloader that follow the PHP Standards Recommendation #0 (PSR-0)
|
||||
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md for more informations.
|
||||
*
|
||||
* Code from the SplClassLoader RFC, see https://wiki.php.net/rfc/splclassloader#example_implementation
|
||||
*
|
||||
* Code inspired from the SplClassLoader RFC
|
||||
* @see https://wiki.php.net/rfc/splclassloader#example_implementation
|
||||
*/
|
||||
spl_autoload_register(function($className) {
|
||||
$className = ltrim($className, '\\');
|
||||
@ -16,7 +16,10 @@ spl_autoload_register(function($className) {
|
||||
$className = substr($className, $lastNsPos + 1);
|
||||
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
|
||||
|
||||
require __DIR__.'/'.$fileName;
|
||||
$fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName . $className . '.php';
|
||||
if (file_exists($fileName)) {
|
||||
require $fileName;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../src/Faker/Factory.php';
|
||||
require_once __DIR__ . '/../src/Faker/Documentor.php';
|
||||
require_once __DIR__ . '/../src/autoload.php';
|
||||
|
||||
$generator = Faker\Factory::create();
|
||||
$generator->seed(1);
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../src/Faker/Factory.php';
|
||||
require_once __DIR__ . '/../src/autoload.php';
|
||||
|
||||
$generator = Faker\Factory::create();
|
||||
$generator->seed(5);
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user