-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ServiceProxyFactory implemented but still failing
- Loading branch information
Showing
6 changed files
with
444 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor | ||
composer.lock | ||
.idea | ||
cache |
322 changes: 322 additions & 0 deletions
322
s HeavyObject extends PHPPeruHeavyObject implements PHPPeru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,322 @@ | ||
[1mdiff --git a/src/PHPPeru/ClassMetadataInterface.php b/src/PHPPeru/ClassMetadataInterface.php[m | ||
[1mdeleted file mode 100644[m | ||
[1mindex 56bdbe8..0000000[m | ||
[1m--- a/src/PHPPeru/ClassMetadataInterface.php[m | ||
[1m+++ /dev/null[m | ||
[36m@@ -1,33 +0,0 @@[m | ||
[31m-<?php[m | ||
[31m-[m | ||
[31m-namespace PHPPeru;[m | ||
[31m-[m | ||
[31m-/**[m | ||
[31m- * Contract for a Service layer ClassMetadata class to implement.[m | ||
[31m- *[m | ||
[31m- * @author Luis Cordova Sosa <cordoval@gmail.com>[m | ||
[31m- * @author Fernando Paredes Garcia <fernando@develcuy.com>[m | ||
[31m- */[m | ||
[31m-interface ClassMetadataInterface[m | ||
[31m-{[m | ||
[31m- /**[m | ||
[31m- * Get fully-qualified class name of this service class.[m | ||
[31m- *[m | ||
[31m- * @return string[m | ||
[31m- */[m | ||
[31m- function getName();[m | ||
[31m-[m | ||
[31m- /**[m | ||
[31m- * Gets the service identifier.[m | ||
[31m- *[m | ||
[31m- * @return string[m | ||
[31m- */[m | ||
[31m- function getIdentifier();[m | ||
[31m-[m | ||
[31m- /**[m | ||
[31m- * Gets the ReflectionClass instance for this service class.[m | ||
[31m- *[m | ||
[31m- * @return \ReflectionClass[m | ||
[31m- */[m | ||
[31m- function getReflectionClass();[m | ||
[31m-}[m | ||
[1mdiff --git a/src/PHPPeru/Examples.php b/src/PHPPeru/Examples.php[m | ||
[1mindex d7559f9..73be71e 100644[m | ||
[1m--- a/src/PHPPeru/Examples.php[m | ||
[1m+++ b/src/PHPPeru/Examples.php[m | ||
[36m@@ -78,17 +78,12 @@[m [mclass Examples[m | ||
$this->c['cache_dir'] = __DIR__.'/../../cache';[m | ||
$this->c['phpperu_namespace'] = 'PHPPeru';[m | ||
[m | ||
[31m- $this->c['proxy_generator'] = function($c) {[m | ||
[31m- return new ProxyGenerator($c['cache_dir'], $c['phpperu_namespace']);[m | ||
[32m+[m[32m $this->c['proxy_factory'] = function($c) {[m | ||
[32m+[m[32m return new ServiceProxyFactory($c['cache_dir'], $c['phpperu_namespace']);[m | ||
};[m | ||
[m | ||
$this->c['heavy_object_proxy'] = function($c) {[m | ||
[31m- $factory = new ServiceProxyFactory($c['cache_dir'], $c['phpperu_namespace']);[m | ||
[31m- $factory->setProxyGenerator($c['proxy_generator']);[m | ||
[31m-[m | ||
[31m- $heavyObjectProxy = $factory->getProxy('HeavyObject', 'heavy_object');[m | ||
[31m-[m | ||
[31m- return $heavyObjectProxy;[m | ||
[32m+[m[32m return $c['proxy_factory']->getProxy("PHPPeru\\HeavyObject", "heavy_object");[m | ||
};[m | ||
[m | ||
$this->c['ioc_controller'] = function ($c) {[m | ||
[1mdiff --git a/src/PHPPeru/ServiceClassMetadata.php b/src/PHPPeru/ServiceClassMetadata.php[m | ||
[1mindex fd65b3a..5f0226a 100644[m | ||
[1m--- a/src/PHPPeru/ServiceClassMetadata.php[m | ||
[1m+++ b/src/PHPPeru/ServiceClassMetadata.php[m | ||
[36m@@ -2,7 +2,9 @@[m | ||
[m | ||
namespace PHPPeru;[m | ||
[m | ||
[31m-class ServiceClassMetadata implements ClassMetadataInterface[m | ||
[32m+[m[32muse Doctrine\Common\Persistence\Mapping\ClassMetadata;[m | ||
[32m+[m | ||
[32m+[m[32mclass ServiceClassMetadata implements ClassMetadata[m | ||
{[m | ||
protected $className;[m | ||
protected $identifier;[m | ||
[36m@@ -18,7 +20,7 @@[m [mclass ServiceClassMetadata implements ClassMetadataInterface[m | ||
*/[m | ||
function getName()[m | ||
{[m | ||
[31m- return $this->serviceClassName;[m | ||
[32m+[m[32m return $this->className;[m | ||
}[m | ||
[m | ||
/**[m | ||
[36m@@ -36,4 +38,108 @@[m [mclass ServiceClassMetadata implements ClassMetadataInterface[m | ||
{[m | ||
return new \ReflectionClass($this->className);[m | ||
}[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function isIdentifier($fieldName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return false;[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function hasField($fieldName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return false;[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function hasAssociation($fieldName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return false;[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function isSingleValuedAssociation($fieldName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return false;[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function isCollectionValuedAssociation($fieldName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return false;[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function getFieldNames()[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return array();[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function getIdentifierFieldNames()[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return array();[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function getAssociationNames()[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return array();[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function getTypeOfField($fieldName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return 'type_of_field_dummy';[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function getAssociationTargetClass($assocName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return 'association_target_class_dummy';[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function isAssociationInverseSide($assocName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return false;[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function getAssociationMappedByTargetField($assocName)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return 'target_field_dummy';[m | ||
[32m+[m[32m }[m | ||
[32m+[m | ||
[32m+[m[32m /**[m | ||
[32m+[m[32m * {@inheritDoc}[m | ||
[32m+[m[32m */[m | ||
[32m+[m[32m function getIdentifierValues($object)[m | ||
[32m+[m[32m {[m | ||
[32m+[m[32m return array();[m | ||
[32m+[m[32m }[m | ||
}[m | ||
\ No newline at end of file[m | ||
[1mdiff --git a/src/PHPPeru/ServiceProxyFactory.php b/src/PHPPeru/ServiceProxyFactory.php[m | ||
[1mindex c14b546..05fcabe 100644[m | ||
[1m--- a/src/PHPPeru/ServiceProxyFactory.php[m | ||
[1m+++ b/src/PHPPeru/ServiceProxyFactory.php[m | ||
[36m@@ -37,8 +37,8 @@[m [mclass ServiceProxyFactory[m | ||
*/[m | ||
public function __construct($proxyDir, $proxyNamespace)[m | ||
{[m | ||
[31m- $this->proxyDir = $proxyDir;[m | ||
[31m- $this->proxyNs = $proxyNamespace;[m | ||
[32m+[m[32m $this->proxyDir = $proxyDir;[m | ||
[32m+[m[32m $this->proxyNamespace = $proxyNamespace;[m | ||
}[m | ||
[m | ||
/**[m | ||
[36m@@ -52,20 +52,18 @@[m [mclass ServiceProxyFactory[m | ||
*/[m | ||
public function getProxy($className, $identifier)[m | ||
{[m | ||
[31m- $fqn = ClassUtils::generateProxyClassName($className, $this->proxyNs);[m | ||
[32m+[m[32m $fqn = ClassUtils::generateProxyClassName($className, $this->proxyNamespace);[m | ||
[m | ||
if ( ! class_exists($fqn, false)) {[m | ||
$generator = $this->getProxyGenerator();[m | ||
$fileName = $generator->getProxyFileName($className);[m | ||
[31m- $classMetadata = new ServiceClassMetaData($className, $identifier);[m | ||
[32m+[m[32m $classMetadata = new ServiceClassMetadata($className, $identifier);[m | ||
$generator->generateProxyClass($classMetadata);[m | ||
[m | ||
require $fileName;[m | ||
}[m | ||
[m | ||
[31m- $entityPersister = $this->uow->getEntityPersister($className);[m | ||
[31m-[m | ||
[31m- $initializer = function (Proxy $proxy) use ($entityPersister, $identifier) {[m | ||
[32m+[m[32m $initializer = function (Proxy $proxy) {[m | ||
$proxy->__setInitializer(function () {});[m | ||
$proxy->__setCloner(function () {});[m | ||
[m | ||
[36m@@ -86,70 +84,23 @@[m [mclass ServiceProxyFactory[m | ||
if (method_exists($proxy, '__wakeup')) {[m | ||
$proxy->__wakeup();[m | ||
}[m | ||
[31m-[m | ||
[31m- if (null === $entityPersister->load($identifier, $proxy)) {[m | ||
[31m- throw new \Doctrine\ORM\EntityNotFoundException();[m | ||
[31m- }[m | ||
};[m | ||
[m | ||
[31m- $cloner = function (Proxy $proxy) use ($entityPersister, $identifier) {[m | ||
[32m+[m[32m $cloner = function (Proxy $proxy) {[m | ||
if ($proxy->__isInitialized()) {[m | ||
return;[m | ||
}[m | ||
[m | ||
$proxy->__setInitialized(true);[m | ||
[31m- $proxy->__setInitializer(function () {});[m | ||
[31m- $class = $entityPersister->getClassMetadata();[m | ||
[31m- $original = $entityPersister->load($identifier);[m | ||
[31m-[m | ||
[31m- if (null === $original) {[m | ||
[31m- throw new \Doctrine\ORM\EntityNotFoundException();[m | ||
[31m- }[m | ||
[32m+[m[32m $proxy->__setInitializer(function (){});[m | ||
[m | ||
[31m- foreach ($class->getReflectionClass()->getProperties() as $reflectionProperty) {[m | ||
[31m- $propertyName = $reflectionProperty->getName();[m | ||
[31m-[m | ||
[31m- if ($class->hasField($propertyName) || $class->hasAssociation($propertyName)) {[m | ||
[31m- $reflectionProperty->setAccessible(true);[m | ||
[31m- $reflectionProperty->setValue($proxy, $reflectionProperty->getValue($original));[m | ||
[31m- }[m | ||
[31m- }[m | ||
[32m+[m[32m return;[m | ||
};[m | ||
[m | ||
return new $fqn($initializer, $cloner, $identifier);[m | ||
}[m | ||
[m | ||
/**[m | ||
[31m- * Generates proxy classes for all given classes.[m | ||
[31m- *[m | ||
[31m- * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata[] $classes The classes (ClassMetadata instances)[m | ||
[31m- * for which to generate proxies.[m | ||
[31m- * @param string $proxyDir The target directory of the proxy classes. If not specified, the[m | ||
[31m- * directory configured on the Configuration of the EntityManager used[m | ||
[31m- * by this factory is used.[m | ||
[31m- * @return int Number of generated proxies.[m | ||
[31m- */[m | ||
[31m- public function generateProxyClasses(array $classes, $proxyDir = null)[m | ||
[31m- {[m | ||
[31m- $generated = 0;[m | ||
[31m-[m | ||
[31m- foreach ($classes as $class) {[m | ||
[31m- /* @var $class \Doctrine\ORM\Mapping\ClassMetadataInfo */[m | ||
[31m- if ($class->isMappedSuperclass || $class->getReflectionClass()->isAbstract()) {[m | ||
[31m- continue;[m | ||
[31m- }[m | ||
[31m-[m | ||
[31m- $generator = $this->getProxyGenerator();[m | ||
[31m-[m | ||
[31m- $proxyFileName = $generator->getProxyFileName($class->getName(), $proxyDir);[m | ||
[31m- $generator->generateProxyClass($class, $proxyFileName);[m | ||
[31m- $generated += 1;[m | ||
[31m- }[m | ||
[31m-[m | ||
[31m- return $generated;[m | ||
[31m- }[m | ||
[31m-[m | ||
[31m- /**[m | ||
* @param ProxyGenerator $proxyGenerator[m | ||
*/[m | ||
public function setProxyGenerator(ProxyGenerator $proxyGenerator)[m | ||
[36m@@ -163,8 +114,8 @@[m [mclass ServiceProxyFactory[m | ||
public function getProxyGenerator()[m | ||
{[m | ||
if (null === $this->proxyGenerator) {[m | ||
[31m- $this->proxyGenerator = new ProxyGenerator($this->proxyDir, $this->proxyNs);[m | ||
[31m- $this->proxyGenerator->setPlaceholder('<baseProxyInterface>', 'Doctrine\ORM\Proxy\Proxy');[m | ||
[32m+[m[32m $this->proxyGenerator = new ProxyGenerator($this->proxyDir, $this->proxyNamespace);[m | ||
[32m+[m[32m $this->proxyGenerator->setPlaceholder('<baseProxyInterface>', 'PHPPeru');[m | ||
}[m | ||
[m | ||
return $this->proxyGenerator;[m |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.