Completed
Pull Request — master (#19)
by Evan
02:29
created

Builder::open()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
cc 1
eloc 2
nc 1
nop 0
rs 10
1
<?php
2
3
namespace Silk\PostType;
4
5
use Silk\Type\Builder as BaseBuilder;
6
use Illuminate\Support\Collection;
7
use Silk\PostType\Exception\InvalidPostTypeNameException;
8
9
class Builder extends BaseBuilder
10
{
11
    /**
12
     * [$labelDefaults description]
13
     * @var array
14
     */
15
    protected $labelDefaults = [
16
        'add_new_item'          => 'Add New {one}',
17
        'all_items'             => 'All {many}',
18
        'archives'              => '{one} Archives',
19
        'edit_item'             => 'Edit {one}',
20
        'filter_items_list'     => 'Filter {many} list',
21
        'insert_into_item'      => 'Insert into {one}',
22
        'items_list_navigation' => '{many} list navigation',
23
        'items_list'            => '{many} list',
24
        'menu_name'             => '{many}',
25
        'name_admin_bar'        => '{one}',
26
        'name'                  => '{many}',
27
        'new_item'              => 'New {one}',
28
        'not_found_in_trash'    => 'No {many} found in Trash.',
29
        'not_found'             => 'No {many} found.',
30
        'search_items'          => 'Search {many}',
31
        'singular_name'         => '{one}',
32
        'uploaded_to_this_item' => 'Uploaded to this {one}',
33
        'view_item'             => 'View {one}',
34
    ];
35
36
    /**
37
     * Specify which features the post type supports.
38
     *
39
     * @param  mixed $features  array of features
40
     *         string ...$features  features as parameters
41
     *
42
     * @return $this
43
     */
44
    public function supports($features)
45
    {
46
        if (! is_array($features)) {
47
            $features = func_get_args();
48
        }
49
50
        return $this->set('supports', $features);
51
    }
52
53
    /**
54
     * Set the post type as publicly available.
55
     *
56
     * @return $this
57
     */
58
    public function open()
59
    {
60
        return $this->set('public', true);
61
    }
62
63
    /**
64
     * Set the post type as non-publicly available.
65
     *
66
     * @return $this
67
     */
68
    public function closed()
69
    {
70
        return $this->set('public', false);
71
    }
72
73
    /**
74
     * Enable admin interface.
75
     *
76
     * @return $this
77
     */
78
    public function withUI()
79
    {
80
        return $this->set('show_ui', true);
81
    }
82
83
    /**
84
     * Disable admin interface.
85
     *
86
     * @return $this
87
     */
88
    public function noUI()
89
    {
90
        return $this->set('show_ui', false);
91
    }
92
93
    /**
94
     * Register the post type.
95
     *
96
     * @return PostType
97
     */
98
    public function register()
99
    {
100
        if (! $this->id || strlen($this->id) > 20) {
101
            throw new InvalidPostTypeNameException('Post type names must be between 1 and 20 characters in length.');
102
        }
103
104
        $object = register_post_type($this->id, $this->assembleArgs());
105
106
        return new PostType($object);
107
    }
108
}
109