Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Change namespace to TightenCo and alias to Illuminate namespace #56

Merged
merged 10 commits into from
Jan 31, 2018
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
},
"autoload": {
"files": [
"src/Illuminate/Support/helpers.php"
"src/Tightenco/Support/helpers.php",
"src/Tightenco/Support/alias.php"
],
"psr-4": {
"Illuminate\\": "src/Illuminate"
"Tightenco\\": "src/Tightenco"
}
},
"minimum-stability": "dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Illuminate\Contracts\Support;
namespace Tightenco\Contracts\Support;

interface Arrayable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Illuminate\Contracts\Support;
namespace Tightenco\Contracts\Support;

interface Jsonable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Illuminate\Support;
namespace Tightenco\Support;

use ArrayAccess;
use InvalidArgumentException;
use Illuminate\Support\Traits\Macroable;
use Tightenco\Support\Traits\Macroable;

class Arr
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Illuminate\Support;
namespace Tightenco\Support;

use Countable;
use Exception;
Expand All @@ -10,10 +10,10 @@
use CachingIterator;
use JsonSerializable;
use IteratorAggregate;
use Illuminate\Support\Debug\Dumper;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
use Tightenco\Support\Debug\Dumper;
use Tightenco\Support\Traits\Macroable;
use Tightenco\Contracts\Support\Jsonable;
use Tightenco\Contracts\Support\Arrayable;

class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable
{
Expand Down Expand Up @@ -1616,7 +1616,7 @@ public function count()
/**
* Get a base Support collection instance from this collection.
*
* @return \Illuminate\Support\Collection
* @return \Tightenco\Support\Collection
*/
public function toBase()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace Illuminate\Support;
namespace Tightenco\Support;

/**
* @mixin \Illuminate\Support\Collection
* @mixin \Tightenco\Support\Collection
*/
class HigherOrderCollectionProxy
{
/**
* The collection being operated on.
*
* @var \Illuminate\Support\Collection
* @var \Tightenco\Support\Collection
*/
protected $collection;

Expand All @@ -24,7 +24,7 @@ class HigherOrderCollectionProxy
/**
* Create a new proxy instance.
*
* @param \Illuminate\Support\Collection $collection
* @param \Tightenco\Support\Collection $collection
* @param string $method
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Illuminate\Support\Traits;
namespace Tightenco\Support\Traits;

use Closure;
use ReflectionClass;
use ReflectionMethod;
use BadMethodCallException;
use Illuminate\Contracts\Support\Macro;
use Tightenco\Contracts\Support\Macro;

trait Macroable
{
Expand Down
16 changes: 16 additions & 0 deletions src/Tightenco/Support/alias.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$aliases = [
Tightenco\Contracts\Support\Arrayable::class => Illuminate\Contracts\Support\Arrayable::class,
Tightenco\Contracts\Support\Jsonable::class => Illuminate\Contracts\Support\Jsonable::class,
Tightenco\Support\Traits\Macroable::class => Illuminate\Support\Traits\Macroable::class,
Tightenco\Support\Arr::class => Illuminate\Support\Arr::class,
Tightenco\Support\Collection::class => Illuminate\Support\Collection::class,
Tightenco\Support\HigherOrderCollectionProxy::class => Illuminate\Support\HigherOrderCollectionProxy::class,
];

foreach ($aliases as $tighten => $illuminate) {
if (! class_exists($illuminate) && ! interface_exists($illuminate) && ! trait_exists($illuminate)) {
class_alias($tighten, $illuminate);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we would be wiser to alias either all classes, or none of them if there's a single conflict. Theoretically, we could end up with a mixture of Laravel and Collect classes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sort of doubt it, but I still like the idea of a single check instead of many.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Tightenco\Support\Arr;
use Tightenco\Support\Collection;

if (! function_exists('array_wrap')) {
/**
Expand All @@ -21,7 +21,7 @@ function array_wrap($value)
* Create a collection from the given value.
*
* @param mixed $value
* @return \Illuminate\Support\Collection
* @return \Tightenco\Support\Collection
*/
function collect($value = null)
{
Expand Down
14 changes: 7 additions & 7 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace Illuminate\Tests\Support;
namespace Tightenco\Tests\Support;

use stdClass;
use ArrayAccess;
use Mockery as m;
use ReflectionClass;
use JsonSerializable;
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;
use Tightenco\Support\Collection;
use Tightenco\Contracts\Support\Jsonable;
use Tightenco\Contracts\Support\Arrayable;

class SupportCollectionTest extends TestCase
{
Expand Down Expand Up @@ -160,9 +160,9 @@ public function testGetArrayableItems()

public function testToArrayCallsToArrayOnEachItemInCollection()
{
$item1 = m::mock('Illuminate\Contracts\Support\Arrayable');
$item1 = m::mock('Tightenco\Contracts\Support\Arrayable');
$item1->shouldReceive('toArray')->once()->andReturn('foo.array');
$item2 = m::mock('Illuminate\Contracts\Support\Arrayable');
$item2 = m::mock('Tightenco\Contracts\Support\Arrayable');
$item2->shouldReceive('toArray')->once()->andReturn('bar.array');
$c = new Collection([$item1, $item2]);
$results = $c->toArray();
Expand All @@ -174,7 +174,7 @@ public function testJsonSerializeCallsToArrayOrJsonSerializeOnEachItemInCollecti
{
$item1 = m::mock('JsonSerializable');
$item1->shouldReceive('jsonSerialize')->once()->andReturn('foo.json');
$item2 = m::mock('Illuminate\Contracts\Support\Arrayable');
$item2 = m::mock('Tightenco\Contracts\Support\Arrayable');
$item2->shouldReceive('toArray')->once()->andReturn('bar.array');
$c = new Collection([$item1, $item2]);
$results = $c->jsonSerialize();
Expand Down