Skip to content

Commit

Permalink
Change namespace (#5).
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Rapaport committed Mar 8, 2017
1 parent d2965ed commit 6cfaa5c
Show file tree
Hide file tree
Showing 20 changed files with 77 additions and 77 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -11,7 +11,7 @@
],
"autoload": {
"psr-4": {
"Acf\\": "src/"
"Samrap\\Acf\\": "src/"
}
},
"autoload-dev": {
Expand Down
38 changes: 19 additions & 19 deletions readme.md
Expand Up @@ -36,7 +36,7 @@ ACF Fluent aims to minimize the mess with a fluent builder that lets you easily
```php
<?php

use Acf\Acf;
use Samrap\Acf\Acf;

$heading = Acf::field('heading')
->default(get_the_title())
Expand All @@ -61,36 +61,36 @@ composer require samrap/acf-fluent

### Basic Usage

All calls to ACF Fluent are done through the `Acf\Acf` class. This class contains static methods which are _factories_ that always return an `Acf\Fluent\Builder` instance. The builder provides the fluent interface for getting and updating fields and sub fields, setting default values, adding constraints, and much more.
All calls to ACF Fluent are done through the `Samrap\Acf\Acf` class. This class contains static methods which are _factories_ that always return an `Samrap\Acf\Fluent\Builder` instance. The builder provides the fluent interface for getting and updating fields and sub fields, setting default values, adding constraints, and much more.

We can retrieve a builder instance for an ACF _field_ by calling the `Acf\Acf::field` method, passing in the name of the field as its argument. Let's take a look:
We can retrieve a builder instance for an ACF _field_ by calling the `Samrap\Acf\Acf::field` method, passing in the name of the field as its argument. Let's take a look:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$field = Acf::field('heading');
```

In the above example, we get a new `Acf\Fluent\Builder` instance for the `heading` ACF field. We can call the `get` method on the builder to retrieve the field:
In the above example, we get a new `Samrap\Acf\Fluent\Builder` instance for the `heading` ACF field. We can call the `get` method on the builder to retrieve the field:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$heading = Acf::field('heading')->get();
```

The same can be done for sub fields just as easily via the `subField` method:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$content = Acf::subField('content')->get();
```

And even global option fields:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$toggle = Acf::option('toggle')->get();
```
Expand Down Expand Up @@ -119,12 +119,12 @@ The real power of ACF Fluent comes when we make full use of the builder. It prov

### Builder Methods

#### `Acf\Fluent\Builder::id(int $id)`
#### `Samrap\Acf\Fluent\Builder::id(int $id)`

Set the post ID to use when getting or updating a field:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$field = Acf::field('url')
->id(2)
Expand All @@ -133,12 +133,12 @@ $field = Acf::field('url')

Alternatively, you may pass the Post ID straight into the static `field` method as the second parameter: `Acf::field('url', 2)->get()`.

#### `Acf\Fluent\Builder::default(mixed $value)`
#### `Samrap\Acf\Fluent\Builder::default(mixed $value)`

Sometimes, ACF fields or sub fields are left empty. We can easily specify a default value by calling the builder's `default` method with any value as its single argument. The default value will be returned if the field is null:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$field = Acf::field('heading')
->default('Hello World')
Expand All @@ -147,12 +147,12 @@ $field = Acf::field('heading')

When we call the builder's get method, it will now check to make sure the call to `get_field` has returned a non-null value. If the value is null, we will instead get the string 'Hello World', otherwise we will get the actual value of the `heading` field.

#### `Acf\Fluent\Builder::expect(string $type)`
#### `Samrap\Acf\Fluent\Builder::expect(string $type)`

We can call the `expect` method on a builder instance to specify the type of value that the field is expected to be:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$field = Acf::subField('items')
->expect('array')
Expand All @@ -162,7 +162,7 @@ $field = Acf::subField('items')
If the result of `items` is an array, then we will get the items just as normal. But if the result is not an array, `null` will be returned as if the value was not even set. Taking our knowledge of this, we can then chain on a `default` value to return instead of null if the type does not match:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$field = Acf::subField('items')
->expect('array')
Expand All @@ -176,12 +176,12 @@ $field = Acf::subField('items')

---

#### `Acf\Fluent\Builder::escape(string $func = 'esc_html')`
#### `Samrap\Acf\Fluent\Builder::escape(string $func = 'esc_html')`

The `escape` method will run the resulting value through a santization function to ensure the value is properly escaped:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$content = Acf::field('content')
->escape()
Expand All @@ -191,7 +191,7 @@ $content = Acf::field('content')
The default santization function is the WordPress [`esc_html`](https://codex.wordpress.org/Function_Reference/esc_html) function. You can specify a different function to run simply by passing the name of the function as the method's single parameter:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

$content = Acf::field('content')
->escape('esc_url')
Expand All @@ -216,7 +216,7 @@ The current supported functions for the `escape` method are:
Though typically less common, you may find yourself updating fields or sub fields from time to time. The fluent builder provides you with the `update` method to do just that:

```php
use Acf\Acf;
use Samrap\Acf\Acf;

Acf::field('heading')->update('Hello World');
Acf::subField('content')
Expand Down
18 changes: 9 additions & 9 deletions src/Acf.php
@@ -1,11 +1,11 @@
<?php

namespace Acf;
namespace Samrap\Acf;

use Acf\Fluent\Runner;
use Acf\Fluent\Builder;
use Acf\Behaviors\FieldBehavior;
use Acf\Behaviors\SubFieldBehavior;
use Samrap\Acf\Fluent\Runner;
use Samrap\Acf\Fluent\Builder;
use Samrap\Acf\Behaviors\FieldBehavior;
use Samrap\Acf\Behaviors\SubFieldBehavior;

class Acf
{
Expand All @@ -24,7 +24,7 @@ private function __construct()
*
* @param string $name
* @param int $id
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public static function field($name, $id = null)
{
Expand All @@ -37,7 +37,7 @@ public static function field($name, $id = null)
* Return a new builder instance for a subfield call.
*
* @param string $name
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public static function subField($name)
{
Expand All @@ -48,7 +48,7 @@ public static function subField($name)
* Return a new builder instance for an option field call.
*
* @param string $name
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public static function option($name)
{
Expand All @@ -61,7 +61,7 @@ public static function option($name)
* Return a builder instance with the given behavior.
*
* @param string $behavior
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
private static function getBuilder($behavior)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Behaviors/BehaviorInterface.php
@@ -1,6 +1,6 @@
<?php

namespace Acf\Behaviors;
namespace Samrap\Acf\Behaviors;

interface BehaviorInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Behaviors/FieldBehavior.php
@@ -1,6 +1,6 @@
<?php

namespace Acf\Behaviors;
namespace Samrap\Acf\Behaviors;

class FieldBehavior implements BehaviorInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Behaviors/SubFieldBehavior.php
@@ -1,6 +1,6 @@
<?php

namespace Acf\Behaviors;
namespace Samrap\Acf\Behaviors;

class SubFieldBehavior implements BehaviorInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/BuilderException.php
@@ -1,6 +1,6 @@
<?php

namespace Acf\Exceptions;
namespace Samrap\Acf\Exceptions;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/RunnerException.php
@@ -1,6 +1,6 @@
<?php

namespace Acf\Exceptions;
namespace Samrap\Acf\Exceptions;

use Exception;

Expand Down
20 changes: 10 additions & 10 deletions src/Fluent/Builder.php
@@ -1,15 +1,15 @@
<?php

namespace Acf\Fluent;
namespace Samrap\Acf\Fluent;

use Acf\Exceptions\BuilderException;
use Samrap\Acf\Exceptions\BuilderException;

class Builder
{
/**
* The Builder's runner.
*
* @var \Acf\Fluent\Runner
* @var \Samrap\Acf\Fluent\Runner
*/
protected $runner;

Expand Down Expand Up @@ -52,7 +52,7 @@ class Builder
/**
* Create a new Builder instance.
*
* @param \Acf\Fluent\Runner $runner
* @param \Samrap\Acf\Fluent\Runner $runner
*/
public function __construct(Runner $runner)
{
Expand All @@ -62,7 +62,7 @@ public function __construct(Runner $runner)
/**
* Get the runner instance.
*
* @return \Acf\Fluent\Runner
* @return \Samrap\Acf\Fluent\Runner
*/
public function getRunner()
{
Expand All @@ -73,7 +73,7 @@ public function getRunner()
* Set the field component.
*
* @param string $name
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public function field($name)
{
Expand All @@ -86,7 +86,7 @@ public function field($name)
* Set the post component.
*
* @param int $id
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public function id($id)
{
Expand All @@ -99,7 +99,7 @@ public function id($id)
* Set the expect component.
*
* @param string $type
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public function expect($type)
{
Expand All @@ -112,7 +112,7 @@ public function expect($type)
* Set the default component.
*
* @param string $default
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public function default($default)
{
Expand All @@ -125,7 +125,7 @@ public function default($default)
* Set the escape component.
*
* @param string $func
* @return \Acf\Fluent\Builder
* @return \Samrap\Acf\Fluent\Builder
*/
public function escape($func = 'esc_html')
{
Expand Down
20 changes: 10 additions & 10 deletions src/Fluent/Runner.php
@@ -1,24 +1,24 @@
<?php

namespace Acf\Fluent;
namespace Samrap\Acf\Fluent;

use Acf\Exceptions\RunnerException;
use Acf\Behaviors\BehaviorInterface;
use Samrap\Acf\Exceptions\RunnerException;
use Samrap\Acf\Behaviors\BehaviorInterface;

class Runner
{
/**
* The behavior to use for ACF function calls.
*
* @var \Acf\Behaviors\BehaviorInterface
* @var \Samrap\Acf\Behaviors\BehaviorInterface
*/
protected $behavior;

/**
* The \Acf\Fluent\Builder components to run.
* The \Samrap\Acf\Fluent\Builder components to run.
*
* The components will be executed in the order defined in this array. Only
* the components defined on the \Acf\Fluent\Builder will be run.
* the components defined on the \Samrap\Acf\Fluent\Builder will be run.
*
* @var array
*/
Expand All @@ -31,7 +31,7 @@ class Runner
/**
* Create a new Runner instance.
*
* @param \Acf\Behaviors\BehaviorInterface $behavior
* @param \Samrap\Acf\Behaviors\BehaviorInterface $behavior
*/
public function __construct(BehaviorInterface $behavior)
{
Expand All @@ -41,7 +41,7 @@ public function __construct(BehaviorInterface $behavior)
/**
* Get the behavior instance.
*
* @return \Acf\Behaviors\BehaviorInterface
* @return \Samrap\Acf\Behaviors\BehaviorInterface
*/
public function getBehavior()
{
Expand All @@ -51,7 +51,7 @@ public function getBehavior()
/**
* Run the ACF 'get' behavior from the given builder.
*
* @param \Acf\Fluent\Builder $builder
* @param \Samrap\Acf\Fluent\Builder $builder
* @return mixed
*/
public function runGet(Builder $builder)
Expand All @@ -75,7 +75,7 @@ public function runGet(Builder $builder)
/**
* Run the ACF 'update' behavior from the given builder.
*
* @param \Acf\Fluent\Builder $builder
* @param \Samrap\Acf\Fluent\Builder $builder
* @param mixed $value
* @return void
*/
Expand Down

0 comments on commit 6cfaa5c

Please sign in to comment.