Skip to content

Commit

Permalink
Namespace refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
skito committed Aug 11, 2022
1 parent 0234c62 commit 2cb5ea3
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/Entase/Client.php → src/Client.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entase;
namespace Entase\SDK;


class Client
Expand Down
2 changes: 1 addition & 1 deletion src/Entase/Endpoint.php → src/Endpoint.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entase;
namespace Entase\SDK;

class Endpoint
{
Expand Down
4 changes: 2 additions & 2 deletions src/Entase/Endpoints/Events.php → src/Endpoints/Events.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Entase\Endpoints;
namespace Entase\SDK\Endpoints;

class Events extends \Entase\Endpoint
class Events extends \Entase\SDK\Endpoint
{
public function __construct($client)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Entase\Endpoints;
namespace Entase\SDK\Endpoints;

class Productions extends \Entase\Endpoint
class Productions extends \Entase\SDK\Endpoint
{
public function __construct($client)
{
Expand Down
Empty file removed src/Entase/Exception.php
Empty file.
2 changes: 1 addition & 1 deletion src/Entase/Env.php → src/Env.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entase;
namespace Entase\SDK;

abstract class Env
{
Expand Down
2 changes: 1 addition & 1 deletion src/Entase/Exceptions/API.php → src/Exceptions/API.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace Entase\Exceptions;
namespace Entase\SDK\Exceptions;

class API extends Base {}
2 changes: 1 addition & 1 deletion src/Entase/Exceptions/Base.php → src/Exceptions/Base.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entase\Exceptions;
namespace Entase\SDK\Exceptions;

class Base extends \Exception
{
Expand Down
2 changes: 1 addition & 1 deletion src/Entase/Exceptions/CURL.php → src/Exceptions/CURL.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace Entase\Exceptions;
namespace Entase\SDK\Exceptions;

class CURL extends Base {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

namespace Entase\Exceptions;
namespace Entase\SDK\Exceptions;

class Request extends Base {}
2 changes: 1 addition & 1 deletion src/Entase/ObjectBase.php → src/ObjectBase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entase;
namespace Entase\SDK;

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

namespace Entase;
namespace Entase\SDK;

use \IteratorAggregate;
use \Traversable;
Expand Down
2 changes: 1 addition & 1 deletion src/Entase/ObjectCursor.php → src/ObjectCursor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Entase;
namespace Entase\SDK;

class ObjectCursor extends ObjectBase
{
Expand Down
33 changes: 11 additions & 22 deletions src/autoloader.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,32 @@
<?php

namespace EntaseSDK;
namespace Entase\SDK;

function AutoLoader($className)
{
if (strpos($className, 'Entase\\') !== 0)
if (strpos($className, 'Entase\\SDK\\') !== 0)
return;

$calledClass = $className;
$className = str_replace('Entase\\SDK\\', '', $className);

$fileName = '';
$namespace = '';

// Sets the include path as the "src" directory
$includePath = dirname(__FILE__).DIRECTORY_SEPARATOR;

if (false !== ($lastNsPos = strripos($className, '\\'))) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}

$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$fullFileName = $includePath . DIRECTORY_SEPARATOR . $fileName;
$fullFileNameEX = $includePath . DIRECTORY_SEPARATOR .'ThirdParty/'.$fileName;

$pos = strpos($fileName, '/');
$fileName_src = ($pos !== false) ? substr_replace($fileName, '/src/', $pos, 1) : 'src/'.$fileName;
$fullFileNameEX_SRC = $includePath . DIRECTORY_SEPARATOR .'ThirdParty/'.$fileName_src;
$fullFilePath = $includePath.DIRECTORY_SEPARATOR.$fileName;

if (file_exists($fullFileName)) {
require_once $fullFileName;
}
elseif (file_exists($fullFileNameEX)) {
require_once $fullFileNameEX;
}
elseif (file_exists($fullFileNameEX_SRC)) {
require_once $fullFileNameEX_SRC;
}
else {
die('Class "'.$className.'" does not exist.');
if (file_exists($fullFilePath)) {
require_once $fullFilePath;
}
else die('Class "'.$calledClass.'" does not exist.');
}

\spl_autoload_register('EntaseSDK\AutoLoader'); // Registers the autoloader
\spl_autoload_register('Entase\\SDK\\AutoLoader'); // Registers the autoloader

0 comments on commit 2cb5ea3

Please sign in to comment.