Skip to content

Commit

Permalink
#2 fix services, namespaces and use of c5 singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
1stthomas committed May 24, 2021
1 parent 6f90764 commit 7a84145
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 432 deletions.
13 changes: 0 additions & 13 deletions src/Concrete/Controllers/Environment.php

This file was deleted.

13 changes: 0 additions & 13 deletions src/Concrete/Controllers/Packages.php

This file was deleted.

141 changes: 0 additions & 141 deletions src/Concrete/Entity/ComposerPackage.php

This file was deleted.

46 changes: 0 additions & 46 deletions src/Concrete/Entity/ComposerPackageRequire.php

This file was deleted.

39 changes: 20 additions & 19 deletions src/Concrete/Entity/OrmEntityBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

namespace Concrete\Package\Ht7C5Base\Entity;

use \DateTime;
use \Concrete\Package\Ht7C5Base\Traits\CanPackageBasics;
use \Concrete\Core\Support\Facade\Application;
use \Doctrine\ORM\EntityManagerInterface;

/**
* @MappedSuperclass
*/
class OrmEntityBase
{

use CanPackageBasics;

/**
* The c5 application facade.
*
* @var \Concrete\Core\Support\Facade\Application
*/
protected static $app;

/**
* Create a new instance of the underlying entity.
*
Expand All @@ -30,10 +21,10 @@ class OrmEntityBase
public function __construct()
{
if (property_exists($this, 'createdAt')) {
$this->createdAt = new DateTime('now');
$this->createdAt = new \DateTime('now');
}
if (property_exists($this, 'updatedAt')) {
$this->updatedAt = new DateTime('now');
$this->updatedAt = new \DateTime('now');
}
}

Expand All @@ -53,14 +44,21 @@ public function __construct()
*/
public function delete($respectSettings = true)
{
if (property_exists(get_called_class(), 'safeDelete') && static::$safeDelete && property_exists($this, 'deletedAt') && $respectSettings) {
$this->deletedAt = new DateTime('now');
if (property_exists(get_called_class(), 'safeDelete') &&
static::$safeDelete &&
property_exists($this, 'deletedAt') &&
$respectSettings) {
$this->deletedAt = new \DateTime('now');

if (property_exists($this, 'updatedAt')) {
$this->updatedAt = new DateTime('now');
$this->updatedAt = new \DateTime('now');
}

$this->save();
} else {
$em = self::getEm();
$em = Application::getFacadeApplication()
->make(EntityManagerInterface::class);

$em->remove($this);
$em->flush();
}
Expand All @@ -75,9 +73,12 @@ public function delete($respectSettings = true)
public function save()
{
if (property_exists($this, 'updatedAt')) {
$this->updatedAt = new DateTime('now');
$this->updatedAt = new \DateTime('now');
}
$em = self::getEm();

$em = Application::getFacadeApplication()
->make(EntityManagerInterface::class);

$em->persist($this);
$em->flush();
}
Expand Down
15 changes: 6 additions & 9 deletions src/Concrete/Entity/OrmEntityExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace Concrete\Package\Ht7C5Base\Entity;

use \InvalidArgumentException;
use \Concrete\Core\Support\Facade\Application;
use \Concrete\Package\Ht7C5Base\Traits\CanLoad;
use \Doctrine\ORM\EntityManagerInterface;

/**
* @MappedSuperclass
Expand Down Expand Up @@ -55,10 +56,6 @@ public function __construct(array $data = [])
parent::__construct();

$this->load($data);

// if (!empty($data)) {
// $this->load($data);
// }
}

/**
Expand Down Expand Up @@ -137,7 +134,8 @@ public static function isActiveSafeDelete()
*/
public static function getByID($id, $respectSafeDeleteProperty = true)
{
$em = self::getEm();
$em = Application::getFacadeApplication()
->make(EntityManagerInterface::class);

if ($respectSafeDeleteProperty && static::$safeDelete) {
return $em->getRepository(static::class)
Expand Down Expand Up @@ -170,14 +168,13 @@ public static function getOrFailByID($id, $respectSafeDeleteProperty = true)
$classNs = static::class;
$className = substr($classNs, strrpos($classNs, '\\') + 1);
$entityName = strpos($className, 'MeschCm') !== false ? str_replace('MeschCm', '', $className) : $className;
// Create the exception message

$msg = tc(
'ht7_c5_base',
'The requested %1$s with the id %2$s could not be found.',
$entityName, $id
);
throw new InvalidArgumentException($msg);
// throw new MeschPageNotFoundException($msg);
throw new \InvalidArgumentException($msg);
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/Concrete/Repository/ComposerPackageRequireRepository.php

This file was deleted.

18 changes: 10 additions & 8 deletions src/Concrete/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Concrete\Package\Ht7C5Base;

use \Concrete\Core\Foundation\Service\Provider as CoreServiceProvider;
use \Concrete\Package\Ht7C5Base\Service\Files\NameFixer;
use \Concrete\Package\Ht7C5Base\Service\Users\User;
use \Concrete\Package\Ht7C5Base\Services\FileNameFixer;
use \Concrete\Package\Ht7C5Base\Services\PackageBase;
use \Concrete\Package\Ht7C5Base\Services\UserBase;

class ServiceProvider extends CoreServiceProvider
{
Expand All @@ -13,15 +14,16 @@ public function register()
{
$this->app->bind(
'helper/ht7/file/namefixer',
NameFixer::class
FileNameFixer::class
);
$this->app->bind(
'helper/ht7/users/user',
User::class
'helper/ht7/package/base',
PackageBase::class
);
$this->app->bind(
'helper/ht7/user/base',
UserBase::class
);

// Add these classes as singleton to have only one active instance of them.
// $this->app->singleton(LogEvents::class);
}

}
Loading

0 comments on commit 7a84145

Please sign in to comment.