Skip to content

Commit

Permalink
WIP: Feature ss4 (#58)
Browse files Browse the repository at this point in the history
* feat(SS4): Start on ss4 upgrade

* chore(SS4): Update composer.json, travis.yml

* Add phpunit.xml, rename code/ to src/

* fix(composer.json): Fix trailing commas

* feat(SS4): More work on SS4

* feat(GeocodeService): Rewrite GoogleGeocoding to use Guzzle and improve ability to retrieve last error for Geocodable

* feat(AddressableTest): Add tests relating to configuring states / countries

* chore(docs): Update documentation

* fix(travis): Fix .travis.yml config

* fix(composer.json): Fix stability for travis-ci

* fix(composer.json): Add PHPUnit / PHPCS

* feat(composer.json): Add guzzle

* fix(Addressable): Fix logic that was broken

* fix(phpcs): Fix php code sniffer

* fix(docs): Improve documentation

* fix(composer.json): Update composer.json

* chore(LICENSE): Update license to use template

* fix(Addressable): Fix bug in Addressable where AddressMap wouldn't work and add test

* fix(tests): Add skip tests for when over query limit
  • Loading branch information
silbinarywolf authored Jul 27, 2018
1 parent cef994b commit 0c31d56
Show file tree
Hide file tree
Showing 24 changed files with 982 additions and 500 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/tests export-ignore
/docs export-ignore
/.travis.yml export-ignore
/.travis.yml export-ignore
/.phpunit.xml.dist export-ignore
/.phpcs.xml.dist export-ignore
README.md export-ignore
Expand Down
42 changes: 25 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
language: php

php:
- 5.4
- 5.6

env:
matrix:
- DB=MYSQL CORE_RELEASE=3.1
- DB=MYSQL CORE_RELEASE=4

matrix:
include:
- php: 5.4
- php: 5.6
env:
- RECIPE_VERSION=1.0.x-dev
- DB=MYSQL
- CORE_RELEASE=3.1
- php: 5.4
- PHPCS_TEST=1
- PHPUNIT_TEST=1
- php: 7.0
env:
- RECIPE_VERSION=1.1.x-dev
- DB=PGSQL
- CORE_RELEASE=3.2
- php: 5.5
- PHPUNIT_TEST=1
- php: 7.1
env:
- RECIPE_VERSION=4.2.x-dev
- DB=MYSQL
- CORE_RELEASE=3.3
- php: 5.6
- PDO=1
- PHPUNIT_TEST=1
- php: 7.2
env:
- RECIPE_VERSION=4.x-dev
- DB=MYSQL
- PHPCS_TEST=1
- CORE_RELEASE=3
- PDO=1
- PHPUNIT_TEST=1

before_script:
- composer self-update || true
- phpenv rehash
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
- cd ~/builds/ss
- phpenv config-rm xdebug.ini
- composer validate
- composer require --no-update silverstripe/recipe-cms:$RECIPE_VERSION
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile

script:
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs addressable/code/ addressable/tests/ -n; fi
- vendor/bin/phpunit addressable/tests/
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ src/Forms/ tests/ ; fi
5 changes: 5 additions & 0 deletions .upgrade.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mappings:
GoogleGeocoding: Symbiote\Addressable\GeocodeService
Addressable: Symbiote\Addressable\Addressable
Geocodable: Symbiote\Addressable\Geocodable
RegexTextField: Symbiote\Addressable\Forms\RegexTextField
43 changes: 22 additions & 21 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
SilverStripe Addressable Module License
=======================================
BSD 3-Clause License

Copyright © 2009, Symbiote PTY LTD - www.symbiote.com.au
Copyright (c) 2018, Symbiote
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in thebvdocumentation and/or
other materials provided with the distribution.
* Neither the name of SilverStripe nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86 changes: 30 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,44 @@
SilverStripe Addressable Module
===============================
[![Build Status](https://travis-ci.org/symbiote/silverstripe-addressable.svg)](https://travis-ci.org/symbiote/silverstripe-addressable)
# Addressable

The Addressable module adds address fields to an object, and also has support
for automatic geocoding.
[![Build Status](https://travis-ci.org/symbiote/silverstripe-addressable.svg?branch=master)](https://travis-ci.org/symbiote/silverstripe-addressable)
[![Latest Stable Version](https://poser.pugx.org/symbiote/silverstripe-addressable/version.svg)](https://github.com/symbiote/silverstripe-addressable/releases)
[![Latest Unstable Version](https://poser.pugx.org/symbiote/silverstripe-addressable/v/unstable.svg)](https://packagist.org/packages/symbiote/silverstripe-addressable)
[![Total Downloads](https://poser.pugx.org/symbiote/silverstripe-addressable/downloads.svg)](https://packagist.org/packages/symbiote/silverstripe-addressable)
[![License](https://poser.pugx.org/symbiote/silverstripe-addressable/license.svg)](https://github.com/symbiote/silverstripe-addressable/blob/master/LICENSE.md)

Maintainer Contact
------------------
* Marcus Nyeholt (<marcus@symbiote.com.au>)
Adds address fields to a DataObject and also has support for automatic geocoding of the provided address.

Requirements
------------
* SilverStripe 3.0+
![CMS screenshot](https://user-images.githubusercontent.com/3859574/43246926-8b218be2-90f6-11e8-9929-72192e23fc81.png)

Documentation
-------------
## Composer Install

Quick Usage Overview
--------------------

In order to add simple address fields (address, suburb, city, postcode and
country) to an object, simply apply to `Addressable` extension:

```yml
Page:
extensions:
- Addressable
```
composer require symbiote/silverstripe-addressable:~4.0
```

## Requirements

In order to then render the full address into a template, you can use either
`$FullAddress` to return a simple string, or `$FullAddressHTML` to render
the address into a HTML `<address>` tag.

You can define a global set of allowed states or countries using
`Addressable::set_allowed_states()` and `::set_allowed_countries()`
respectively. These can also be set per-instance using `setAllowedStates()` and
`setAllowedCountries()`.

If a single string is provided as a value, then this will be set as the field
for all new objects and the user will not be presented with an input field. If
the value is an array, the user will be presented with a dropdown field.

To add automatic geocoding to an `Addressable` object when the address is
changed, simple apply the `Geocodable` extension:
* SilverStripe 4.0+

```yml
## Documentation

Page:
extensions:
- Geocodable
* [Quick Start](docs/en/quick-start.md)
* [Advanced Usage](docs/en/advanced-usage.md)
* [License](LICENSE.md)
* [Contributing](CONTRIBUTING.md)

```
## Changes from SilverStripe 3.X

This will then use the Google Maps API to translate the address into a latitude
and longitude on save, and save it into the `Lat` and `Lng` fields. NOTE - to support
this, you _must_ specify a Google app Server API key
* `GoogleGeocoding` changed class name to `Symbiote\Addressable\GeocodeService`
* The static method `address_to_point` was changed to a non-static method called `addressToPoint`. This allows you to use the Injector and replace GeocodeService with something else if you need to.
* `Addressable::set_allowed_states(array('' => '', 'NSW' => "New South Wales"));` has been deprecated in favour of config values.
* `Addressable::set_allowed_countries(array('' => '', 'AU' => "Australia"));` has been deprecated in favour of config values.
* `Addressable::set_postcode_regex(...);` has been deprecated in favour of config values.
* `Addressable::set_postcode_regex` config value has been deprecated in favour of `Addressable::postcode_regex`
* NOTE: Previously there was a hack in Addressable that read `Addressable::set_postcode_regex` config value, then called `Addressable::set_postcode_regex()` to update the `protected static postcode_regex;` value in the Addressable __construct() method.

```yml
GoogleGeocoding:
google_api_key: {your_google_server_api_key}
## Credits

```

Allow different postcode regex (e.g. UK postcode with numbers and letters mixed) in config.yml
```yml
Addressable:
set_postcode_regex: '/^[0-9A-Za-z]+$/'
```
* [Mark Taylor](https://github.com/symbiote/silverstripe-addressable/commit/7eb2f81c66502093c82c293943f43de9154ad807) for adding the ability to easily embed a map with AddressMap
* [Nic](https://github.com/muskie9) for writing tests for this module
* [AJ Short](https://github.com/ajshort) for initially writing this module
8 changes: 0 additions & 8 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
name: Addressable
---
GoogleGeocoding:
google_api_url: 'https://maps.googleapis.com/maps/api/geocode/xml'
google_api_key: ''

Geocodable:
is_geocodable: true
Loading

0 comments on commit 0c31d56

Please sign in to comment.