| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace Dcat\Admin\Support;
- use Illuminate\Contracts\Support\Arrayable;
- use Illuminate\Support\Arr;
- /**
- * @property string $name
- * @property string $description
- * @property string $type
- * @property array $keywords
- * @property string $homepage
- * @property string $license
- * @property array $authors
- * @property array $require
- * @property array $require_dev
- * @property array $suggest
- * @property array $autoload
- * @property array $autoload_dev
- * @property array $scripts
- * @property array $extra
- * @property string $version
- */
- class ComposerProperty implements Arrayable
- {
- /**
- * @var array
- */
- protected $attributes = [];
- public function __construct(array $attributes = [])
- {
- $this->attributes = $attributes;
- }
- /**
- * @param $key
- * @param null $default
- * @return mixed
- */
- public function get($key, $default = null)
- {
- return Arr::get($this->attributes, $key, $default);
- }
- /**
- * @param $key
- * @param $val
- * @return $this
- */
- public function set($key, $val)
- {
- $new = $this->attributes;
- Arr::set($new, $key, $val);
- return new static($new);
- }
- /**
- * @param $key
- * @return $this
- */
- public function delete($key)
- {
- $new = $this->attributes;
- Arr::forget($new, $key);
- return new static($new);
- }
- /**
- * @param $name
- * @return mixed
- */
- public function __get($name)
- {
- return $this->get(str_replace('_', '-', $name));
- }
- public function toArray()
- {
- return $this->attributes;
- }
- public function toJson()
- {
- return json_encode($this->toArray());
- }
- }
|