From 280551152c622fd3f6d2cecca749dc483b7198fb Mon Sep 17 00:00:00 2001 From: michalmarcinkowski Date: Tue, 23 Sep 2014 15:04:00 +0200 Subject: [PATCH] Initial Contact component. --- phpspec.yml | 1 + src/Sylius/Component/Contact/.gitignore | 5 + src/Sylius/Component/Contact/.travis.yml | 13 ++ src/Sylius/Component/Contact/CHANGELOG.md | 6 + src/Sylius/Component/Contact/LICENCE | 19 ++ .../Contact/Model/ContactRequest.php | 199 ++++++++++++++++++ .../Contact/Model/ContactRequestInterface.php | 72 +++++++ .../Component/Contact/Model/ContactTopic.php | 60 ++++++ .../Contact/Model/ContactTopicInterface.php | 32 +++ src/Sylius/Component/Contact/README.md | 47 +++++ src/Sylius/Component/Contact/composer.json | 48 +++++ .../Contact/Model/ContactRequestSpec.php | 118 +++++++++++ .../Contact/Model/ContactTopicSpec.php | 47 +++++ 13 files changed, 667 insertions(+) create mode 100644 src/Sylius/Component/Contact/.gitignore create mode 100644 src/Sylius/Component/Contact/.travis.yml create mode 100644 src/Sylius/Component/Contact/CHANGELOG.md create mode 100644 src/Sylius/Component/Contact/LICENCE create mode 100644 src/Sylius/Component/Contact/Model/ContactRequest.php create mode 100644 src/Sylius/Component/Contact/Model/ContactRequestInterface.php create mode 100644 src/Sylius/Component/Contact/Model/ContactTopic.php create mode 100644 src/Sylius/Component/Contact/Model/ContactTopicInterface.php create mode 100644 src/Sylius/Component/Contact/README.md create mode 100644 src/Sylius/Component/Contact/composer.json create mode 100644 src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactRequestSpec.php create mode 100644 src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactTopicSpec.php diff --git a/phpspec.yml b/phpspec.yml index aafcfd3f63..14d0e8e865 100644 --- a/phpspec.yml +++ b/phpspec.yml @@ -3,6 +3,7 @@ suites: Attribute : { namespace: Sylius, spec_path: src/Sylius/Component/Attribute } Cart : { namespace: Sylius, spec_path: src/Sylius/Component/Cart } Core : { namespace: Sylius, spec_path: src/Sylius/Component/Core } + Contact : { namespace: Sylius, spec_path: src/Sylius/Component/Contact } Currency : { namespace: Sylius, spec_path: src/Sylius/Component/Currency } Installer : { namespace: Sylius, spec_path: src/Sylius/Component/Installer } Inventory : { namespace: Sylius, spec_path: src/Sylius/Component/Inventory } diff --git a/src/Sylius/Component/Contact/.gitignore b/src/Sylius/Component/Contact/.gitignore new file mode 100644 index 0000000000..bf3c80625a --- /dev/null +++ b/src/Sylius/Component/Contact/.gitignore @@ -0,0 +1,5 @@ +vendor/ +bin/ + +composer.phar +composer.lock \ No newline at end of file diff --git a/src/Sylius/Component/Contact/.travis.yml b/src/Sylius/Component/Contact/.travis.yml new file mode 100644 index 0000000000..c0fefa372b --- /dev/null +++ b/src/Sylius/Component/Contact/.travis.yml @@ -0,0 +1,13 @@ +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + +before_script: composer install --dev --prefer-source + +script: bin/phpspec run -fpretty --verbose + +notifications: + irc: "irc.freenode.org#sylius-dev" diff --git a/src/Sylius/Component/Contact/CHANGELOG.md b/src/Sylius/Component/Contact/CHANGELOG.md new file mode 100644 index 0000000000..d8d625a53c --- /dev/null +++ b/src/Sylius/Component/Contact/CHANGELOG.md @@ -0,0 +1,6 @@ +CHANGELOG +========= + +### v0.12.0 + +* Initial dev release. diff --git a/src/Sylius/Component/Contact/LICENCE b/src/Sylius/Component/Contact/LICENCE new file mode 100644 index 0000000000..3f2217e164 --- /dev/null +++ b/src/Sylius/Component/Contact/LICENCE @@ -0,0 +1,19 @@ +Copyright (c) 2011-2014 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. diff --git a/src/Sylius/Component/Contact/Model/ContactRequest.php b/src/Sylius/Component/Contact/Model/ContactRequest.php new file mode 100644 index 0000000000..66e28d3249 --- /dev/null +++ b/src/Sylius/Component/Contact/Model/ContactRequest.php @@ -0,0 +1,199 @@ + + */ +class ContactRequest implements ContactRequestInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $firstName; + + /** + * @var string + */ + protected $lastName; + + /** + * @var string + */ + protected $email; + + /** + * @var string + */ + protected $message; + + /** + * @var ContactTopicInterface + */ + protected $topic; + + /** + * @var \DateTime + */ + protected $createdAt; + + /** + * @var \DateTime + */ + protected $updatedAt; + + /** + * Constructor + */ + public function __construct() + { + $this->createdAt = new \DateTime(); + } + + public function getId() + { + return $this->id; + } + + /** + * {@inheritdoc} + */ + public function setTopic($topic) + { + $this->topic = $topic; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getTopic() + { + return $this->topic; + } + + /** + * {@inheritdoc} + */ + public function setEmail($email) + { + $this->email = $email; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getEmail() + { + return $this->email; + } + + /** + * {@inheritdoc} + */ + public function setFirstName($firstName) + { + $this->firstName = $firstName; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getFirstName() + { + return $this->firstName; + } + + /** + * {@inheritdoc} + */ + public function setLastName($lastName) + { + $this->lastName = $lastName; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * {@inheritdoc} + */ + public function setMessage($message) + { + $this->message = $message; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getMessage() + { + return $this->message; + } + + /** + * {@inheritdoc} + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * {@inheritdoc} + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getUpdatedAt() + { + return $this->updatedAt; + } + + /** + * {@inheritdoc} + */ + public function setUpdatedAt(\DateTime $updatedAt) + { + $this->updatedAt = $updatedAt; + + return $this; + } +} diff --git a/src/Sylius/Component/Contact/Model/ContactRequestInterface.php b/src/Sylius/Component/Contact/Model/ContactRequestInterface.php new file mode 100644 index 0000000000..93b508e1e6 --- /dev/null +++ b/src/Sylius/Component/Contact/Model/ContactRequestInterface.php @@ -0,0 +1,72 @@ + + */ +interface ContactRequestInterface extends TimestampableInterface +{ + /** + * @return string + */ + public function getFirstName(); + + /** + * @param string $firstName + */ + public function setFirstName($firstName); + + /** + * @return string + */ + public function getLastName(); + + /** + * @param string $lastName + */ + public function setLastName($lastName); + + /** + * @return string + */ + public function getEmail(); + + /** + * @param string $email + */ + public function setEmail($email); + + /** + * @return string + */ + public function getMessage(); + + /** + * @param string $message + */ + public function setMessage($message); + + /** + * @return ContactTopicInterface + */ + public function getTopic(); + + /** + * @param ContactTopicInterface $topic + */ + public function setTopic($topic); +} diff --git a/src/Sylius/Component/Contact/Model/ContactTopic.php b/src/Sylius/Component/Contact/Model/ContactTopic.php new file mode 100644 index 0000000000..d964259734 --- /dev/null +++ b/src/Sylius/Component/Contact/Model/ContactTopic.php @@ -0,0 +1,60 @@ + + */ +class ContactTopic implements ContactTopicInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $title; + + /** + * @return integer + */ + public function getId() + { + return $this->id; + } + + /** + * {@inheritdoc} + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * {@inheritdoc} + */ + public function getTitle() + { + return $this->title; + } + + public function __toString() + { + return $this->title; + } + +} \ No newline at end of file diff --git a/src/Sylius/Component/Contact/Model/ContactTopicInterface.php b/src/Sylius/Component/Contact/Model/ContactTopicInterface.php new file mode 100644 index 0000000000..a6c2535e9a --- /dev/null +++ b/src/Sylius/Component/Contact/Model/ContactTopicInterface.php @@ -0,0 +1,32 @@ + + */ +interface ContactTopicInterface +{ + /** + * @return string + */ + public function getTitle(); + + /** + * @param string $title + */ + public function setTitle($title); + +} \ No newline at end of file diff --git a/src/Sylius/Component/Contact/README.md b/src/Sylius/Component/Contact/README.md new file mode 100644 index 0000000000..2a51a3dd23 --- /dev/null +++ b/src/Sylius/Component/Contact/README.md @@ -0,0 +1,47 @@ +Contact Component [![Build status...](https://secure.travis-ci.org/Sylius/Contact.png?branch=master)](http://travis-ci.org/Sylius/Contact) +=============== + +Contact request component for e-commerce applications. + +Sylius +------ + +Modern ecommerce for PHP and Symfony2. Visit [Sylius.org](http://sylius.org). + +Documentation +------------- + +Documentation is available on [**docs.sylius.org**](http://docs.sylius.org/en/latest/components/Contact/index.html). + +Contributing +------------ + +All instructions for contributing to Sylius can be found in the [Contributing Guide](http://docs.sylius.org/en/latest/contributing/index.html). + +Support +------- + +If you have a question regarding the usage of this library, please ask on +[Stackoverflow](http://stackoverflow.com). You should use "sylius" +tag when posting and make sure to [browse existing questions](http://stackoverflow.com/questions/tagged/sylius). + +Sylius on Twitter +----------------- + +[Follow the official Sylius account on Twitter!](http://twitter.com/Sylius). + +Bug Tracking +------------ + +If you find a bug, please refer to the [Reporting a Bug](http://docs.sylius.org/en/latest/contributing/code/bugs.html) guide. + +MIT License +----------- + +License can be found [here](https://github.com/Sylius/Contact/blob/master/LICENSE). + +Authors +------- + +The component was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com). +See the list of [contributors](https://github.com/Sylius/Contact/contributors). diff --git a/src/Sylius/Component/Contact/composer.json b/src/Sylius/Component/Contact/composer.json new file mode 100644 index 0000000000..d619f90fca --- /dev/null +++ b/src/Sylius/Component/Contact/composer.json @@ -0,0 +1,48 @@ +{ + "name": "sylius/contact", + "type": "library", + "description": "Contact component for PHP applications.", + "keywords": ["contact", "contact form", "support", "contact request"], + "homepage": "http://sylius.org", + "license": "MIT", + "authors": [ + { + "name": "Paweł Jędrzejewski", + "homepage": "http://pjedrzejewski.com" + }, + { + "name": "Michał Marcinkowski", + "homepage": "http://michalmarcinkowski.com" + }, + { + "name": "Sylius project", + "homepage": "http://sylius.org" + }, + { + "name": "Community contributions", + "homepage": "http://github.com/Sylius/Sylius/contributors" + } + ], + "require": { + "php": ">=5.3.3", + + "sylius/resource": "0.12.*@dev" + }, + "require-dev": { + "phpspec/phpspec": "~2.0" + }, + "config": { + "bin-dir": "bin" + }, + "autoload": { + "psr-4": { "Sylius\\Component\\Contact\\": "" } + }, + "autoload-dev": { + "psr-4": { "Sylius\\Component\\Contact\\spec\\": "spec/" } + }, + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + } +} diff --git a/src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactRequestSpec.php b/src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactRequestSpec.php new file mode 100644 index 0000000000..d8504d57aa --- /dev/null +++ b/src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactRequestSpec.php @@ -0,0 +1,118 @@ + + */ +class ContactRequestSpec extends ObjectBehavior +{ + function it_is_initializable() + { + $this->shouldHaveType('Sylius\Component\Contact\Model\ContactRequest'); + } + + function it_implements_Sylius_contact_request_interface() + { + $this->shouldImplement('Sylius\Component\Contact\Model\ContactRequestInterface'); + } + + function it_has_no_id_by_default() + { + $this->getId()->shouldReturn(null); + } + + function it_has_no_first_name_by_default() + { + $this->getFirstName()->shouldReturn(null); + } + + function its_first_name_is_mutable() + { + $this->setFirstName('Michal'); + $this->getFirstName()->shouldReturn('Michal'); + } + + function it_has_no_last_name_by_default() + { + $this->getLastName()->shouldReturn(null); + } + + function its_last_name_is_mutable() + { + $this->setLastName('lastname'); + $this->getLastName()->shouldReturn('lastname'); + } + + function it_has_no_email_by_default() + { + $this->getEmail()->shouldReturn(null); + } + + function its_email_is_mutable() + { + $this->setEmail('michal@lakion.com'); + $this->getEmail()->shouldReturn('michal@lakion.com'); + } + + function it_has_no_message_by_default() + { + $this->getMessage()->shouldReturn(null); + } + + function its_message_is_mutable() + { + $this->setMessage('hello'); + $this->getMessage()->shouldReturn('hello'); + } + + function it_has_no_topic_by_default() + { + $this->getTopic()->shouldReturn(null); + } + + function its_topic_is_mutable(ContactTopicInterface $topic) + { + $this->setTopic($topic); + $this->getTopic()->shouldReturn($topic); + } + + function it_initializes_creation_date_by_default() + { + $this->getCreatedAt()->shouldHaveType('DateTime'); + } + + function its_creation_date_is_mutable() + { + $date = new \DateTime(); + + $this->setCreatedAt($date); + $this->getCreatedAt()->shouldReturn($date); + } + + function it_has_no_last_update_date_by_default() + { + $this->getUpdatedAt()->shouldReturn(null); + } + + function its_last_update_date_is_mutable() + { + $date = new \DateTime(); + + $this->setUpdatedAt($date); + $this->getUpdatedAt()->shouldReturn($date); + } +} diff --git a/src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactTopicSpec.php b/src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactTopicSpec.php new file mode 100644 index 0000000000..f7273a6de6 --- /dev/null +++ b/src/Sylius/Component/Contact/spec/Sylius/Component/Contact/Model/ContactTopicSpec.php @@ -0,0 +1,47 @@ + + */ +class ContactTopicSpec extends ObjectBehavior +{ + function it_is_initializable() + { + $this->shouldHaveType('Sylius\Component\Contact\Model\ContactTopic'); + } + + function it_implements_Sylius_contact_topic_interface() + { + $this->shouldImplement('Sylius\Component\Contact\Model\ContactTopicInterface'); + } + + function it_has_no_id_by_default() + { + $this->getId()->shouldReturn(null); + } + + function it_has_no_title_by_default() + { + $this->getTitle()->shouldReturn(null); + } + + function its_title_is_mutable() + { + $this->setTitle('Title'); + $this->getTitle()->shouldReturn('Title'); + } + +}