├── .styleci.yml ├── .gitignore ├── src ├── InvalidStatusException.php ├── StatusManager.php ├── HasStatus.php └── Status.php ├── tests ├── Stubs │ ├── Order.php │ └── OrderStatus.php ├── TestCase.php └── Feature │ ├── BaseStatusTest.php │ └── QueryStatusTest.php ├── phpunit.xml ├── composer.json ├── CONTRIBUTING.md ├── .github └── workflows │ └── test.yml ├── readme.md └── LICENSE.md /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | composer.phar 3 | composer.lock 4 | vendor 5 | .php_cs.cache 6 | .phpunit.result.cache 7 | .phpunit.cache 8 | -------------------------------------------------------------------------------- /src/InvalidStatusException.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ./tests/ 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "makeabledk/laravel-eloquent-status", 3 | "license": "CC-BY-SA-4.0", 4 | "autoload": { 5 | "psr-4": { 6 | "Makeable\\EloquentStatus\\": "src/" 7 | } 8 | }, 9 | "require": { 10 | "php": "^8.1", 11 | "illuminate/support": "^10.0|^11.0|^12.0", 12 | "makeabledk/laravel-querykit": "^3.0|^4.0" 13 | }, 14 | "require-dev": { 15 | "laravel/laravel": "^10.3.3|^11.0.5|^12.0", 16 | "phpunit/phpunit": "^10.5.17|^11.0" 17 | }, 18 | "autoload-dev": { 19 | "psr-4": { 20 | "Makeable\\EloquentStatus\\Tests\\": "tests/" 21 | } 22 | }, 23 | "scripts": { 24 | "test": "./vendor/bin/phpunit" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We accept contributions via Pull Requests on [Github](https://github.com/makeabledk/php-value-objects). 4 | 5 | 6 | ## Pull Requests 7 | 8 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - see **fixing styles** section 9 | 10 | - **Add tests** - Your patch must include tests of the added functionality. See **Running tests** section 11 | 12 | - **Document any change in behaviour** - Make sure the `README.md` and `CHANGELOG.md` are kept up-to-date. 13 | 14 | - **Create feature branches** - Don't ask us to pull from your master branch. 15 | 16 | 17 | ## Fixing styles 18 | 19 | ``` bash 20 | $ composer style 21 | ``` 22 | 23 | ## Running Tests 24 | 25 | ``` bash 26 | $ composer test 27 | ``` 28 | 29 | 30 | **Happy coding**! -------------------------------------------------------------------------------- /tests/Stubs/OrderStatus.php: -------------------------------------------------------------------------------- 1 | whereNull('status'); 17 | } 18 | 19 | /** 20 | * @param Builder $query 21 | * @return Builder 22 | */ 23 | public function accepted($query) 24 | { 25 | return $query->where('status', 1); 26 | } 27 | 28 | /** 29 | * @param Builder $query 30 | * @return Builder 31 | */ 32 | public function declined($query) 33 | { 34 | return $query->where('status', 0); 35 | } 36 | 37 | /** 38 | * @return void 39 | */ 40 | private function privateMethodToIgnore() 41 | { 42 | // 43 | } 44 | 45 | /** 46 | * @return void 47 | */ 48 | public static function staticMethodToIgnore() 49 | { 50 | // 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Run tests 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | php: [8.1, 8.2, 8.3, 8.4] 15 | laravel: ['10.*', '11.*', '12.*'] 16 | dependency-version: [prefer-lowest, prefer-stable] 17 | exclude: 18 | - laravel: 11.* 19 | php: 8.1 20 | - laravel: 12.* 21 | php: 8.1 22 | 23 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} 24 | 25 | steps: 26 | - name: Checkout code 27 | uses: actions/checkout@v1 28 | 29 | - name: Setup PHP 30 | uses: shivammathur/setup-php@v2 31 | with: 32 | php-version: ${{ matrix.php }} 33 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick 34 | coverage: none 35 | 36 | - name: Install dependencies 37 | run: | 38 | composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update 39 | composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction 40 | 41 | - name: Execute tests 42 | run: vendor/bin/phpunit 43 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | setUpDatabase($this->app); 16 | } 17 | 18 | /** 19 | * Creates the application. 20 | * 21 | * @return \Illuminate\Foundation\Application 22 | */ 23 | public function createApplication() 24 | { 25 | putenv('APP_ENV=testing'); 26 | putenv('DB_CONNECTION=sqlite'); 27 | putenv('DB_DATABASE=:memory:'); 28 | 29 | $app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php'; 30 | 31 | $app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap(); 32 | $app->register(QueryKitServiceProvider::class); 33 | 34 | return $app; 35 | } 36 | 37 | /** 38 | * @param \Illuminate\Foundation\Application $app 39 | */ 40 | protected function setUpDatabase($app) 41 | { 42 | $app['db']->connection()->getSchemaBuilder()->create('orders', function (Blueprint $table) { 43 | $table->increments('id'); 44 | $table->boolean('status')->nullable(); 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/StatusManager.php: -------------------------------------------------------------------------------- 1 | $status) { 36 | static::bind($model, $status); 37 | } 38 | 39 | return static::$map; 40 | } 41 | 42 | /** 43 | * @param $model 44 | * @return Status 45 | * 46 | * @throws InvalidStatusException 47 | */ 48 | public static function resolveOrFail($model, $status) 49 | { 50 | if ($status instanceof Status) { 51 | return $status; 52 | } 53 | 54 | if ($match = Arr::get(static::$map, get_class($model))) { 55 | return new $match($status); 56 | } 57 | 58 | throw new InvalidStatusException('Couldnt resolve '.$status.' for model '.get_class($model)); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/HasStatus.php: -------------------------------------------------------------------------------- 1 | scope($query); 23 | } 24 | 25 | /** 26 | * @param Builder $query 27 | * @param ArrayAccess|array $statuses 28 | * @return Builder 29 | */ 30 | public function scopeStatusIn($query, $statuses) 31 | { 32 | return $query->where(function ($query) use ($statuses) { 33 | foreach ($statuses as $status) { 34 | $query->orWhere(function ($query) use ($status) { 35 | $this->scopeStatus($query, $status); 36 | }); 37 | } 38 | }); 39 | } 40 | 41 | /** 42 | * @param Status|string $status 43 | * @return bool 44 | */ 45 | public function checkStatus($status) 46 | { 47 | return $this->passesScope('status', $status); 48 | } 49 | 50 | /** 51 | * @param ArrayAccess|array $statuses 52 | * @return bool 53 | */ 54 | public function checkStatusIn($statuses) 55 | { 56 | return $this->passesScope('statusIn', $statuses); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/Feature/BaseStatusTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(3, $statuses->count()); 15 | $this->assertTrue($statuses->first() instanceof OrderStatus); 16 | } 17 | 18 | public function test_it_skips_static_methods() 19 | { 20 | $this->expectException(InvalidStatusException::class); 21 | new OrderStatus('static method to skip'); 22 | } 23 | 24 | public function test_it_skips_private_methods() 25 | { 26 | $this->expectException(InvalidStatusException::class); 27 | new OrderStatus('private method to skip'); 28 | } 29 | 30 | public function test_it_validates_statuses() 31 | { 32 | $this->assertTrue(OrderStatus::validate('accepted')); 33 | $this->assertFalse(OrderStatus::validate('test')); 34 | } 35 | 36 | public function test_it_instantiates_with_valid_value() 37 | { 38 | $status = new OrderStatus('accepted'); 39 | $this->assertTrue($status instanceof OrderStatus); 40 | $this->assertEquals('accepted', $status->get()); 41 | } 42 | 43 | public function test_it_throws_validation_exception() 44 | { 45 | $this->expectException(InvalidStatusException::class); 46 | new OrderStatus('invalid status'); 47 | } 48 | 49 | public function test_it_finds_a_valid_status_or_returns_null() 50 | { 51 | $this->assertInstanceOf(OrderStatus::class, OrderStatus::find('accepted')); 52 | $this->assertNull(OrderStatus::find('foobar')); 53 | } 54 | 55 | public function test_it_casts_to_string() 56 | { 57 | $this->assertEquals('accepted', (string) new OrderStatus('accepted')); 58 | } 59 | 60 | public function test_it_casts_to_array() 61 | { 62 | $this->assertEquals('accepted', (new OrderStatus('accepted'))->toArray()); 63 | } 64 | 65 | public function test_it_converts_to_snake_case() 66 | { 67 | $this->assertEquals('pending_accept', (string) new OrderStatus('pendingAccept')); 68 | $this->assertEquals('pending_accept', (string) new OrderStatus('pending_accept')); 69 | } 70 | 71 | public function test_it_converts_to_title() 72 | { 73 | $this->assertEquals('Pending Accept', (new OrderStatus('pendingAccept'))->getTitle()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/Feature/QueryStatusTest.php: -------------------------------------------------------------------------------- 1 | 1]); 23 | Order::create(['status' => 1]); 24 | Order::create(['status' => 0]); 25 | 26 | $this->assertEquals(2, Order::status(new OrderStatus('accepted'))->count()); 27 | $this->assertEquals(1, Order::status(new OrderStatus('declined'))->count()); 28 | } 29 | 30 | public function test_it_checks_a_model_against_a_status() 31 | { 32 | $order = Order::create(['status' => 1]); 33 | 34 | $this->assertTrue($order->checkStatus(new OrderStatus('accepted'))); 35 | $this->assertFalse($order->checkStatus(new OrderStatus('declined'))); 36 | } 37 | 38 | public function test_it_guesses_a_models_status() 39 | { 40 | $model = Order::create(['status' => 0]); 41 | $this->assertEquals('declined', OrderStatus::guess($model)->get()); 42 | 43 | $model = Order::create(['status' => null]); 44 | $this->assertEquals('pending_accept', OrderStatus::guess($model)->get()); 45 | } 46 | 47 | /** @test **/ 48 | public function it_accepts_valid_string_status_when_mapped_in_manager() 49 | { 50 | $model = Order::create(['status' => 1]); 51 | 52 | $this->expectException(InvalidStatusException::class); 53 | $model->checkStatus('accepted'); 54 | 55 | StatusManager::bind(Order::class, OrderStatus::class); 56 | $this->assertTrue($model->checkStatus('accepted')); 57 | } 58 | 59 | /** @test **/ 60 | public function it_queries_database_where_status_in_haystack() 61 | { 62 | Order::create(['status' => 1]); 63 | Order::create(['status' => 0]); 64 | Order::create(['status' => null]); 65 | 66 | StatusManager::bind(Order::class, OrderStatus::class); 67 | 68 | $acceptedOrDeclined = Order::statusIn(['accepted', 'declined'])->get(); 69 | 70 | $this->assertCount(2, $acceptedOrDeclined); 71 | $this->assertEquals([1, 2], $acceptedOrDeclined->pluck('id')->toArray()); 72 | } 73 | 74 | /** @test **/ 75 | public function it_checks_models_if_status_in_haystack() 76 | { 77 | StatusManager::bind(Order::class, OrderStatus::class); 78 | 79 | $this->assertTrue(Order::create(['status' => 1])->checkStatusIn(['accepted', 'declined'])); 80 | $this->assertTrue(Order::create(['status' => 0])->checkStatusIn(['accepted', 'declined'])); 81 | $this->assertFalse(Order::create(['status' => null])->checkStatusIn(['accepted', 'declined'])); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Status.php: -------------------------------------------------------------------------------- 1 | value = $value; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function __toString() 43 | { 44 | return $this->get(); 45 | } 46 | 47 | /** 48 | * @param $value 49 | * @return Status|null 50 | */ 51 | public static function find($value) 52 | { 53 | try { 54 | return new static($value); 55 | } catch (InvalidStatusException $e) { 56 | return; 57 | } 58 | } 59 | 60 | /** 61 | * @return string 62 | */ 63 | public function jsonSerialize(): mixed 64 | { 65 | return $this->toArray(); 66 | } 67 | 68 | /** 69 | * @return string 70 | */ 71 | public function toArray() 72 | { 73 | return $this->get(); 74 | } 75 | 76 | /** 77 | * @return Collection 78 | * 79 | * @throws ReflectionException 80 | */ 81 | public static function all() 82 | { 83 | $class = new ReflectionClass(static::class); 84 | 85 | return collect($class->getMethods(ReflectionMethod::IS_PUBLIC)) 86 | ->filter(function (ReflectionMethod $method) { 87 | return $method->getDeclaringClass()->getName() === static::class; 88 | }) 89 | ->reject(function (ReflectionMethod $method) { 90 | return $method->isStatic(); 91 | }) 92 | ->map(function (ReflectionMethod $method) { 93 | return new static($method->getName(), false); 94 | }); 95 | } 96 | 97 | /** 98 | * @param $model 99 | * @return Status 100 | * 101 | * @throws Exception 102 | */ 103 | public static function guess($model) 104 | { 105 | if (! method_exists($model, 'checkStatus')) { 106 | throw new Exception(class_basename($model).' must implement a checkStatus() method'); 107 | } 108 | 109 | return static::all()->first(function ($status) use ($model) { 110 | return $model->checkStatus($status); 111 | }); 112 | } 113 | 114 | /** 115 | * @param $value 116 | * @return bool 117 | */ 118 | public static function validate($value) 119 | { 120 | return static::all()->contains($value); 121 | } 122 | 123 | /** 124 | * @return string 125 | */ 126 | public function get() 127 | { 128 | return $this->value; 129 | } 130 | 131 | /** 132 | * @return string 133 | */ 134 | public function getTitle() 135 | { 136 | return str_replace('_', ' ', Str::title($this->value)); 137 | } 138 | 139 | /** 140 | * @param $query 141 | * @return Builder 142 | */ 143 | public function scope($query) 144 | { 145 | $method = Str::camel($this->get()); 146 | 147 | return $this->$method($query); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Laravel Eloquent Status 3 | 4 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/makeabledk/laravel-eloquent-status.svg?style=flat-square)](https://packagist.org/packages/makeabledk/laravel-eloquent-status) 5 | [![Build Status](https://img.shields.io/github/workflow/status/makeabledk/laravel-eloquent-status/Run%20tests?label=Tests)](https://github.com/makeabledk/laravel-eloquent-status/actions) 6 | [![StyleCI](https://styleci.io/repos/102474433/shield?branch=master)](https://styleci.io/repos/102474433) 7 | 8 | **Check out the blog post explaining the concepts of this package:** 9 | 10 | https://medium.com/@rasmuscnielsen/an-eloquent-way-of-handling-model-state-c9aa372e9cb8 11 | ___ 12 | 13 | Most models has some sort of status or state to it. Few examples could be 14 | 15 | - Post: draft, private, published, 16 | - Job: applied, accepted, declined, completed, cancelled 17 | - Approval: pending, reviewing, approved 18 | 19 | Traditionally you may find yourself having a `scopeAccepted` and then additionally a `ìsAccepted` helper method to test a model-instance against a specific status. 20 | 21 | This package offers a very handy way of dealing with statuses like these without cluttering you model. 22 | 23 | When you've successfully setup this package you'll be able to achieve syntax like 24 | 25 | ````php 26 | Approval::status('approved')->get(); // Collection 27 | ```` 28 | 29 | ````php 30 | $model->checkStatus('approved'); // bool 31 | ```` 32 | 33 | ___ 34 | 35 | Makeable is web- and mobile app agency located in Aarhus, Denmark. 36 | 37 | ## Installation 38 | 39 | You can install this package via composer: 40 | 41 | ``` bash 42 | composer require makeabledk/laravel-eloquent-status 43 | ``` 44 | 45 | ## Example usage 46 | 47 | Given our Approval example from earlier we may have the following database fields: 48 | 49 | - id 50 | - *... (some foreign keys)* 51 | - tutor_approved_at 52 | - teacher_approved_at 53 | - assessor_approved_at 54 | - created_at 55 | - updated_at 56 | 57 | Let's start out by creating a status class that holds our status definitions 58 | 59 | ### Getting started 60 | 61 | #### 1. Create a status class 62 | 63 | We will define all our valid statuses as public functions in a dedicated status class. 64 | 65 | ````php 66 | whereNull('tutor_approved_at') 74 | ->whereNull('teacher_approved_at') 75 | ->whereNull('assessor_approved_at'); 76 | } 77 | 78 | public function reviewing($query) 79 | { 80 | return $query 81 | ->whereNotNull('tutor_approved_at') 82 | ->whereNull('assessor_approved_at'); 83 | } 84 | 85 | public function approved($query) 86 | { 87 | return $query 88 | ->whereNotNull('tutor_approved_at') 89 | ->whereNotNull('teacher_approved_at') 90 | ->whereNotNull('assessor_approved_at'); 91 | } 92 | } 93 | ```` 94 | 95 | Notice how the statuses are defined just like regular `scope` functions. While this example is super simple, you have the full power of the Eloquent Query Builder at your disposal! 96 | 97 | **🔥 Tip:** We recommend that your statuses has unambiguous definitions, meaning that a model can only pass one definition at a time. 98 | This will come in handy in the next few steps. 99 | 100 | #### 2. Apply trait on the model 101 | 102 | ```php 103 | get(); 118 | ``` 119 | 120 | Again, notice how this is very close to just calling a scope like we're used to: `Approval::pending()`. 121 | 122 | However there are som benefits to this new approach. 123 | 124 | - We've defined and encapsulated all our statuses in one place de-cluttering our model 125 | - We can only query against valid statuses 126 | 127 | ```php 128 | Approval::status(new ApprovalStatus('something-else'))->get(); // throws exception 129 | ``` 130 | 131 | For instance this makes it convenient and safe to accept a raw status from a GET filter in your controller and return the result with no further validation or if-switches. 132 | 133 | 134 | ### 🔥 Checking model status 135 | 136 | The real magic of the package! 137 | 138 | We can actually use the same status definitions to check if a model instance adheres to a given status. 139 | 140 | ````php 141 | $approval->checkStatus(new ApprovalStatus('reviewing')); // true or false 142 | ```` 143 | 144 | This sorcery is powered by our other package [makeabledk/laravel-query-kit](https://github.com/makeabledk/laravel-query-kit). 145 | 146 | **Note:** Make sure to see the *Limitations* section of this readme. 147 | 148 | ### Guessing model status 149 | 150 | What if you wanted to know *which* status a model is from its attributes? Well you're in luck. 151 | 152 | ````php 153 | 154 | status` would attempt resolve the approval status from your definitions. 169 | 170 | **Note:** The status is guessed by checking each definition one-by-one until one passes. This is why you may consider unambiguous definitions. 171 | 172 | Also you should be careful not to load relations in your definitions and generally consider a caching-strategy for large query-sets. 173 | 174 | Furthermore see the *Limitations* section of this readme. 175 | 176 | ### Binding a default status to a model 177 | 178 | Rather than passing an instance of a status class each time you perform a check, you may bind a default status class to your model: 179 | 180 | ````php 181 | use Makeable\EloquentStatus\StatusManager; 182 | 183 | StatusManager::bind(Approval::class, ApprovalStatus::class); 184 | ```` 185 | 186 | Now you may simply type name of the status 187 | 188 | ```php 189 | $approval->checkStatus('accepted'); 190 | ``` 191 | Other status classes than the default can still be used when passed explicitly. 192 | 193 | You may bind the status classes in the `boot` function of your `AppServiceProvider` or create a separate service provider if you wish. 194 | 195 | 196 | ## Limitations 197 | 198 | This package is an abstraction on top of [makeabledk/laravel-query-kit](https://github.com/makeabledk/laravel-query-kit). 199 | 200 | QueryKit provides a mocked version of the native QueryBuilder, allowing to run a scope function against a model instance. 201 | 202 | This approach ensures great performance with no DB-queries needed, but introduces certain limitations. 203 | 204 | While QueryKit supports most QueryBuilder syntaxes such as closures and nested queries, it *does not* support SQL language such as joins and selects. These limitation only applies to `checkStatus()` and `guess()` functions. 205 | 206 | Check out the **Limitations** section in the [makeabledk/laravel-query-kit documentation](https://github.com/makeabledk/laravel-query-kit) for more information. 207 | 208 | 209 | ## Available methods on `HasStatus` 210 | 211 | **- scopeStatus($status)** 212 | 213 | ```php 214 | Approval::status(new ApprovalStatus('approved'))->get(); // Collection 215 | 216 | // Or when default status is defined 217 | Approval::status('approved')->get(); // Collection 218 | ``` 219 | 220 | **- scopeStatusIn($statuses)** 221 | 222 | ```php 223 | Approval::statusIn(['pending', 'reviewing'])->get(); // Collection 224 | ``` 225 | 226 | **- checkStatus** 227 | 228 | ```php 229 | $approval->checkStatus('approved'); // bool 230 | ``` 231 | 232 | **- checkStatusIn** 233 | 234 | ```php 235 | $approval->checkStatusIn(['pending', 'reviewing']); // bool 236 | ``` 237 | 238 | ## Testing 239 | 240 | You can run the tests with: 241 | 242 | ```bash 243 | composer test 244 | ``` 245 | 246 | ## Contributing 247 | 248 | We are happy to receive pull requests for additional functionality. Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 249 | 250 | ## Credits 251 | 252 | - [Rasmus Christoffer Nielsen](https://github.com/rasmuscnielsen) 253 | - [All Contributors](../../contributors) 254 | 255 | ## License 256 | 257 | Attribution-ShareAlike 4.0 International. Please see [License File](LICENSE.md) for more information. 258 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | wiki.creativecommons.org/Considerations_for_licensors 37 | 38 | Considerations for the public: By using one of our public 39 | licenses, a licensor grants the public permission to use the 40 | licensed material under specified terms and conditions. If 41 | the licensor's permission is not necessary for any reason--for 42 | example, because of any applicable exception or limitation to 43 | copyright--then that use is not regulated by the license. Our 44 | licenses grant only permissions under copyright and certain 45 | other rights that a licensor has authority to grant. Use of 46 | the licensed material may still be restricted for other 47 | reasons, including because others have copyright or other 48 | rights in the material. A licensor may make special requests, 49 | such as asking that all changes be marked or described. 50 | Although not required by our licenses, you are encouraged to 51 | respect those requests where reasonable. More_considerations 52 | for the public: 53 | wiki.creativecommons.org/Considerations_for_licensees 54 | 55 | ======================================================================= 56 | 57 | Creative Commons Attribution-ShareAlike 4.0 International Public 58 | License 59 | 60 | By exercising the Licensed Rights (defined below), You accept and agree 61 | to be bound by the terms and conditions of this Creative Commons 62 | Attribution-ShareAlike 4.0 International Public License ("Public 63 | License"). To the extent this Public License may be interpreted as a 64 | contract, You are granted the Licensed Rights in consideration of Your 65 | acceptance of these terms and conditions, and the Licensor grants You 66 | such rights in consideration of benefits the Licensor receives from 67 | making the Licensed Material available under these terms and 68 | conditions. 69 | 70 | 71 | Section 1 -- Definitions. 72 | 73 | a. Adapted Material means material subject to Copyright and Similar 74 | Rights that is derived from or based upon the Licensed Material 75 | and in which the Licensed Material is translated, altered, 76 | arranged, transformed, or otherwise modified in a manner requiring 77 | permission under the Copyright and Similar Rights held by the 78 | Licensor. For purposes of this Public License, where the Licensed 79 | Material is a musical work, performance, or sound recording, 80 | Adapted Material is always produced where the Licensed Material is 81 | synched in timed relation with a moving image. 82 | 83 | b. Adapter's License means the license You apply to Your Copyright 84 | and Similar Rights in Your contributions to Adapted Material in 85 | accordance with the terms and conditions of this Public License. 86 | 87 | c. BY-SA Compatible License means a license listed at 88 | creativecommons.org/compatiblelicenses, approved by Creative 89 | Commons as essentially the equivalent of this Public License. 90 | 91 | d. Copyright and Similar Rights means copyright and/or similar rights 92 | closely related to copyright including, without limitation, 93 | performance, broadcast, sound recording, and Sui Generis Database 94 | Rights, without regard to how the rights are labeled or 95 | categorized. For purposes of this Public License, the rights 96 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 97 | Rights. 98 | 99 | e. Effective Technological Measures means those measures that, in the 100 | absence of proper authority, may not be circumvented under laws 101 | fulfilling obligations under Article 11 of the WIPO Copyright 102 | Treaty adopted on December 20, 1996, and/or similar international 103 | agreements. 104 | 105 | f. Exceptions and Limitations means fair use, fair dealing, and/or 106 | any other exception or limitation to Copyright and Similar Rights 107 | that applies to Your use of the Licensed Material. 108 | 109 | g. License Elements means the license attributes listed in the name 110 | of a Creative Commons Public License. The License Elements of this 111 | Public License are Attribution and ShareAlike. 112 | 113 | h. Licensed Material means the artistic or literary work, database, 114 | or other material to which the Licensor applied this Public 115 | License. 116 | 117 | i. Licensed Rights means the rights granted to You subject to the 118 | terms and conditions of this Public License, which are limited to 119 | all Copyright and Similar Rights that apply to Your use of the 120 | Licensed Material and that the Licensor has authority to license. 121 | 122 | j. Licensor means the individual(s) or entity(ies) granting rights 123 | under this Public License. 124 | 125 | k. Share means to provide material to the public by any means or 126 | process that requires permission under the Licensed Rights, such 127 | as reproduction, public display, public performance, distribution, 128 | dissemination, communication, or importation, and to make material 129 | available to the public including in ways that members of the 130 | public may access the material from a place and at a time 131 | individually chosen by them. 132 | 133 | l. Sui Generis Database Rights means rights other than copyright 134 | resulting from Directive 96/9/EC of the European Parliament and of 135 | the Council of 11 March 1996 on the legal protection of databases, 136 | as amended and/or succeeded, as well as other essentially 137 | equivalent rights anywhere in the world. 138 | 139 | m. You means the individual or entity exercising the Licensed Rights 140 | under this Public License. Your has a corresponding meaning. 141 | 142 | 143 | Section 2 -- Scope. 144 | 145 | a. License grant. 146 | 147 | 1. Subject to the terms and conditions of this Public License, 148 | the Licensor hereby grants You a worldwide, royalty-free, 149 | non-sublicensable, non-exclusive, irrevocable license to 150 | exercise the Licensed Rights in the Licensed Material to: 151 | 152 | a. reproduce and Share the Licensed Material, in whole or 153 | in part; and 154 | 155 | b. produce, reproduce, and Share Adapted Material. 156 | 157 | 2. Exceptions and Limitations. For the avoidance of doubt, where 158 | Exceptions and Limitations apply to Your use, this Public 159 | License does not apply, and You do not need to comply with 160 | its terms and conditions. 161 | 162 | 3. Term. The term of this Public License is specified in Section 163 | 6(a). 164 | 165 | 4. Media and formats; technical modifications allowed. The 166 | Licensor authorizes You to exercise the Licensed Rights in 167 | all media and formats whether now known or hereafter created, 168 | and to make technical modifications necessary to do so. The 169 | Licensor waives and/or agrees not to assert any right or 170 | authority to forbid You from making technical modifications 171 | necessary to exercise the Licensed Rights, including 172 | technical modifications necessary to circumvent Effective 173 | Technological Measures. For purposes of this Public License, 174 | simply making modifications authorized by this Section 2(a) 175 | (4) never produces Adapted Material. 176 | 177 | 5. Downstream recipients. 178 | 179 | a. Offer from the Licensor -- Licensed Material. Every 180 | recipient of the Licensed Material automatically 181 | receives an offer from the Licensor to exercise the 182 | Licensed Rights under the terms and conditions of this 183 | Public License. 184 | 185 | b. Additional offer from the Licensor -- Adapted Material. 186 | Every recipient of Adapted Material from You 187 | automatically receives an offer from the Licensor to 188 | exercise the Licensed Rights in the Adapted Material 189 | under the conditions of the Adapter's License You apply. 190 | 191 | c. No downstream restrictions. You may not offer or impose 192 | any additional or different terms or conditions on, or 193 | apply any Effective Technological Measures to, the 194 | Licensed Material if doing so restricts exercise of the 195 | Licensed Rights by any recipient of the Licensed 196 | Material. 197 | 198 | 6. No endorsement. Nothing in this Public License constitutes or 199 | may be construed as permission to assert or imply that You 200 | are, or that Your use of the Licensed Material is, connected 201 | with, or sponsored, endorsed, or granted official status by, 202 | the Licensor or others designated to receive attribution as 203 | provided in Section 3(a)(1)(A)(i). 204 | 205 | b. Other rights. 206 | 207 | 1. Moral rights, such as the right of integrity, are not 208 | licensed under this Public License, nor are publicity, 209 | privacy, and/or other similar personality rights; however, to 210 | the extent possible, the Licensor waives and/or agrees not to 211 | assert any such rights held by the Licensor to the limited 212 | extent necessary to allow You to exercise the Licensed 213 | Rights, but not otherwise. 214 | 215 | 2. Patent and trademark rights are not licensed under this 216 | Public License. 217 | 218 | 3. To the extent possible, the Licensor waives any right to 219 | collect royalties from You for the exercise of the Licensed 220 | Rights, whether directly or through a collecting society 221 | under any voluntary or waivable statutory or compulsory 222 | licensing scheme. In all other cases the Licensor expressly 223 | reserves any right to collect such royalties. 224 | 225 | 226 | Section 3 -- License Conditions. 227 | 228 | Your exercise of the Licensed Rights is expressly made subject to the 229 | following conditions. 230 | 231 | a. Attribution. 232 | 233 | 1. If You Share the Licensed Material (including in modified 234 | form), You must: 235 | 236 | a. retain the following if it is supplied by the Licensor 237 | with the Licensed Material: 238 | 239 | i. identification of the creator(s) of the Licensed 240 | Material and any others designated to receive 241 | attribution, in any reasonable manner requested by 242 | the Licensor (including by pseudonym if 243 | designated); 244 | 245 | ii. a copyright notice; 246 | 247 | iii. a notice that refers to this Public License; 248 | 249 | iv. a notice that refers to the disclaimer of 250 | warranties; 251 | 252 | v. a URI or hyperlink to the Licensed Material to the 253 | extent reasonably practicable; 254 | 255 | b. indicate if You modified the Licensed Material and 256 | retain an indication of any previous modifications; and 257 | 258 | c. indicate the Licensed Material is licensed under this 259 | Public License, and include the text of, or the URI or 260 | hyperlink to, this Public License. 261 | 262 | 2. You may satisfy the conditions in Section 3(a)(1) in any 263 | reasonable manner based on the medium, means, and context in 264 | which You Share the Licensed Material. For example, it may be 265 | reasonable to satisfy the conditions by providing a URI or 266 | hyperlink to a resource that includes the required 267 | information. 268 | 269 | 3. If requested by the Licensor, You must remove any of the 270 | information required by Section 3(a)(1)(A) to the extent 271 | reasonably practicable. 272 | 273 | b. ShareAlike. 274 | 275 | In addition to the conditions in Section 3(a), if You Share 276 | Adapted Material You produce, the following conditions also apply. 277 | 278 | 1. The Adapter's License You apply must be a Creative Commons 279 | license with the same License Elements, this version or 280 | later, or a BY-SA Compatible License. 281 | 282 | 2. You must include the text of, or the URI or hyperlink to, the 283 | Adapter's License You apply. You may satisfy this condition 284 | in any reasonable manner based on the medium, means, and 285 | context in which You Share Adapted Material. 286 | 287 | 3. You may not offer or impose any additional or different terms 288 | or conditions on, or apply any Effective Technological 289 | Measures to, Adapted Material that restrict exercise of the 290 | rights granted under the Adapter's License You apply. 291 | 292 | 293 | Section 4 -- Sui Generis Database Rights. 294 | 295 | Where the Licensed Rights include Sui Generis Database Rights that 296 | apply to Your use of the Licensed Material: 297 | 298 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 299 | to extract, reuse, reproduce, and Share all or a substantial 300 | portion of the contents of the database; 301 | 302 | b. if You include all or a substantial portion of the database 303 | contents in a database in which You have Sui Generis Database 304 | Rights, then the database in which You have Sui Generis Database 305 | Rights (but not its individual contents) is Adapted Material, 306 | 307 | including for purposes of Section 3(b); and 308 | c. You must comply with the conditions in Section 3(a) if You Share 309 | all or a substantial portion of the contents of the database. 310 | 311 | For the avoidance of doubt, this Section 4 supplements and does not 312 | replace Your obligations under this Public License where the Licensed 313 | Rights include other Copyright and Similar Rights. 314 | 315 | 316 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 317 | 318 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 319 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 320 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 321 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 322 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 323 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 324 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 325 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 326 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 327 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 328 | 329 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 330 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 331 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 332 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 333 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 334 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 335 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 336 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 337 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 338 | 339 | c. The disclaimer of warranties and limitation of liability provided 340 | above shall be interpreted in a manner that, to the extent 341 | possible, most closely approximates an absolute disclaimer and 342 | waiver of all liability. 343 | 344 | 345 | Section 6 -- Term and Termination. 346 | 347 | a. This Public License applies for the term of the Copyright and 348 | Similar Rights licensed here. However, if You fail to comply with 349 | this Public License, then Your rights under this Public License 350 | terminate automatically. 351 | 352 | b. Where Your right to use the Licensed Material has terminated under 353 | Section 6(a), it reinstates: 354 | 355 | 1. automatically as of the date the violation is cured, provided 356 | it is cured within 30 days of Your discovery of the 357 | violation; or 358 | 359 | 2. upon express reinstatement by the Licensor. 360 | 361 | For the avoidance of doubt, this Section 6(b) does not affect any 362 | right the Licensor may have to seek remedies for Your violations 363 | of this Public License. 364 | 365 | c. For the avoidance of doubt, the Licensor may also offer the 366 | Licensed Material under separate terms or conditions or stop 367 | distributing the Licensed Material at any time; however, doing so 368 | will not terminate this Public License. 369 | 370 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 371 | License. 372 | 373 | 374 | Section 7 -- Other Terms and Conditions. 375 | 376 | a. The Licensor shall not be bound by any additional or different 377 | terms or conditions communicated by You unless expressly agreed. 378 | 379 | b. Any arrangements, understandings, or agreements regarding the 380 | Licensed Material not stated herein are separate from and 381 | independent of the terms and conditions of this Public License. 382 | 383 | 384 | Section 8 -- Interpretation. 385 | 386 | a. For the avoidance of doubt, this Public License does not, and 387 | shall not be interpreted to, reduce, limit, restrict, or impose 388 | conditions on any use of the Licensed Material that could lawfully 389 | be made without permission under this Public License. 390 | 391 | b. To the extent possible, if any provision of this Public License is 392 | deemed unenforceable, it shall be automatically reformed to the 393 | minimum extent necessary to make it enforceable. If the provision 394 | cannot be reformed, it shall be severed from this Public License 395 | without affecting the enforceability of the remaining terms and 396 | conditions. 397 | 398 | c. No term or condition of this Public License will be waived and no 399 | failure to comply consented to unless expressly agreed to by the 400 | Licensor. 401 | 402 | d. Nothing in this Public License constitutes or may be interpreted 403 | as a limitation upon, or waiver of, any privileges and immunities 404 | that apply to the Licensor or You, including from the legal 405 | processes of any jurisdiction or authority. 406 | 407 | 408 | ======================================================================= 409 | 410 | Creative Commons is not a party to its public 411 | licenses. Notwithstanding, Creative Commons may elect to apply one of 412 | its public licenses to material it publishes and in those instances 413 | will be considered the “Licensor.” The text of the Creative Commons 414 | public licenses is dedicated to the public domain under the CC0 Public 415 | Domain Dedication. Except for the limited purpose of indicating that 416 | material is shared under a Creative Commons public license or as 417 | otherwise permitted by the Creative Commons policies published at 418 | creativecommons.org/policies, Creative Commons does not authorize the 419 | use of the trademark "Creative Commons" or any other trademark or logo 420 | of Creative Commons without its prior written consent including, 421 | without limitation, in connection with any unauthorized modifications 422 | to any of its public licenses or any other arrangements, 423 | understandings, or agreements concerning use of licensed material. For 424 | the avoidance of doubt, this paragraph does not form part of the 425 | public licenses. 426 | 427 | Creative Commons may be contacted at creativecommons.org. --------------------------------------------------------------------------------