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

Tidied up READMEs. #893

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions Library/Phalcon/Acl/Adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ This adapter uses a database to store the ACL list:
use Phalcon\Acl\Adapter\Database as AclDb;
use Phalcon\Db\Adapter\Pdo\Sqlite;

$connection = new Sqlite(['dbname' => 'sample.db']);
$connection = new Sqlite(
[
'dbname' => 'sample.db',
]
);

$acl = AclDb(
[
'db' => $connection,
'roles' => 'roles',
'rolesInherits' => 'roles_inherits',
'resources' => 'resources',
'resourcesAccesses' => 'resources_accesses',
'accessList' => 'access_list'
]
[
'db' => $connection,
'roles' => 'roles',
'rolesInherits' => 'roles_inherits',
'resources' => 'resources',
'resourcesAccesses' => 'resources_accesses',
'accessList' => 'access_list',
]
);

```
Expand Down Expand Up @@ -64,22 +68,33 @@ CREATE TABLE `roles_inherits` (
Using the cache adapter:

```php

// By default the action is deny access
$acl->setDefaultAction(Phalcon\Acl::DENY);
$acl->setDefaultAction(
\Phalcon\Acl::DENY
);

// You can add roles/resources/accesses to list or insert them directly in the tables

// Add roles
$acl->addRole(new Phalcon\Acl\Role('Admins'));
$acl->addRole(
new \Phalcon\Acl\Role('Admins')
);

// Create the resource with its accesses
$acl->addResource('Products', ['insert', 'update', 'delete']);
$acl->addResource(
'Products',
[
'insert',
'update',
'delete',
]
);

// Allow Admins to insert products
$acl->allow('Admin', 'Products', 'insert');

// Do Admins are allowed to insert Products?
var_dump($acl->isAllowed('Admins', 'Products', 'update'));

var_dump(
$acl->isAllowed('Admins', 'Products', 'update')
);
```
9 changes: 5 additions & 4 deletions Library/Phalcon/Acl/Factory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ in case `\Phalcon\Config` or one of its adapters is used for configuration.
To setup `acl` service in DI `service.php` file using `acl.ini` file:
(example of structure and options in ini file can be found in [tests/_fixtures/Acl/acl.ini](tests/_fixtures/Acl/acl.ini)


```php
use Phalcon\Config\Adapter\Ini as ConfigIni;
use Phalcon\Acl\Factory\Memory as AclMemory;
Expand All @@ -18,10 +17,12 @@ $di->setShared(
function () {
$config = new ConfigIni(APP_PATH . '/config/acl.ini');
$factory = new AclMemory();

// returns instance of \Phalcon\Acl\Adapter\Memory
// note the [acl] section in ini file
return $factory->create($config->get('acl'));
return $factory->create(
$config->get('acl')
);
}
);
```
Expand All @@ -38,7 +39,7 @@ $di->setShared(
function () {
$config = new Config(APP_PATH . '/config/acl.php');
$factory = new AclMemory();

// returns instance of \Phalcon\Acl\Adapter\Memory
return $factory->create($config);
}
Expand Down
82 changes: 50 additions & 32 deletions Library/Phalcon/Annotations/Adapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ This adapter uses a `Phalcon\Cache\Backend\Libmemcached` backend to store the ca
```php
use Phalcon\Annotations\Adapter\Memcached;

$di->set('annotations', function () {
return new Memcached([
'lifetime' => 8600,
'host' => 'localhost',
'port' => 11211,
'weight' => 1,
'prefix' => 'prefix.',
]);
});
$di->set(
'annotations',
function () {
return new Memcached(
[
'lifetime' => 8600,
'host' => 'localhost',
'port' => 11211,
'weight' => 1,
'prefix' => 'prefix.',
]
);
}
);
```

## Redis
Expand All @@ -29,14 +34,19 @@ This adapter uses a `Phalcon\Cache\Backend\Redis` backend to store the cached co
```php
use Phalcon\Annotations\Adapter\Redis;

$di->set('annotations', function () {
return new Redis([
'lifetime' => 8600,
'host' => 'localhost',
'port' => 6379,
'prefix' => 'annotations_',
]);
});
$di->set(
'annotations',
function () {
return new Redis(
[
'lifetime' => 8600,
'host' => 'localhost',
'port' => 6379,
'prefix' => 'annotations_',
]
);
}
);
```

## Aerospike
Expand All @@ -47,19 +57,27 @@ This adapter uses a `Phalcon\Cache\Backend\Aerospike` backend to store the cache
```php
use Phalcon\Annotations\Adapter\Aerospike;

$di->set('annotations', function () {
return new Aerospike([
'hosts' => [
['addr' => '127.0.0.1', 'port' => 3000]
],
'persistent' => true,
'namespace' => 'test',
'prefix' => 'annotations_',
'lifetime' => 8600,
'options' => [
\Aerospike::OPT_CONNECT_TIMEOUT => 1250,
\Aerospike::OPT_WRITE_TIMEOUT => 1500
]
]);
});
$di->set(
'annotations',
function () {
return new Aerospike(
[
'hosts' => [
[
'addr' => '127.0.0.1',
'port' => 3000,
],
],
'persistent' => true,
'namespace' => 'test',
'prefix' => 'annotations_',
'lifetime' => 8600,
'options' => [
\Aerospike::OPT_CONNECT_TIMEOUT => 1250,
\Aerospike::OPT_WRITE_TIMEOUT => 1500,
],
]
);
}
);
```
28 changes: 18 additions & 10 deletions Library/Phalcon/Annotations/Extended/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ using either _APCu_ or _APC_ extension. This adapter is suitable for production.
```php
use Phalcon\Annotations\Extended\Adapter\Apc;

$di->set('annotations', function () {
return new Apc([
'lifetime' => 8600, // Optional
'statsSey' => '_PHAN', // Optional
'prefix' => 'app-annotations-', // Optional
]);
});
$di->set(
'annotations',
function () {
return new Apc(
[
'lifetime' => 8600, // Optional
'statsSey' => '_PHAN', // Optional
'prefix' => 'app-annotations-', // Optional
]
);
}
);
```

## Memory
Expand All @@ -34,9 +39,12 @@ Stores the parsed annotations in the memory. This adapter is the suitable develo
```php
use Phalcon\Annotations\Extended\Adapter\Memory;

$di->set('annotations', function () {
return new Memory();
});
$di->set(
'annotations',
function () {
return new Memory();
}
);
```

## Files
Expand Down
45 changes: 27 additions & 18 deletions Library/Phalcon/Avatar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ Users must register their email addresses with Gravatar before their avatars wil
```php
use Phalcon\Avatar\Gravatar;

$di->setShared('gravatar', function () {
// Get Gravatar instance
$gravatar = new Gravatar([]);

// Setting default image, maximum size and maximum allowed Gravatar rating
$gravatar->setDefaultImage('retro')
->setSize(220)
->setRating(Gravatar::RATING_PG);

return $gravatar;
});
$di->setShared(
'gravatar',
function () {
// Get Gravatar instance
$gravatar = new Gravatar(
[]
);

// Setting default image, maximum size and maximum allowed Gravatar rating
$gravatar->setDefaultImage('retro')
->setSize(220)
->setRating(Gravatar::RATING_PG);

return $gravatar;
}
);
```

#### Setup through config
Expand All @@ -40,13 +45,15 @@ $config = [
'use_https' => true,
];

$di->setShared(
'gravatar',
function () use ($config) {
// Get Gravatar instance
$gravatar = new Gravatar($config);

$di->setShared('gravatar', function () use ($config) {
// Get Gravatar instance
$gravatar = new Gravatar($config);

return $gravatar;
});
return $gravatar;
}
);
```

### Using
Expand Down Expand Up @@ -156,7 +163,9 @@ By default, the Gravatar rating is `Gravatar::RATING_G`.
Example:

```php
$gravatar->setRating(Gravatar::RATING_PG);
$gravatar->setRating(
Gravatar::RATING_PG
);
```

If an invalid maximum rating is specified, this method will throw an exception of class `\InvalidArgumentException`.
Expand Down
Loading