initial commit.

This commit is contained in:
Paweł Jędrzejewski 2011-09-09 16:12:24 +02:00
commit bb5650e703
31 changed files with 1839 additions and 0 deletions

View file

@ -0,0 +1,143 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Controller\Backend;
use Sylius\Bundle\AddressingBundle\EventDispatcher\Event\FilterAddressEvent;
use Sylius\Bundle\AddressingBundle\EventDispatcher\SyliusAddressingEvents;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Backend address controller.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class AddressController extends ContainerAware
{
/**
* Show all paginated addresses.
*/
public function listAction()
{
$addressManager = $this->container->get('sylius_addressing.manager.address');
$paginator = $addressManager->createPaginator();
$paginator->setCurrentPage($this->container->get('request')->query->get('page', 1), true, true);
$addresses = $paginator->getCurrentPageResults();
return $this->container->get('templating')->renderResponse('SyliusAddressingBundle:Backend/Address:list.html.twig', array(
'addresses' => $addresses,
'paginator' => $paginator
));
}
/**
* Shows one address.
*/
public function showAction($id)
{
$address = $this->container->get('sylius_addressing.manager.address')->findAddress($id);
if (!$address) {
throw new NotFoundHttpException('Requested address does not exist.');
}
return $this->container->get('templating')->renderResponse('SyliusAddressingBundle:Backend/Address:show.html.twig', array(
'address' => $address
));
}
/**
* Creating an address.
*/
public function createAction()
{
$address = $this->container->get('sylius_addressing.manager.address')->createAddress();
$form = $this->container->get('form.factory')->create($this->container->get('sylius_addressing.form.type.address'));
$form->setData($address);
$request = $this->container->get('request');
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
$this->container->get('event_dispatcher')->dispatch(SyliusAddressingEvents::ADDRESS_CREATE, new FilterAddressEvent($address));
$this->container->get('sylius_addressing.manipulator.address')->create($address);
return new RedirectResponse($this->container->get('router')->generate('sylius_addressing_backend_address_show', array(
'id' => $address->getId()
)));
}
}
return $this->container->get('templating')->renderResponse('SyliusAddressingBundle:Backend/Address:create.html.twig', array(
'form' => $form->createView()
));
}
/**
* Updating an address.
*/
public function updateAction($id)
{
$address = $this->container->get('sylius_addressing.manager.address')->findAddress($id);
if (!$address) {
throw new NotFoundHttpException('Requested address does not exist.');
}
$form = $this->container->get('form.factory')->create($this->container->get('sylius_addressing.form.type.address'));
$form->setData($address);
$request = $this->container->get('request');
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
if ($form->isValid()) {
$this->container->get('event_dispatcher')->dispatch(SyliusAddressingEvents::ADDRESS_UPDATE, new FilterAddressEvent($address));
$this->container->get('sylius_addressing.manipulator.address')->update($address);
return new RedirectResponse($this->container->get('router')->generate('sylius_addressing_backend_address_show', array(
'id' => $address->getId()
)));
}
}
return $this->container->get('templating')->renderResponse('SyliusAddressingBundle:Backend/Address:update.html.twig', array(
'form' => $form->createView(),
'address' => $address
));
}
/**
* Deletes address.
*/
public function deleteAction($id)
{
$address = $this->container->get('sylius_addressing.manager.address')->findAddress($id);
if (!$address) {
throw new NotFoundHttpException('Requested address does not exist.');
}
$this->container->get('sylius_addressing.manipulator.address')->delete($address);
return new RedirectResponse($this->container->get('router')->generate('sylius_addressing_backend_address_list'));
}
}

View file

@ -0,0 +1,97 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\DependencyInjection;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
/**
* This class contains the configuration information for the bundle.
*
* This information is solely responsible for how the different configuration
* sections are normalized, and merged.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class Configuration implements ConfigurationInterface
{
/**
* Generates the configuration tree.
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sylius_addressing');
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode('driver')->cannotBeOverwritten()->isRequired()->cannotBeEmpty()->end()
->scalarNode('engine')->defaultValue('twig')->end()
->end();
$this->addClassesSection($rootNode);
return $treeBuilder;
}
/**
* Adds `classes` section.
*/
private function addClassesSection(ArrayNodeDefinition $node)
{
$node
->children()
->arrayNode('classes')
->isRequired()
->addDefaultsIfNotSet()
->children()
->arrayNode('model')
->isRequired()
->children()
->scalarNode('address')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->arrayNode('controller')
->addDefaultsIfNotSet()
->children()
->arrayNode('backend')
->addDefaultsIfNotSet()
->children()
->scalarNode('address')->defaultValue('Sylius\\Bundle\\AddressingBundle\\Controller\\Backend\\AddressController')->end()
->end()
->end()
->end()
->end()
->arrayNode('manipulator')
->addDefaultsIfNotSet()
->children()
->scalarNode('address')->defaultValue('Sylius\\Bundle\\AddressingBundle\\Manipulator\\AddressManipulator')->end()
->end()
->end()
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->arrayNode('type')
->addDefaultsIfNotSet()
->children()
->scalarNode('address')->defaultValue('Sylius\Bundle\\AddressingBundle\\Form\\Type\\AddressFormType')->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end();
}
}

View file

@ -0,0 +1,112 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\DependencyInjection;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Processor;
/**
* Addressing system extension.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class SyliusAddressingExtension extends Extension
{
public function load(array $config, ContainerBuilder $container)
{
$processor = new Processor();
$configuration = new Configuration();
$config = $processor->processConfiguration($configuration, $config);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/container'));
if (!in_array($config['driver'], array('ORM'))) {
throw new \InvalidArgumentException(sprintf('Driver "%s" is unsupported for this extension.', $config['driver']));
}
if (!in_array($config['engine'], array('php', 'twig'))) {
throw new \InvalidArgumentException(sprintf('Engine "%s" is unsupported for this extension.', $config['engine']));
}
$loader->load(sprintf('driver/%s.xml', $config['driver']));
$loader->load(sprintf('engine/%s.xml', $config['engine']));
$container->setParameter('sylius_addressing.driver', $config['driver']);
$container->setParameter('sylius_addressing.engine', $config['engine']);
$configurations = array(
'controllers',
'manipulators',
'forms',
);
foreach($configurations as $basename) {
$loader->load(sprintf('%s.xml', $basename));
}
$this->remapParametersNamespaces($config['classes'], $container, array(
'model' => 'sylius_addressing.model.%s.class',
'manipulator' => 'sylius_addressing.manipulator.%s.class'
));
$this->remapParametersNamespaces($config['classes']['form'], $container, array(
'type' => 'sylius_addressing.form.type.%s.class',
));
$this->remapParametersNamespaces($config['classes']['controller'], $container, array(
'backend' => 'sylius_addressing.controller.backend.%s.class',
'frontend' => 'sylius_addressing.controller.frontend.%s.class'
));
}
/**
* Remap parameters.
*/
protected function remapParameters(array $config, ContainerBuilder $container, array $map)
{
foreach ($map as $name => $paramName) {
if (isset($config[$name])) {
$container->setParameter($paramName, $config[$name]);
}
}
}
/**
* Remap parameter namespaces.
*/
protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces)
{
foreach ($namespaces as $ns => $map) {
if ($ns) {
if (!isset($config[$ns])) {
continue;
}
$namespaceConfig = $config[$ns];
} else {
$namespaceConfig = $config;
}
if (is_array($map)) {
$this->remapParameters($namespaceConfig, $container, $map);
} else {
foreach ($namespaceConfig as $name => $value) {
if (null !== $value) {
$container->setParameter(sprintf($map, $name), $value);
}
}
}
}
}
}

View file

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Entity;
use Sylius\Bundle\AddressingBundle\Model\Address as BaseAddress;
/**
* Address entity.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class Address extends BaseAddress
{
}

View file

@ -0,0 +1,126 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Entity;
use Pagerfanta\Pagerfanta;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Sylius\Bundle\AddressingBundle\Model\AddressInterface;
use Sylius\Bundle\AddressingBundle\Model\AddressManager as BaseAddressManager;
/**
* Address entity manager.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class AddressManager extends BaseAddressManager
{
/**
* Entity manager.
*
* @var EntityManager
*/
protected $entityManager;
/**
* Address repository.
*
* @var EntityRepository
*/
protected $repository;
/**
* Constructor.
*
* @param EntityManager $entityManager
* @param string $class
*/
public function __construct(EntityManager $entityManager, $class)
{
parent::__construct($class);
$this->entityManager = $entityManager;
$this->repository = $entityManager->getRepository($class);
}
/**
* {@inheritdoc}
*/
public function createAddress()
{
$class = $this->getClass();
return new $class;
}
/**
* {@inheritdoc}
*/
public function persistAddress(AddressInterface $address)
{
$this->entityManager->persist($address);
$this->entityManager->flush();
}
/**
* {@inheritdoc}
*/
public function removeAddress(AddressInterface $address)
{
$this->entityManager->remove($address);
$this->entityManager->flush();
}
/**
* {@inheritdoc}
*/
public function findAddress($id)
{
return $this->repository->find($id);
}
/**
* {@inheritdoc}
*/
public function findAddressBy(array $criteria)
{
return $this->repository->findOneBy($criteria);
}
/**
* {@inheritdoc}
*/
public function findAddresses()
{
return $this->repository->findAll();
}
/**
* {@inheritdoc}
*/
public function findAddressesBy(array $criteria)
{
return $this->repository->findBy($criteria);
}
/**
* {@inheritdoc}
*/
public function createPaginator()
{
$queryBuilder = $this->entityManager->createQueryBuilder()
->select('a')
->from($this->class, 'a');
return new Pagerfanta(new DoctrineORMAdapter($queryBuilder->getQuery()));
}
}

View file

@ -0,0 +1,31 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\EventDispatcher\Event;
use Sylius\Bundle\AddressingBundle\Model\AddressInterface;
use Symfony\Component\EventDispatcher\Event;
class FilterAddressEvent extends Event
{
private $address;
public function __construct(AddressInterface $address)
{
$this->address = $address;
}
public function getAddress()
{
return $this->address;
}
}

View file

@ -0,0 +1,19 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\EventDispatcher;
final class SyliusAddressingEvents
{
const ADDRESS_CREATE = 'sylius_addressing.event.address.create';
const ADDRESS_UPDATE = 'sylius_addressing.event.address.update';
const ADDRESS_DELETE = 'sylius_addressing.event.address.delete';
}

View file

@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\AbstractType;
/**
* Address form type.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class AddressFormType extends AbstractType
{
/**
* Data class.
*
* @var string
*/
protected $dataClass;
/**
* Constructor.
*
* @param string $dataClass
*/
public function __construct($dataClass)
{
$this->dataClass = $dataClass;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('company', 'text', array('required' => false))
->add('name', 'text')
->add('surname', 'text')
->add('street', 'text')
->add('postcode', 'text')
->add('city', 'text')
;
}
/**
* {@inheritdoc}
*/
public function getDefaultOptions(array $options)
{
return array(
'data_class' => $this->dataClass
);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'sylius_addressing_address';
}
}

View file

@ -0,0 +1,66 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Manipulator;
use Sylius\Bundle\AddressingBundle\Model\AddressManagerInterface;
use Sylius\Bundle\AddressingBundle\Model\AddressInterface;
/**
* Address manipulator.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class AddressManipulator implements AddressManipulatorInterface
{
/**
* Address manager.
*
* @var AddressManagerInterface
*/
protected $addressManager;
/**
* Constructor.
*
* @param $addressManager AddressManagerInterface
*/
public function __construct(AddressManagerInterface $addressManager)
{
$this->addressManager = $addressManager;
}
/**
* {@inheritdoc}
*/
public function create(AddressInterface $address)
{
$address->incrementCreatedAt();
$this->addressManager->persistAddress($address);
}
/**
* {@inheritdoc}
*/
public function update(AddressInterface $address)
{
$address->incrementUpdatedAt();
$this->addressManager->persistAddress($address);
}
/**
* {@inheritdoc}
*/
public function delete(AddressInterface $address)
{
$this->addressManager->removeAddress($address);
}
}

View file

@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Manipulator;
use Sylius\Bundle\AddressingBundle\Model\AddressInterface;
/**
* Address manipulator interface.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
interface AddressManipulatorInterface
{
/**
* Creates a address.
*
* @param AddressInterface $address
*/
function create(AddressInterface $address);
/**
* Updates a address.
*
* @param AddressInterface $address
*/
function update(AddressInterface $address);
/**
* Deletes a address.
*
* @param AddressInterface $address
*/
function delete(AddressInterface $address);
}

View file

@ -0,0 +1,219 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Model;
/**
* Abstract model class for address.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
abstract class Address implements AddressInterface
{
/**
* Address id.
*
* @var integer
*/
protected $id;
/**
* Company name.
*
* @var string
*/
protected $company;
/**
* Name.
*
* @var string
*/
protected $name;
/**
* Surname.
*
* @var string
*/
protected $surname;
/**
* Street.
*
* @var string
*/
protected $street;
/**
* Postal code.
*
* @var string
*/
protected $postcode;
/**
* City name.
*
* @var string
*/
protected $city;
/**
* Creation time.
*
* @var \DateTime
*/
protected $createdAt;
/**
* Modification time.
*
* @var \DateTime
*/
protected $updatedAt;
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getCompany()
{
return $this->company;
}
/**
* {@inheritdoc}
*/
public function setCompany($company)
{
$this->company = $company;
}
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name)
{
$this->name = $name;
}
/**
* {@inheritdoc}
*/
public function getSurname()
{
return $this->surname;
}
/**
* {@inheritdoc}
*/
public function setSurname($surname)
{
$this->surname = $surname;
}
/**
* {@inheritdoc}
*/
public function getStreet()
{
return $this->street;
}
/**
* {@inheritdoc}
*/
public function setStreet($street)
{
$this->street = $street;
}
/**
* {@inheritdoc}
*/
public function getPostcode()
{
return $this->postcode;
}
/**
* {@inheritdoc}
*/
public function setPostcode($postcode)
{
$this->postcode = $postcode;
}
/**
* {@inheritdoc}
*/
public function getCity()
{
return $this->city;
}
/**
* {@inheritdoc}
*/
public function setCity($city)
{
$this->city = $city;
}
/**
* {@inheritdoc}
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* {@inheritdoc}
*/
public function incrementCreatedAt()
{
$this->createdAt = new \DateTime();
}
/**
* {@inheritdoc}
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* {@inheritdoc}
*/
public function incrementUpdatedAt()
{
$this->updatedAt = new \DateTime();
}
}

View file

@ -0,0 +1,139 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Model;
/**
* Address model interface.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
interface AddressInterface
{
/**
* Returns address id.
*
* @return integer
*/
function getId();
/**
* Returns company.
*
* @return string
*/
function getCompany();
/**
* Sets company.
*
* @param string $company
*/
function setCompany($company);
/**
* Returns first name.
*
* @return string
*/
function getName();
/**
* Sets first name.
*
* @param string $name
*/
function setName($name);
/**
* Returns last name.
*
* @return string
*/
function getSurname();
/**
* Sets last name.
*
* @param string $surname
*/
function setSurname($surname);
/**
* Returns street.
*
* @return string
*/
function getStreet();
/**
* Sets street.
*
* @param string $street
*/
function setStreet($street);
/**
* Returns postal code.
*
* @return string
*/
function getPostcode();
/**
* Sets postal code.
*
* @param string $postcode
*/
function setPostcode($postcode);
/**
* Returns city.
*
* @return string
*/
function getCity();
/**
* Sets city.
*
* @param string $city
*/
function setCity($city);
/**
* Get creation time.
*
* @return \DateTime
*/
function getCreatedAt();
/**
* Increments creation time.
*
* @return null
*/
function incrementCreatedAt();
/**
* Get modification time.
*
* @return \DateTime
*/
function getUpdatedAt();
/**
* Increments modification time.
*
* @return null
*/
function incrementUpdatedAt();
}

View file

@ -0,0 +1,53 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Model;
/**
* Address manager model.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
abstract class AddressManager implements AddressManagerInterface
{
/**
* Address model class.
*
* @var string
*/
protected $class;
/**
* Constructor.
*
* @param string $class The address model class
*/
public function __construct($class)
{
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function getClass()
{
return $this->class;
}
/**
* {@inheritdoc}
*/
public function setClass($class)
{
$this->class = $class;
}
}

View file

@ -0,0 +1,83 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle\Model;
/**
* Address manager interface.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
interface AddressManagerInterface
{
/**
* Creates address model.
*
* @return AddressInterface
*/
function createAddress();
/**
* Persists address model.
*
* @param AddressInterface $address
*/
function persistAddress(AddressInterface $address);
/**
* Removes address model.
*
* @param AddressInterface $address
*/
function removeAddress(AddressInterface $address);
/**
* Finds address by id.
*
* @param integer $id The address id
*/
function findAddress($id);
/**
* Finds address by criteria.
*
* @param array $criteria The criteria
*/
function findAddressBy(array $criteria);
/**
* Finds all adresses.
*
* @return array The adressess
*/
function findAddresses();
/**
* Finds addresses by criteria.
*
* @param array $criteria The criteria
*/
function findAddressesBy(array $criteria);
/**
* Returns address model class.
*
* @return string The address model class
*/
function getClass();
/**
* Sets the address model class.
*
* @param string $class The address model class
*/
function setClass($class);
}

View file

@ -0,0 +1,39 @@
About SyliusAddressingBundle...
=================================
This bundle is part of **Sylius e-commerce system**.
Addressing mechanisms for Symfony2 applications.
About project "Sylius".
-----------------------
Sylius is meant to be a e-commerce system build on Symfony2 and by its community.
The goal is to create a end-user application that will be developer friendly.
Most of parts are fully functional and are powering 2 online shops that run in production.
The work is focused on the bundles like PluginsBundle and ThemingBundle.
More bundles are one their way to github. Stay tuned.
**Please note!** I know that many of this bundles are far from being perfect.
I just want to share my work with others and also learn something new.
Documentation.
--------------
Docs are available [here](https://github.com/Sylius/AddressingBundle/blob/master/Resources/doc/index.md).
Dependencies.
-------------
This bundle uses the awesome [Pagerfanta library](https://github.com/whiteoctober/Pagerfanta) and [Pagerfanta bundle](https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle).
License.
--------
Licence can be found here...
Resources/meta/LICENSE
Authors.
--------
See the list of [contributors](https://github.com/Sylius/AddressingBundle/contributors).

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_addressing.controller.backend.address" class="%sylius_addressing.controller.backend.address.class%">
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
</service>
</services>
</container>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter key="sylius_addressing.manager.address.class">Sylius\Bundle\AddressingBundle\Entity\AddressManager</parameter>
</parameters>
<services>
<service id="sylius_addressing.manager.address" class="%sylius_addressing.manager.address.class%">
<argument type="service" id="doctrine.orm.default_entity_manager" />
<argument>%sylius_addressing.model.address.class%</argument>
</service>
</services>
</container>

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
</container>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_addressing.form.type.address" class="%sylius_addressing.form.type.address.class%">
<argument>%sylius_addressing.model.address.class%</argument>
<tag name="form.type" alias="sylius_addressing_address" />
</service>
</services>
</container>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius_addressing.manipulator.address" class="%sylius_addressing.manipulator.address.class%">
<argument type="service" id="sylius_addressing.manager.address" />
</service>
</services>
</container>

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Sylius\Bundle\AddressingBundle\Entity\Address" table="sylius_addressing_address">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
<field name="company" column="company" type="string" length="255" nullable="true" />
<field name="name" column="name" type="string" length="255" />
<field name="surname" column="surname" type="string" length="255" />
<field name="street" column="street" type="string" length="255" />
<field name="postcode" column="postcode" type="string" length="255" />
<field name="city" column="city" type="string" length="255" />
<field name="createdAt" column="created_at" type="datetime" />
<field name="updatedAt" column="updated_at" type="datetime" nullable="true" />
</entity>
</doctrine-mapping>

View file

@ -0,0 +1,19 @@
sylius_addressing_backend_address_create:
pattern: /address/create
defaults: { _controller: sylius_addressing.controller.backend.address:createAction }
sylius_addressing_backend_address_update:
pattern: /address/{id}/update
defaults: { _controller: sylius_addressing.controller.backend.address:updateAction }
sylius_addressing_backend_address_delete:
pattern: /address/{id}/delete
defaults: { _controller: sylius_addressing.controller.backend.address:deleteAction }
sylius_addressing_backend_address_show:
pattern: /address/{id}
defaults: { _controller: sylius_addressing.controller.backend.address:showAction }
sylius_addressing_backend_address_list:
pattern: /addresses
defaults: { _controller: sylius_addressing.controller.backend.address:listAction }

View file

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping
http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
<class name="Sylius\Bundle\AddressingBundle\Model\Address">
<property name="company">
<constraint name="MinLength">
<option name="limit">2</option>
<option name="message">The company name is too short</option>
</constraint>
<constraint name="MaxLength">
<option name="limit">255</option>
<option name="message">The company name is too long</option>
</constraint>
</property>
<property name="name">
<constraint name="NotBlank">
<option name="message">Please enter name</option>
</constraint>
<constraint name="MinLength">
<option name="limit">2</option>
<option name="message">The name is too short</option>
</constraint>
<constraint name="MaxLength">
<option name="limit">255</option>
<option name="message">The name is too long</option>
</constraint>
</property>
<property name="surname">
<constraint name="NotBlank">
<option name="message">Please enter surname</option>
</constraint>
<constraint name="MinLength">
<option name="limit">2</option>
<option name="message">The surname is too short</option>
</constraint>
<constraint name="MaxLength">
<option name="limit">255</option>
<option name="message">The surname is too long</option>
</constraint>
</property>
<property name="street">
<constraint name="NotBlank">
<option name="message">Please enter street</option>
</constraint>
<constraint name="MinLength">
<option name="limit">2</option>
<option name="message">The street is too short</option>
</constraint>
<constraint name="MaxLength">
<option name="limit">255</option>
<option name="message">The street is too long</option>
</constraint>
</property>
<property name="postcode">
<constraint name="NotBlank">
<option name="message">Please enter postcode</option>
</constraint>
</property>
<property name="city">
<constraint name="NotBlank">
<option name="message">Please enter city</option>
</constraint>
<constraint name="MinLength">
<option name="limit">2</option>
<option name="message">The city name is too short</option>
</constraint>
<constraint name="MaxLength">
<option name="limit">255</option>
<option name="message">The city name is too long</option>
</constraint>
</property>
</class>
</constraint-mapping>

View file

@ -0,0 +1,157 @@
SyliusAddressingBundle documentation.
=====================================
This bundle provides models and interfaces for managing addresses in Symfony2 applications.
**Note!** This documentation is inspired by [FOSUserBundle docs](https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md).
Installation.
-------------
+ Installing dependencies.
+ Downloading the bundle.
+ Autoloader configuration.
+ Adding bundle to kernel.
+ Creating your Address class.
+ DIC configuration.
+ Importing routing cfgs.
+ Updating database schema.
### Installing dependencies.
This bundle uses Pagerfanta library and PagerfantaBundle.
The installation guide can be found [here](https://github.com/whiteoctober/WhiteOctoberPagerfantaBundle).
### Downloading the bundle.
The good practice is to download the bundle to the `vendor/bundles/Sylius/Bundle/AddressingBundle` directory.
This can be done in several ways, depending on your preference. The first
method is the standard Symfony2 method.
**Using the vendors script.**
Add the following lines in your `deps` file...
```
[SyliusAddressingBundle]
git=git://github.com/Sylius/SyliusAddressingBundle.git
target=bundles/Sylius/Bundle/AddressingBundle
```
Now, run the vendors script to download the bundle.
``` bash
$ php bin/vendors install
```
**Using submodules.**
If you prefer instead to use git submodules, the run the following:
``` bash
$ git submodule add git://github.com/Sylius/SyliusAddressingBundle.git vendor/bundles/Sylius/Bundle/AssortmentBundle
$ git submodule update --init
```
### Autoloader configuration.
Add the `Sylius\Bundle` namespace to your autoloader.
``` php
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Sylius\\Bundle' => __DIR__.'/../vendor/bundles',
));
```
### Adding bundle to kernel.
Finally, enable the bundle in the kernel.
``` php
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Sylius\Bundle\AddressingBundle\SyliusAddressingBundle(),
);
}
```
### Creating your address class or using the standard one.
If you want to use the default address object skip this step.
Creating your own address class is pretty simple!
``` php
<?php
// src/Application/Bundle/AddressingBundle/Entity/Address.php
namespace Application\Bundle\AddressingBundle\Entity;
use Sylius\Bundle\AddressingBundle\Entity\Address as BaseAddress;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="sylius_addressing_address")
*/
class Address extends BaseAddress
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
```
### Container configuration.
Now you have to do the minimal configuration, no worries, it is not painful.
Open up your `config.yml` file and add this...
``` yaml
sylius_addressing:
driver: ORM
classes:
model:
address: Application\Bundle\AddressingBundle\Entity\Address
```
`Please note, that the "ORM" is currently the only supported driver.`
### Import routing files.
Now is the time to import routing files. Open up your `routing.yml` file. Customize the prefixes or whatever you want.
``` yaml
sylius_addressing_backend_address:
resource: "@SyliusAddressingBundle/Resources/config/routing/backend/address.yml"
prefix: /administration
```
### Updating database schema.
The last thing you need to do is updating the database schema.
For "ORM" driver run the following command.
``` bash
$ php app/console doctrine:schema:update --force
```
### Finish.
That is all, I hope it was not so bad.
Now you can visit `/administration/addresses` to see the list of addresses.
`This documentation is under construction.`

View file

@ -0,0 +1,19 @@
Copyright (c) 2011 Paweł Jędrzejewski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,15 @@
{% extends 'SyliusAddressingBundle:Backend:layout.html.twig' %}
{% block content %}
<h2>creating new address...</h2>
<form action="{{ path('sylius_addressing_backend_address_create') }}" method="post">
{{ form_widget(form) }}
<input type="submit" value="create address" />
</form>
{% endblock content %}

View file

@ -0,0 +1,27 @@
{% extends 'SyliusAddressingBundle:Backend:layout.html.twig' %}
{% block content %}
<h2>addresses list.</h2>
{% for address in addresses %}
id: {{ address.id }} <br />
name: {{ address.name }} <br />
surname: {{ address.surname }} <br />
city: {{ address.city }} <br />
postcode: {{ address.postcode }} <br />
street: {{ address.street }} <br />
<ul>
<li><a href="{{ path('sylius_addressing_backend_address_show', {'id': address.id}) }}">details</a></li>
<li><a href="{{ path('sylius_addressing_backend_address_update', {'id': address.id}) }}">edit</a></li>
<li><a href="{{ path('sylius_addressing_backend_address_delete', {'id': address.id}) }}">delete</a></li>
</ul>
{% endfor %}
<br /> <br />
{{ pagerfanta(paginator, 'default') }}
{% endblock %}

View file

@ -0,0 +1,19 @@
{% extends 'SyliusAddressingBundle:Backend:layout.html.twig' %}
{% block content %}
<h2>address details.</h2>
id: {{ address.id }} <br />
name: {{ address.name }} <br />
surname: {{ address.surname }} <br />
city: {{ address.city }} <br />
postcode: {{ address.postcode }} <br />
street: {{ address.street }} <br />
<ul>
<li><a href="{{ path('sylius_addressing_backend_address_update', {'id': address.id}) }}">edit</a></li>
<li><a href="{{ path('sylius_addressing_backend_address_delete', {'id': address.id}) }}">delete</a></li>
</ul>
{% endblock %}

View file

@ -0,0 +1,15 @@
{% extends 'SyliusAddressingBundle:Backend:layout.html.twig' %}
{% block content %}
<h2>updating address...</h2>
<form action="{{ path('sylius_addressing_backend_address_update', {'id': address.id}) }}" method="post">
{{ form_widget(form) }}
<input type="submit" value="update address" />
</form>
{% endblock content %}

View file

@ -0,0 +1,25 @@
<!doctype html>
<head>
<title> Sylius e-commerce platform administration. </title>
<meta charset="utf-8">
</head>
<body>
<h1>backend.</h1>
<ul>
<li><a href="{{ path('sylius_addressing_backend_address_list') }}">list addresses</a></li>
<li><a href="{{ path('sylius_addressing_backend_address_create') }}">create address</a></li>
</ul>
{% block content %}
{% endblock %}
</body>
</html>

View file

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\AddressingBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
/**
* Bundle of addressing.
*
* @author Paweł Jędrzejewski <pjedrzejewski@sylius.pl>
*/
class SyliusAddressingBundle extends Bundle
{
}