diff --git a/Controller/PanelController.php b/Controller/PanelController.php index 45e6b2c..b1c239b 100644 --- a/Controller/PanelController.php +++ b/Controller/PanelController.php @@ -10,10 +10,9 @@ namespace Propel\PropelBundle\Controller; +use Symfony\Bridge\Propel1\DataCollector\PropelDataCollector; use Symfony\Component\DependencyInjection\ContainerAware; -use Propel\PropelBundle\DataCollector\PropelDataCollector; - /** * PanelController is designed to display information in the Propel Panel. * diff --git a/DataCollector/PropelDataCollector.php b/DataCollector/PropelDataCollector.php deleted file mode 100644 index cb2e194..0000000 --- a/DataCollector/PropelDataCollector.php +++ /dev/null @@ -1,127 +0,0 @@ - - */ -class PropelDataCollector extends DataCollector -{ - /** - * Propel logger - * - * @var Propel\PropelBundle\Logger\PropelLogger - */ - private $logger; - /** - * Propel configuration - * - * @var \PropelConfiguration - */ - protected $propelConfiguration; - - /** - * Constructor - * - * @param \Propel\PropelBundle\Logger\PropelLogger $logger A PropelLogger - */ - public function __construct(\Propel\PropelBundle\Logger\PropelLogger $logger, \PropelConfiguration $propelConfiguration) - { - $this->logger = $logger; - $this->propelConfiguration = $propelConfiguration; - } - - /** - * {@inheritdoc} - * - */ - public function collect(Request $request, Response $response, \Exception $exception = null) - { - $this->data = array( - 'queries' => $this->buildQueries(), - 'querycount' => $this->countQueries(), - ); - } - - /** - * Returns the collector name. - * - * @return string The collector name. - */ - public function getName() - { - return 'propel'; - } - - /** - * Creates an array of Build objects. - * - * @return array An array of Build objects - */ - private function buildQueries() - { - $queries = array(); - - $outerGlue = $this->propelConfiguration->getParameter('debugpdo.logging.outerglue', ' | '); - $innerGlue = $this->propelConfiguration->getParameter('debugpdo.logging.innerglue', ': '); - - foreach($this->logger->getQueries() as $q) - { - $parts = explode($outerGlue, $q); - - $times = explode($innerGlue, $parts[0]); - $memories = explode($innerGlue, $parts[1]); - - $sql = trim($parts[2]); - $time = trim($times[1]); - $memory = trim($memories[1]); - - $queries[] = new Query($sql, $time, $memory); - } - - return $queries; - } - - /** - * Count queries. - * @return int The number of queries. - */ - private function countQueries() - { - return count($this->logger->getQueries()); - } - - /** - * Returns queries. - * - * @return array Queries - */ - public function getQueries() - { - return $this->data['queries']; - } - - /** - * Returns the query count. - * - * @return integer The query count - */ - public function getQueryCount() - { - return $this->data['querycount']; - } -} diff --git a/DataCollector/Query.php b/DataCollector/Query.php deleted file mode 100644 index 78d40e9..0000000 --- a/DataCollector/Query.php +++ /dev/null @@ -1,81 +0,0 @@ - - */ -class Query -{ - /** - * SQL statement - * @var string - */ - private $sql; - /** - * Execution time - * - * @var string - */ - private $time; - /** - * Memory - * - * @var string - */ - private $memory; - - /** - * Default constructor - * - * @param $sql A SQL statement - * @param $time An execution time - * @param $memory Memory used - */ - public function __construct($sql, $time, $memory) - { - $this->sql = $sql; - $this->time = $time; - $this->memory = $memory; - } - - /** - * Getter - * - * @return string SQL statement - */ - public function getSql() - { - return $this->sql; - } - - /** - * Getter - * - * @return string Execution time - */ - public function getTime() - { - return $this->time; - } - - /** - * Getter - * - * @return string Memory - */ - public function getMemory() - { - return $this->memory; - } -} diff --git a/Form/ChoiceList/ModelChoiceList.php b/Form/ChoiceList/ModelChoiceList.php deleted file mode 100644 index 27df60c..0000000 --- a/Form/ChoiceList/ModelChoiceList.php +++ /dev/null @@ -1,221 +0,0 @@ - - */ -class ModelChoiceList extends ArrayChoiceList -{ - /** - * The models from which the user can choose - * - * This array is either indexed by ID (if the ID is a single field) - * or by key in the choices array (if the ID consists of multiple fields) - * - * This property is initialized by initializeChoices(). It should only - * be accessed through getModel() and getModels(). - * - * @var Collection - */ - private $models = array(); - /** - * The fields of which the identifier of the underlying class consists - * - * This property should only be accessed through identifier. - * - * @var array - */ - private $identifier = array(); - /** - * TableMap - * - * @var \TableMap - */ - private $table = null; - /** - * Property path - * - * @var \Symfony\Component\Form\Util\PropertyPath - */ - private $propertyPath = null; - /** - * Query - */ - private $query = null; - - /** - * @param string $class - * @param string $property - * @param array $choices - * @param \ModelCriteria $queryObject - */ - public function __construct($class, $property = null, $choices = array(), $queryObject = null) - { - $this->class = $class; - - $queryClass = $this->class . 'Query'; - $query = new $queryClass(); - - $this->table = $query->getTableMap(); - $this->identifier = $this->table->getPrimaryKeys(); - $this->query = $queryObject ?: $query; - - // The property option defines, which property (path) is used for - // displaying models as strings - if ($property) { - $this->propertyPath = new PropertyPath($property); - } - - parent::__construct($choices); - } - - /** - * Initializes the choices and returns them - * - * The choices are generated from the models. If the models have a - * composite identifier, the choices are indexed using ascending integers. - * Otherwise the identifiers are used as indices. - * - * If the models were passed in the "choices" option, this method - * does not have any significant overhead. Otherwise, if a query object - * was passed in the "query" option, this query is now used and executed. - * In the last case, all models for the underlying class are fetched. - * - * If the option "property" was passed, the property path in that option - * is used as option values. Otherwise this method tries to convert - * objects to strings using __toString(). - * - * @return array An array of choices - */ - protected function load() - { - parent::load(); - - if ($this->choices) { - $models = $this->choices; - } else { - $models = $this->query->find(); - } - - $this->choices = array(); - $this->models = array(); - - foreach ($models as $key => $model) { - if ($this->propertyPath) { - // If the property option was given, use it - $value = $this->propertyPath->getValue($model); - } else { - // Otherwise expect a __toString() method in the model - $value = (string)$model; - } - - if (count($this->identifier) > 1) { - // When the identifier consists of multiple field, use - // naturally ordered keys to refer to the choices - $this->choices[$key] = $value; - $this->models[$key] = $model; - } else { - // When the identifier is a single field, index choices by - // model ID for performance reasons - $id = current($this->getIdentifierValues($model)); - $this->choices[$id] = $value; - $this->models[$id] = $model; - } - } - } - - public function getIdentifier() - { - return $this->identifier; - } - - /** - * Returns the according models for the choices - * - * If the choices were not initialized, they are initialized now. This - * is an expensive operation, except if the models were passed in the - * "choices" option. - * - * @return array An array of models - */ - public function getModels() - { - if (!$this->loaded) { - $this->load(); - } - - return $this->models; - } - - /** - * Returns the model for the given key - * - * If the underlying models have composite identifiers, the choices - * are intialized. The key is expected to be the index in the choices - * array in this case. - * - * If they have single identifiers, they are either fetched from the - * internal model cache (if filled) or loaded from the database. - * - * @param string $key The choice key (for models with composite - * identifiers) or model ID (for models with single - * identifiers) - * @return object The matching model - */ - public function getModel($key) - { - if (!$this->loaded) { - $this->load(); - } - - try { - if (count($this->identifier) > 1) { - // $key is a collection index - $models = $this->getModels(); - return isset($models[$key]) ? $models[$key] : null; - } else if ($this->models) { - return isset($this->models[$key]) ? $this->models[$key] : null; - } - - $queryClass = $this->class . 'Query'; - return $queryClass::create()->findPk($key); - } catch (NoResultException $e) { - return null; - } - } - - /** - * Returns the values of the identifier fields of an model - * - * Propel must know about this model, that is, the model must already - * be persisted or added to the idmodel map before. Otherwise an - * exception is thrown. - * - * @param object $model The model for which to get the identifier - * @throws FormException If the model does not exist - */ - public function getIdentifierValues($model) - { - if ($model instanceof \BaseObject) { - return array($model->getPrimaryKey()); - } - - return $model->getPrimaryKeys(); - } -} diff --git a/Form/DataTransformer/ModelToIdTransformer.php b/Form/DataTransformer/ModelToIdTransformer.php deleted file mode 100644 index d4fb0a2..0000000 --- a/Form/DataTransformer/ModelToIdTransformer.php +++ /dev/null @@ -1,72 +0,0 @@ - - */ -class ModelToIdTransformer implements DataTransformerInterface -{ - /** - * @var \Propel\PropelBundle\Form\ChoiceList\ModelChoiceList - */ - private $choiceList; - - /** - * @param \Propel\PropelBundle\Form\ChoiceList\ModelChoiceList $choiceList - */ - public function __construct(ModelChoiceList $choiceList) - { - $this->choiceList = $choiceList; - } - - public function transform($model) - { - if (null === $model || '' === $model) { - return ''; - } - - if (!is_object($model)) { - throw new UnexpectedTypeException($model, 'object'); - } - - if (count($this->choiceList->getIdentifier()) > 1) { - $availableModels = $this->choiceList->getModels(); - - return array_search($model, $availableModels); - } - - return current($this->choiceList->getIdentifierValues($model)); - } - - public function reverseTransform($key) - { - if ('' === $key || null === $key) { - return null; - } - - if (count($this->choiceList->getIdentifier()) > 1 && !is_numeric($key)) { - throw new UnexpectedTypeException($key, 'numeric'); - } - - if (!($model = $this->choiceList->getModel($key))) { - throw new TransformationFailedException(sprintf('The model with key "%s" could not be found', $key)); - } - - return $model; - } -} diff --git a/Form/DataTransformer/ModelsToArrayTransformer.php b/Form/DataTransformer/ModelsToArrayTransformer.php deleted file mode 100644 index c72539c..0000000 --- a/Form/DataTransformer/ModelsToArrayTransformer.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @author Pierre-Yves Lebecq - */ -class ModelsToArrayTransformer implements DataTransformerInterface -{ - /** - * @var \Propel\PropelBundle\Form\ChoiceList\ModelChoiceList - */ - private $choiceList; - - /** - * @param \Propel\PropelBundle\Form\ChoiceList\ModelChoiceList $choiceList - */ - public function __construct(ModelChoiceList $choiceList) - { - $this->choiceList = $choiceList; - } - - public function transform($collection) - { - if (null === $collection) { - return array(); - } - - if (!$collection instanceof PropelCollection) { - throw new UnexpectedTypeException($collection, '\PropelCollection'); - } - - $array = array(); - - if (count($this->choiceList->getIdentifier()) > 1) { - $availableModels = $this->choiceList->getModels(); - - foreach ($collection as $model) { - $key = array_search($model, $availableModels); - $array[] = $key; - } - } else { - foreach ($collection as $model) { - $array[] = current($this->choiceList->getIdentifierValues($model)); - } - } - - return $array; - } - - public function reverseTransform($keys) - { - $collection = new PropelObjectCollection(); - - if ('' === $keys || null === $keys) { - return $collection; - } - - if (!is_array($keys)) { - throw new UnexpectedTypeException($keys, 'array'); - } - - $notFound = array(); - - foreach ($keys as $key) { - if ($model = $this->choiceList->getModel($key)) { - $collection->append($model); - } else { - $notFound[] = $key; - } - } - - if (count($notFound) > 0) { - throw new TransformationFailedException(sprintf('The models with keys "%s" could not be found', implode('", "', $notFound))); - } - - return $collection; - } -} diff --git a/Form/PropelTypeGuesser.php b/Form/PropelTypeGuesser.php deleted file mode 100644 index 880ead8..0000000 --- a/Form/PropelTypeGuesser.php +++ /dev/null @@ -1,146 +0,0 @@ - - */ -class PropelTypeGuesser implements FormTypeGuesserInterface -{ - private $cache = array(); - - /** - * {@inheritDoc} - */ - public function guessType($class, $property) - { - if (!$table = $this->getTable($class)) { - return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); - } - - foreach ($table->getRelations() as $relation) { - if (in_array($relation->getType(), array(\RelationMap::MANY_TO_ONE, \RelationMap::ONE_TO_MANY))) { - if ($property == $relation->getForeignTable()->getName()) { - return new TypeGuess('model', array( - 'class' => $relation->getForeignTable()->getClassName(), - 'multiple' => \RelationMap::MANY_TO_ONE === $relation->getType() ? false : true, - ), Guess::HIGH_CONFIDENCE); - } - } elseif ($relation->getType() === \RelationMap::MANY_TO_MANY) { - if (strtolower($property) == strtolower($relation->getPluralName())) { - return new TypeGuess('model', array( - 'class' => $relation->getLocalTable()->getClassName(), - 'multiple' => true, - ), Guess::HIGH_CONFIDENCE); - } - } - } - - if (!$column = $this->getColumn($class, $property)) { - return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); - } - - switch ($column->getType()) { - case \PropelColumnTypes::BOOLEAN: - case \PropelColumnTypes::BOOLEAN_EMU: - return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE); - case \PropelColumnTypes::TIMESTAMP: - case \PropelColumnTypes::BU_TIMESTAMP: - return new TypeGuess('datetime', array(), Guess::HIGH_CONFIDENCE); - case \PropelColumnTypes::DATE: - case \PropelColumnTypes::BU_DATE: - return new TypeGuess('date', array(), Guess::HIGH_CONFIDENCE); - case \PropelColumnTypes::TIME: - return new TypeGuess('time', array(), Guess::HIGH_CONFIDENCE); - case \PropelColumnTypes::FLOAT: - case \PropelColumnTypes::REAL: - case \PropelColumnTypes::DOUBLE: - case \PropelColumnTypes::DECIMAL: - return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE); - case \PropelColumnTypes::TINYINT: - case \PropelColumnTypes::SMALLINT: - case \PropelColumnTypes::INTEGER: - case \PropelColumnTypes::BIGINT: - case \PropelColumnTypes::NUMERIC: - return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE); - case \PropelColumnTypes::CHAR: - case \PropelColumnTypes::VARCHAR: - return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE); - case \PropelColumnTypes::LONGVARCHAR: - case \PropelColumnTypes::BLOB: - case \PropelColumnTypes::CLOB: - case \PropelColumnTypes::CLOB_EMU: - return new TypeGuess('textarea', array(), Guess::MEDIUM_CONFIDENCE); - default: - return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE); - } - } - - /** - * {@inheritDoc} - */ - public function guessRequired($class, $property) - { - if ($column = $this->getColumn($class, $property)) { - return new ValueGuess($column->isNotNull(), Guess::HIGH_CONFIDENCE); - } - } - - /** - * {@inheritDoc} - */ - public function guessMaxLength($class, $property) - { - if (($column = $this->getColumn($class, $property)) && $column->isText()) { - return new ValueGuess($column->getSize(), Guess::HIGH_CONFIDENCE); - } - } - - /** - * {@inheritDoc} - */ - public function guessMinLength($class, $property) - { - } - - protected function getTable($class) - { - if (isset($this->cache[$class])) { - return $this->cache[$class]; - } - - if (class_exists($queryClass = $class.'Query')) { - $query = new $queryClass(); - - return $this->cache[$class] = $query->getTableMap(); - } - } - - protected function getColumn($class, $property) - { - if (isset($this->cache[$class.'::'.$property])) { - return $this->cache[$class.'::'.$property]; - } - - $table = $this->getTable($class); - - if ($table && $table->hasColumn($property)) { - return $this->cache[$class.'::'.$property] = $table->getColumn($property); - } - } -} diff --git a/Form/Type/ModelType.php b/Form/Type/ModelType.php deleted file mode 100644 index 64713e3..0000000 --- a/Form/Type/ModelType.php +++ /dev/null @@ -1,74 +0,0 @@ - - */ -class ModelType extends AbstractType -{ - public function buildForm(FormBuilder $builder, array $options) - { - if ($options['multiple']) { - $builder->prependClientTransformer(new ModelsToArrayTransformer($options['choice_list'])); - } else { - $builder->prependClientTransformer(new ModelToIdTransformer($options['choice_list'])); - } - } - - public function getDefaultOptions(array $options) - { - $defaultOptions = array( - 'template' => 'choice', - 'multiple' => false, - 'expanded' => false, - 'class' => null, - 'property' => null, - 'query' => null, - 'choices' => array(), - 'preferred_choices' => array(), - ); - - $options = array_replace($defaultOptions, $options); - - if (!isset($options['choice_list'])) { - $defaultOptions['choice_list'] = new ModelChoiceList( - $options['class'], - $options['property'], - $options['choices'], - $options['query'] - ); - } - - return $defaultOptions; - } - - public function getParent(array $options) - { - return 'choice'; - } - - public function getName() - { - return 'model'; - } -} \ No newline at end of file diff --git a/Logger/PropelLogger.php b/Logger/PropelLogger.php deleted file mode 100644 index f762bdd..0000000 --- a/Logger/PropelLogger.php +++ /dev/null @@ -1,137 +0,0 @@ - - * @author William DURAND - */ -class PropelLogger -{ - /** - * @var LoggerInterface - */ - protected $logger; - /** - * @var array - */ - protected $queries; - - /** - * Constructor. - * - * @param LoggerInterface $logger A LoggerInterface instance - */ - public function __construct(LoggerInterface $logger = null) - { - $this->logger = $logger; - $this->queries = array(); - } - - /** - * A convenience function for logging an alert event. - * - * @param mixed $message the message to log. - */ - public function alert($message) - { - if (null !== $this->logger) { - $this->logger->alert($message); - } - } - - /** - * A convenience function for logging a critical event. - * - * @param mixed $message the message to log. - */ - public function crit($message) - { - if (null !== $this->logger) { - $this->logger->crit($message); - } - } - - /** - * A convenience function for logging an error event. - * - * @param mixed $message the message to log. - */ - public function err($message) - { - if (null !== $this->logger) { - $this->logger->err($message); - } - } - - /** - * A convenience function for logging a warning event. - * - * @param mixed $message the message to log. - */ - public function warning($message) - { - if (null !== $this->logger) { - $this->logger->warn($message); - } - } - - /** - * A convenience function for logging an critical event. - * - * @param mixed $message the message to log. - */ - public function notice($message) - { - if (null !== $this->logger) { - $this->logger->notice($message); - } - } - - /** - * A convenience function for logging an critical event. - * - * @param mixed $message the message to log. - */ - public function info($message) - { - if (null !== $this->logger) { - $this->logger->info($message); - } - } - - /** - * A convenience function for logging a debug event. - * - * @param mixed $message the message to log. - */ - public function debug($message) - { - $this->queries[] = $message; - if (null !== $this->logger) { - $this->logger->debug($message); - } - } - - /** - * Returns queries. - * - * @return array Queries - */ - public function getQueries() - { - return $this->queries; - } -} diff --git a/Resources/config/propel.xml b/Resources/config/propel.xml index 0d24ce5..56e1f11 100644 --- a/Resources/config/propel.xml +++ b/Resources/config/propel.xml @@ -7,12 +7,12 @@ default PropelConfiguration - Propel\PropelBundle\Logger\PropelLogger - Propel\PropelBundle\DataCollector\PropelDataCollector + Symfony\Bridge\Propel1\Logger\PropelLogger + Symfony\Bridge\Propel1\DataCollector\PropelDataCollector Propel\PropelBundle\DependencyInjection\Properties - Propel\PropelBundle\Form\Type\ModelType + Symfony\Bridge\Propel1\Form\Type\ModelType Propel\PropelBundle\Twig\Extension\SyntaxExtension - Propel\PropelBundle\Form\PropelTypeGuesser + Symfony\Bridge\Propel1\Form\PropelTypeGuesser