change phpdoc api generator to phpdoc

This commit is contained in:
Manuel Raynaud
2013-08-08 13:26:49 +02:00
parent a70ea40c3e
commit df371355b9
3674 changed files with 3538567 additions and 1503017 deletions

View File

@@ -0,0 +1,57 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Choice;
class AdminLogin extends BaseForm {
protected function buildForm()
{
$this->formBuilder
->add("username", "text", array(
"constraints" => array(
new NotBlank(),
new Length(array("min" => 3))
)
))
->add("password", "password", array(
"constraints" => array(
new NotBlank()
)
))
->add("remember_me", "checkbox", array(
'value' => 'yes'
))
;
}
public function getName()
{
return "thelia_admin_login";
}
}

View File

@@ -0,0 +1,213 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
use Symfony\Component\Form\Forms;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension;
use Symfony\Component\Form\Extension\Csrf\CsrfExtension;
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
use Symfony\Component\Validator\Validation;
use Thelia\Model\ConfigQuery;
use Thelia\Tools\URL;
abstract class BaseForm {
/**
* @var \Symfony\Component\Form\FormFactoryInterface
*/
protected $formBuilder;
/**
* @var \Symfony\Component\Form\Form
*/
protected $form;
private $view = null;
/**
* true if the form has an error, false otherwise.
* @var boolean
*/
private $has_error = false;
/**
* The form error message.
* @var string
*/
private $error_message = '';
public function __construct(Request $request, $type= "form", $data = array(), $options = array())
{
$validator = Validation::createValidator();
if(!isset($options["attr"]["name"])) {
$options["attr"]["thelia_name"] = $this->getName();
}
$builder = Forms::createFormFactoryBuilder()
->addExtension(new HttpFoundationExtension());
if(!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
$builder->addExtension(
new CsrfExtension(
new SessionCsrfProvider(
$request->getSession(),
isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))
)
)
);
}
$this->formBuilder = $builder
->addExtension(new ValidatorExtension($validator))
->getFormFactory()
->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
;
$this->buildForm();
// If not already set, define the success_url field
if (! $this->formBuilder->has('success_url')) {
$this->formBuilder->add("success_url", "text");
}
$this->form = $this->formBuilder->getForm();
}
protected function cleanOptions($options)
{
unset($options["csrf_protection"]);
return $options;
}
/**
* Returns the absolute URL to redirect the user to if the form is successfully processed.
*
* @param string $default the default URL. If not given, the configured base URL is used.
*
* @return string an absolute URL
*/
public function getSuccessUrl($default = null) {
$successUrl = $this->form->get('success_url')->getData();
if (empty($successUrl)) {
if ($default === null) $default = ConfigQuery::read('base_url', '/');
$successUrl = $default;
}
return URL::absoluteUrl($successUrl);
}
public function createView() {
$this->view = $this->form->createView();
}
public function getView() {
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
return $this->view;
}
// -- Error and errro message ----------------------------------------------
/**
* Set the error status of the form.
*
* @param boolean $has_error
*/
public function setError($has_error = true)
{
$this->has_error = $has_error;
}
/**
* Get the cuirrent error status of the form.
*
* @return boolean
*/
public function hasError()
{
return $this->has_error;
}
/**
* Set the error message related to global form error
*
* @param unknown $message
*/
public function setErrorMessage($message)
{
$this->error_message = $message;
}
/**
* Get the form error message.
*
* @return string
*/
public function getErrorMessage()
{
return $this->error_message;
}
/**
* @return \Symfony\Component\Form\Form
*/
public function getForm()
{
return $this->form;
}
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
abstract protected function buildForm();
/**
* @return string the name of you form. This name must be unique
*/
abstract public function getName();
}

View File

@@ -0,0 +1,138 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Action\Exception\StockNotFoundException;
use Thelia\Action\Exception\ProductNotFoundException;
use Thelia\Model\ProductSaleElementsQuery;
use Thelia\Model\ConfigQuery;
use Thelia\Model\ProductQuery;
class CartAdd extends BaseForm
{
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->formBuilder attribute :
*
* $this->formBuilder->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new \Symfony\Component\Validator\Constraints\NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add("product", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
array($this, "checkProduct")
)))
)
))
->add("product_sale_elements_id", "text", array(
"constraints" => array(
new Constraints\Callback(array("methods" => array(
array($this, "checkStockAvailability")
)))
)
))
->add("quantity", "text", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(array("methods" => array(
array($this, "checkStock")
))),
new Constraints\GreaterThanOrEqual(array(
"value" => 0
))
)
))
->add("append", "hidden")
->add("newness", "hidden")
;
}
public function checkProduct($value, ExecutionContextInterface $context)
{
$product = ProductQuery::create()->findPk($value);
if (is_null($product) || $product->getVisible() == 0) {
throw new ProductNotFoundException(sprintf("this product id does not exists : %d", $value));
}
}
public function checkStockAvailability($value, ExecutionContextInterface $context)
{
if ($value) {
$data = $context->getRoot()->getData();
$productSaleElements = ProductSaleElementsQuery::create()
->filterById($value)
->filterByProductId($data["product"])
->count();
if ($productSaleElements == 0) {
throw new StockNotFoundException(sprintf("This product_sale_elements_id does not exists for this product : %d", $value));
}
}
}
public function checkStock($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
$productSaleElements = ProductSaleElementsQuery::create()
->filterById($data["product_sale_elements_id"])
->filterByProductId($data["product"])
->findOne();
if ($productSaleElements->getQuantity() < $value && ConfigQuery::read("verifyStock", 1) == 1) {
$context->addViolation("quantity value is not valid");
}
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_cart_add";
}
}

View File

@@ -0,0 +1,165 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Model\CustomerQuery;
class CustomerCreation extends BaseForm
{
protected function buildForm()
{
$this->formBuilder
->add("firstname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "firstname"
))
->add("lastname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "lastname"
))
->add("address1", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "address"
))
->add("address2", "text", array(
"label" => "Address Line 2"
))
->add("address3", "text", array(
"label" => "Address Line 3"
))
->add("phone", "text", array(
"label" => "phone"
))
->add("cellphone", "text", array(
"label" => "cellphone"
))
->add("zipcode", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "zipcode"
))
->add("city", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "city"
))
->add("country", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "country"
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "title"
))
->add("email", "email", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Email(),
new Constraints\Callback(array(
"methods" => array(
array($this,
"verifyExistingEmail")
)
))
),
"label" => "email"
))
->add("email_confirm", "email", array(
"constraints" => array(
new Constraints\Callback(array(
"methods" => array(
array($this,
"verifyEmailField")
)
))
),
"label" => "email confirmation"
))
->add("password", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4)))
),
"label" => "password"
))
->add("password_confirm", "password", array(
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Length(array("min" => ConfigQuery::read("password.length", 4))),
new Constraints\Callback(array("methods" => array(
array($this, "verifyPasswordField")
)))
),
"label" => "password confirmation"
))
;
}
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation("password confirmation is not the same as password field");
}
}
public function verifyEmailField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["email"] != $data["email_confirm"]) {
$context->addViolation("email confirmation is not the same as email field");
}
}
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::create()->findOneByEmail($value);
if ($customer) {
$context->addViolation("This email already exists");
}
}
public function getName()
{
return "thelia_customer_creation";
}
}

View File

@@ -0,0 +1,57 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Email;
class CustomerLogin extends BaseForm {
protected function buildForm()
{
$this->formBuilder
->add("email", "text", array(
"constraints" => array(
new NotBlank(),
new Email()
)
))
->add("password", "password", array(
"constraints" => array(
new NotBlank()
)
))
->add("remember_me", "checkbox")
;
}
public function getName()
{
return "thelia_customer_login";
}
}

View File

@@ -0,0 +1,120 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints;
use Thelia\Model\Customer;
class CustomerModification extends BaseForm {
/**
*
* in this function you add all the fields you need for your Form.
* Form this you have to call add method on $this->form attribute :
*
* $this->form->add("name", "text")
* ->add("email", "email", array(
* "attr" => array(
* "class" => "field"
* ),
* "label" => "email",
* "constraints" => array(
* new NotBlank()
* )
* )
* )
* ->add('age', 'integer');
*
* @return null
*/
protected function buildForm()
{
$this->formBuilder
->add("firstname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "firstname"
))
->add("lastname", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "lastname"
))
->add("address1", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "address"
))
->add("address2", "text", array(
"label" => "Address Line 2"
))
->add("address3", "text", array(
"label" => "Address Line 3"
))
->add("phone", "text", array(
"label" => "phone"
))
->add("cellphone", "text", array(
"label" => "cellphone"
))
->add("zipcode", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "zipcode"
))
->add("city", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "city"
))
->add("country", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "country"
))
->add("title", "text", array(
"constraints" => array(
new Constraints\NotBlank()
),
"label" => "title"
))
;
}
/**
* @return string the name of you form. This name must be unique
*/
public function getName()
{
return "thelia_customer_modification";
}
}