How does the WordPress URL Routing work? - php

I would like to try and mimic how WordPress has their URL routing system designed, only a much more simplistic level. Can someone help me understand how they have their routing system designed so that I could try and mimic it for my own development.
I see that their routing is set up like this:
Array
(
[sitemap(-+([a-zA-Z0-9_-]+))?\.xml$] => index.php?xml_sitemap=params=$matches[2]
[sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$] => index.php?xml_sitemap=params=$matches[2];zip=true
[sitemap(-+([a-zA-Z0-9_-]+))?\.html$] => index.php?xml_sitemap=params=$matches[2];html=true
[sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$] => index.php?xml_sitemap=params=$matches[2];html=true;zip=true
[category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?category_name=$matches[1]&feed=$matches[2]
[category/(.+?)/page/?([0-9]{1,})/?$] => index.php?category_name=$matches[1]&paged=$matches[2]
[category/(.+?)/?$] => index.php?category_name=$matches[1]
[tag/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?tag=$matches[1]&feed=$matches[2]
[tag/([^/]+)/page/?([0-9]{1,})/?$] => index.php?tag=$matches[1]&paged=$matches[2]
[tag/([^/]+)/?$] => index.php?tag=$matches[1]
[type/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?post_format=$matches[1]&feed=$matches[2]
[type/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?post_format=$matches[1]&feed=$matches[2]
[type/([^/]+)/page/?([0-9]{1,})/?$] => index.php?post_format=$matches[1]&paged=$matches[2]
[type/([^/]+)/?$] => index.php?post_format=$matches[1]
[robots\.txt$] => index.php?robots=1
[.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$] => index.php?feed=old
[.*wp-app\.php(/.*)?$] => index.php?error=403
[.*wp-register.php$] => index.php?register=true
[feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]
[(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]
[page/?([0-9]{1,})/?$] => index.php?&paged=$matches[1]
[comments/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]&withcomments=1
[comments/(feed|rdf|rss|rss2|atom)/?$] => index.php?&feed=$matches[1]&withcomments=1
[search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?s=$matches[1]&feed=$matches[2]
[search/(.+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?s=$matches[1]&feed=$matches[2]
[search/(.+)/page/?([0-9]{1,})/?$] => index.php?s=$matches[1]&paged=$matches[2]
[search/(.+)/?$] => index.php?s=$matches[1]
[author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?author_name=$matches[1]&feed=$matches[2]
[author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?author_name=$matches[1]&feed=$matches[2]
[author/([^/]+)/page/?([0-9]{1,})/?$] => index.php?author_name=$matches[1]&paged=$matches[2]
[author/([^/]+)/?$] => index.php?author_name=$matches[1]
[([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]
[([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]
[([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]
[([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]
[([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]
[([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]
[([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]
[([0-9]{4})/([0-9]{1,2})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]
[([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&feed=$matches[2]
[([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&feed=$matches[2]
[([0-9]{4})/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&paged=$matches[2]
[([0-9]{4})/?$] => index.php?year=$matches[1]
[[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
[[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
[[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[[0-9]{4}/[0-9]{1,2}/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
[([0-9]{4})/([0-9]{1,2})/([^/]+)/trackback/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&tb=1
[([0-9]{4})/([0-9]{1,2})/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&feed=$matches[4]
[([0-9]{4})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&feed=$matches[4]
[([0-9]{4})/([0-9]{1,2})/([^/]+)/page/?([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&paged=$matches[4]
[([0-9]{4})/([0-9]{1,2})/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&cpage=$matches[4]
[([0-9]{4})/([0-9]{1,2})/([^/]+)(/[0-9]+)?/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&page=$matches[4]
[[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/?$] => index.php?attachment=$matches[1]
[[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
[[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[[0-9]{4}/[0-9]{1,2}/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
[([0-9]{4})/([0-9]{1,2})/comment-page-([0-9]{1,})/?$] => index.php?year=$matches[1]&monthnum=$matches[2]&cpage=$matches[3]
[([0-9]{4})/comment-page-([0-9]{1,})/?$] => index.php?year=$matches[1]&cpage=$matches[2]
[.?.+?/attachment/([^/]+)/?$] => index.php?attachment=$matches[1]
[.?.+?/attachment/([^/]+)/trackback/?$] => index.php?attachment=$matches[1]&tb=1
[.?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[.?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$] => index.php?attachment=$matches[1]&feed=$matches[2]
[.?.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$] => index.php?attachment=$matches[1]&cpage=$matches[2]
[(.?.+?)/trackback/?$] => index.php?pagename=$matches[1]&tb=1
[(.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$] => index.php?pagename=$matches[1]&feed=$matches[2]
[(.?.+?)/(feed|rdf|rss|rss2|atom)/?$] => index.php?pagename=$matches[1]&feed=$matches[2]
[(.?.+?)/page/?([0-9]{1,})/?$] => index.php?pagename=$matches[1]&paged=$matches[2]
[(.?.+?)/comment-page-([0-9]{1,})/?$] => index.php?pagename=$matches[1]&cpage=$matches[2]
[(.?.+?)(/[0-9]+)?/?$] => index.php?pagename=$matches[1]&page=$matches[2]
)
From there, I am having a tough time following how they physically route all of the traffic through the single index.php file. Conceptually, I understand the commands in the array that setup the URL rewrites and how the .htaccess file works, but I just can't seem to understand how it physically executes the code to pass the parameters through the index.php files.
Anyone have any good tutorials or examples?

Related

Identifying unknown structured data formats – what could be class-oriented JSON

I'm currently working with a Sophos UTM, pushing the wireless statistics to another platform and trying to digest this data format.
It's clearly structured and looks like class-oriented JSON, but cannot quite figure out what it is or how to convert it to something usable. Any ideas? I thought about just writing a JSON-converter in PHP, but I'm afraid that I might just be missing a puzzle piece.
{
'clients' => {
'0c:2c:54:xx:xx:xx' => {
'ap' => '',
'connected_time_sec' => 1720,
'connected_time_str' => '00:28:40',
'hwaddr' => '0c:2c:54:xx:xx:xx',
'ip' => '172.16.28.206',
'last_rxrate_bps' => '1048576',
'last_rxrate_str' => '1024.0 kbit/s',
'last_txrate_bps' => '6815744',
'last_txrate_str' => '6.5 Mbit/s',
'lastseen_str' => '2018-11-04 18:06:37',
'lastseen_ts' => 1541351197,
'mesh_id' => '',
'mesh_mode' => 'none',
'name' => 'HUAWEI_P20_Pro',
'radio_id' => '0',
'signal_per' => '39',
'ssid' => 'ssid',
'vendor' => 'unknown'
},
'44:d8:84:xx:xx:xx' => {
'ap' => 'A40001AXX8FXXXX',
'connected_time_sec' => 534992,
'connected_time_str' => '06:04:36:32',
'hwaddr' => '44:d8:84:xx:xx:xx',
'ip' => '172.16.28.149',
'last_rxrate_bps' => '1048576',
'last_rxrate_str' => '1024.0 kbit/s',
'last_txrate_bps' => '60607488',
'last_txrate_str' => '57.8 Mbit/s',
'lastseen_str' => '2018-11-04 20:44:28',
'lastseen_ts' => 1541360668,
'mesh_id' => '',
'mesh_mode' => 'none',
'name' => 'iMac-OBC',
'radio_id' => '0',
'signal_per' => '65',
'ssid' => 'ssid',
'vendor' => 'Apple'
}
},
'connected' => {
'A40001AXX8FXXXX' => {
'associated_clients' => [
'ab:cd:ef:gh:ij:kl',
'44:d8:84:xx:xx:xx',
],
'bss' => undef,
'id' => 'A40001AXX8FXXXX',
'ip' => '192.168.10.11',
'lan_mac' => '00:1a:8c:xx:xx:xx',
'location' => 'AP30',
'type' => 'AP30',
'wifi_mac' => '00:1a:8c:xx:xx:xx'
},
'A4000EASIJDFSDOI' => {
'associated_clients' => [],
'bss' => undef,
'id' => 'A4000EASIJDFSDOI',
'ip' => '192.168.10.12',
'lan_mac' => '00:1a:8c:xx:xx:xx',
'location' => 'AP30',
'type' => 'AP30',
'wifi_mac' => '00:1a:8c:xx:xx:xx'
}
},
'disconnected' => {},
'lastupdate' => 1541360678
}
Your sample data has 4 repairs to make on the road to valid json town.
Make the following replacements:
=> to :
' to "
remove all trailing , that are followed by zero or more whitespace characters then a ]
wrap your undef values in double quotes
Code: (Demo)
$almostjson = <<<ALMOSTJSON
...your input string
ALMOSTJSON;
$json = preg_replace(["~=>~", "~'~", "~,(?=\s*])~", "~:\s+\Kundef~"], [':', '"', '', '"$0"'], $almostjson);
var_export(json_decode($json, true));
Calling regex functions on strings that contain key-value relationships is vulnerable to unintended matching. This "solution" should be considered a "bandaid" until the source of the data can be improved. This solution may silently fail in the future if the wrong quality of text is in the string.

Symfony2.8 -> 3.3 Sonata\CoreBundle\Form\Extension\DependencyInjectionExtension::__construct() must be of the type array, object given, called in

I have updated symfony 2.8 -> 3.3
Now Top page looks working.
However when I load the page where uses form builder I burped into this error.
Type error: Argument 3 passed to
Sonata\CoreBundle\Form\Extension\DependencyInjectionExtension::__construct()
must be of the type array, object given, called in
/Users/whitebear/CodingWorks/httproot/myapp/var/cache/dev/appDevDebugProjectContainer.php
on line 1325
I think this is related to service container though, I can’t figure out where should I fix.
What I am doing is like this below
$em = $this->getDoctrine()->getManager();
$reqDoc = new reqDoc();
$form = $this->createFormBuilder($reqDoc)
error messages is below
DependencyInjectionExtension->__construct(object(appDevDebugProjectContainer), array('Symfony\Component\Form\Extension\Core\Type\FormType'
=>object(RewindableGenerator), 'Symfony\Component\Form\Extension\Core\Type\RepeatedType'
=> object(RewindableGenerator), 'Symfony\Component\Form\Extension\Core\Type\SubmitType'
=> object(RewindableGenerator), 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'
=> object(RewindableGenerator)), object(RewindableGenerator), null,array('sonata_type_admin'
=> 'Sonata\AdminBundle\Form\Type\AdminType', 'sonata_type_model' => 'Sonata\AdminBundle\Form\Type\ModelType', 'sonata_type_model_list' =>
'Sonata\AdminBundle\Form\Type\ModelTypeList',
'sonata_type_model_reference' =>
'Sonata\AdminBundle\Form\Type\ModelReferenceType',
'sonata_type_model_hidden' =>
'Sonata\AdminBundle\Form\Type\ModelHiddenType',
'sonata_type_model_autocomplete' =>
'Sonata\AdminBundle\Form\Type\ModelAutocompleteType',
'sonata_type_native_collection' =>
'Sonata\AdminBundle\Form\Type\CollectionType',
'sonata_type_choice_field_mask' =>
'Sonata\AdminBundle\Form\Type\ChoiceFieldMaskType',
'sonata_type_filter_number' =>
'Sonata\AdminBundle\Form\Type\Filter\NumberType',
'sonata_type_filter_choice' =>
'Sonata\AdminBundle\Form\Type\Filter\ChoiceType',
'sonata_type_filter_default' =>
'Sonata\AdminBundle\Form\Type\Filter\DefaultType',
'sonata_type_filter_date' =>
'Sonata\AdminBundle\Form\Type\Filter\DateType',
'sonata_type_filter_date_range' =>
'Sonata\AdminBundle\Form\Type\Filter\DateRangeType',
'sonata_type_filter_datetime' =>
'Sonata\AdminBundle\Form\Type\Filter\DateTimeType',
'sonata_type_filter_datetime_range' =>
'Sonata\AdminBundle\Form\Type\Filter\DateTimeRangeType', 'tab' =>
'Mopa\Bundle\BootstrapBundle\Form\Type\TabType',
'sonata_block_service_choice' =>
'Sonata\BlockBundle\Form\Type\ServiceListType',
'sonata_type_container_template_choice' =>
'Sonata\BlockBundle\Form\Type\ContainerTemplateType', 'form' =>
'Symfony\Component\Form\Extension\Core\Type\FormType',
'birthday' =>
'Symfony\Component\Form\Extension\Core\Type\BirthdayType',
'checkbox' =>
'Symfony\Component\Form\Extension\Core\Type\CheckboxType',
'choice' =>
'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
'collection' =>
'Symfony\Component\Form\Extension\Core\Type\CollectionType',
'country' =>
'Symfony\Component\Form\Extension\Core\Type\CountryType', 'date'
=> 'Symfony\Component\Form\Extension\Core\Type\DateType', 'datetime' =>
'Symfony\Component\Form\Extension\Core\Type\DateTimeType',
'email' =>
'Symfony\Component\Form\Extension\Core\Type\EmailType', 'file'
=> 'Symfony\Component\Form\Extension\Core\Type\FileType', 'hidden' =>
'Symfony\Component\Form\Extension\Core\Type\HiddenType',
'integer' =>
'Symfony\Component\Form\Extension\Core\Type\IntegerType',
'language' =>
'Symfony\Component\Form\Extension\Core\Type\LanguageType',
'locale' =>
'Symfony\Component\Form\Extension\Core\Type\LocaleType', 'money'
=> 'Symfony\Component\Form\Extension\Core\Type\MoneyType', 'number' =>
'Symfony\Component\Form\Extension\Core\Type\NumberType',
'password' =>
'Symfony\Component\Form\Extension\Core\Type\PasswordType',
'percent' =>
'Symfony\Component\Form\Extension\Core\Type\PercentType',
'radio' =>
'Symfony\Component\Form\Extension\Core\Type\RadioType',
'repeated' =>
'Symfony\Component\Form\Extension\Core\Type\RepeatedType',
'search' =>
'Symfony\Component\Form\Extension\Core\Type\SearchType',
'textarea' =>
'Symfony\Component\Form\Extension\Core\Type\TextareaType',
'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
'time' => 'Symfony\Component\Form\Extension\Core\Type\TimeType',
'timezone' =>
'Symfony\Component\Form\Extension\Core\Type\TimezoneType', 'url'
=> 'Symfony\Component\Form\Extension\Core\Type\UrlType', 'button' =>
'Symfony\Component\Form\Extension\Core\Type\ButtonType',
'submit' =>
'Symfony\Component\Form\Extension\Core\Type\SubmitType', 'reset'
=> 'Symfony\Component\Form\Extension\Core\Type\ResetType', 'currency' =>
'Symfony\Component\Form\Extension\Core\Type\CurrencyType',
'entity' => 'Symfony\Bridge\Doctrine\Form\Type\EntityType',
'sonata_type_immutable_array' =>
'Sonata\CoreBundle\Form\Type\ImmutableArrayType',
'sonata_type_boolean' =>
'Sonata\CoreBundle\Form\Type\BooleanType',
'sonata_type_collection' =>
'Sonata\CoreBundle\Form\Type\CollectionType',
'sonata_type_translatable_choice' =>
'Sonata\CoreBundle\Form\Type\TranslatableChoiceType',
'sonata_type_date_range' =>
'Sonata\CoreBundle\Form\Type\DateRangeType',
'sonata_type_datetime_range' =>
'Sonata\CoreBundle\Form\Type\DateTimeRangeType',
'sonata_type_date_picker' =>
'Sonata\CoreBundle\Form\Type\DatePickerType',
'sonata_type_datetime_picker' =>
'Sonata\CoreBundle\Form\Type\DateTimePickerType',
'sonata_type_date_range_picker' =>
'Sonata\CoreBundle\Form\Type\DateRangePickerType',
'sonata_type_datetime_range_picker' =>
'Sonata\CoreBundle\Form\Type\DateTimeRangePickerType',
'sonata_type_equal' => 'Sonata\CoreBundle\Form\Type\EqualType',
'sonata_type_color_selector' =>
'Sonata\CoreBundle\Form\Type\ColorSelectorType'), array('form'
=>array('sonata.admin.form.extension.field', 'mopa_bootstrap.form.type_extension.help',
'mopa_bootstrap.form.type_extension.legend',
'mopa_bootstrap.form.type_extension.error',
'mopa_bootstrap.form.type_extension.widget',
'mopa_bootstrap.form.type_extension.horizontal',
'mopa_bootstrap.form.type_extension.widget_collection',
'mopa_bootstrap.form.type_extension.tabbed',
'form.type_extension.form.http_foundation',
'form.type_extension.form.validator', 'form.type_extension.csrf',
'form.type_extension.form.data_collector'), 'choice'
=>array('sonata.admin.form.extension.choice'), 'button' => array('mopa_bootstrap.form.type_extension.button'), 'date' =>array('mopa_bootstrap.form.type_extension.date'), 'repeated' => array('form.type_extension.repeated.validator'), 'submit' =>array('form.type_extension.submit.validator')), array())
in var/cache/dev/appDevDebugProjectContainer.php (line 1325)
Here my answer mentioned in the comments:
Probably you have to upgrade your SonataCoreBundle dependency version as well. Maybe this one is not compatible with Symfony 3.3.

Array into a PHP Soapclient call

I'm using php and Soapclient. I need send next parameters:
<sch:CodConsulta v="5473"/>
<sch:Parametros>
<sch:Txt n="Agente" v="aaa"/>
<sch:Fec n="Fecha" v="2018-01-24"/>
<sch:Txt n="Sesion" v="0"/>
</sch:Parametros>
I've tried send params like this:
$parametros = array(
"CodConsulta" => array('_' => '',"v" => "5473"),
"Parametros" => array(
"Txt" => array('_' => '',"n" => "Agente","v" => "aaa"),
"Fec" => array('_' => '',"n" => "Fecha","v" => "2018-01-24"),
"Txt" => array('_' => '',"n" => "Sesion","v" => "0")
)
);
Webservice return error, only receive 1 param...
Any help would be much appreciated. Thanks in advance.

Having a hard time retrieving the customer_id getId() from createCustomer object to pass to createCustomerCard

Here is my code which is the example I used from here
$createcustomer_api = new \SquareConnect\Api\CustomersApi();
$createcustomer_result = $createcustomer_api->createCustomer(array(
'given_name' => 'Amelia',
'family_name' => 'Earhart',
'email_address' => 'Amelia.Earhart#example.com',
'address' => array(
'address_line_1' => '500 Electric Ave',
'address_line_2' => 'Suite 600',
'locality' => 'New York',
'administrative_district_level_1' => 'NY',
'postal_code' => '10003',
'country' => 'US'
),
'phone_number' => '1-555-555-0122',
'reference_id' => 'YOUR_REFERENCE_ID',
'note' => 'a customer'
));
If I print out the results I get
SquareConnect\Model\CreateCustomerResponse Object
(
[errors:protected] =>
[customer:protected] => SquareConnect\Model\Customer Object
(
[id:protected] => CBASEHtp6YVU8AirkMv1lrVMyoIgAQ
[created_at:protected] => 2017-09-27T23:19:44.62Z
[updated_at:protected] => 2017-09-27T23:19:44.62Z
[cards:protected] =>
[given_name:protected] => Amelia
[family_name:protected] => Earhart
[nickname:protected] =>
[company_name:protected] =>
[email_address:protected] => Amelia.Earhart#example.com
[address:protected] => SquareConnect\Model\Address Object
(
[address_line_1:protected] => 500 Electric Ave
[address_line_2:protected] => Suite 600
[address_line_3:protected] =>
[locality:protected] => New York
[sublocality:protected] =>
[sublocality_2:protected] =>
[sublocality_3:protected] =>
[administrative_district_level_1:protected] => NY
[administrative_district_level_2:protected] =>
[administrative_district_level_3:protected] =>
[postal_code:protected] => 10003
[country:protected] => US
[first_name:protected] =>
[last_name:protected] =>
[organization:protected] =>
)
[phone_number:protected] => 1-555-555-0122
[reference_id:protected] => YOUR_REFERENCE_ID
[note:protected] => a customer
[preferences:protected] => SquareConnect\Model\CustomerPreferences Object
(
[email_unsubscribed:protected] =>
)
[groups:protected] =>
)
)
Now I need to create the customer card to associate with the customer for future recurring payments.
$createcard_api = new \SquareConnect\Api\CustomersApi();
$createcard_result = $createcard_api->createCustomerCard($createcustomer_result->getId(), array(
'card_nonce' => $nonce,
'billing_address' => array(
'address_line_1' => '1455 Market St',
'address_line_2' => 'Suite 600',
'locality' => 'San Francisco',
'administrative_district_level_1' => 'CA',
'postal_code' => '94103',
'country' => 'US'
),
'cardholder_name' => 'Amelia Earhart'
));
From what I understand there is a built-in function with the square SDK that is getId() which according to this is called like $customer->getId(), but according to this I need to just add ->getId() to my createCustomer object.
So I am trying to call the getId() function as
$createcustomer_result->getId()
but in my code I am getting the error
Fatal error: Call to undefined method SquareConnect\Model\CreateCustomerResponse::getId()
How do I properly get the customer id from the createCustomer?
You've only got the response object from the API, a communication device. You need to first extract the created object from the response, then you can query it for the ID.
$customer = $createcustomer_result->getCustomer();
That should get you the actual customer object, then you can:
$customer_id = $customer->getId();
This is pretty common for API libraries. You can also query the response object for errors if they occur. When using these kinds of libraries, have a look inside the various classes and read through the functions, you can get a better idea of how you use them that way.

Wordpress rewrite_rules order is wrong

After an export with migrate DB, my rewrite rules are not in a good order, and I can't fix it in database because when I regenerate them, it happens again.
I don't know if it's related to the plugin or not.
What I call my rules are the rules added with my custom post types.
So, the rules should begin with MY RULES first (from custom post types), but it starts with
.?.+?/attachment/([^/]+)/?$ => index.php?attachment=$matches[1]
and this rule and the ones that follow it (I checked in other wordpress databases) should be near the end of the array.
My problem is that there is a rule after this one that break every page in my site (because it's too generic and catch everything), it's this one :
"(.?.+?)(/[0-9]+)?/?$ => index.php?pagename=$matches[1]&page=$matches[2]"
I've debugged it but I cannot resolve it.
Here's the order:
".?.+?/attachment/([^/]+)/?$ => index.php?attachment=$matches[1]"
".?.+?/attachment/([^/]+)/trackback/?$ => index.php?attachment=$matches[1]&tb=1"
".?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
".?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
".?.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?attachment=$matches[1]&cpage=$matches[2]"
"(.?.+?)/trackback/?$ => index.php?pagename=$matches[1]&tb=1"
"(.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?pagename=$matches[1]&feed=$matches[2]"
"(.?.+?)/(feed|rdf|rss|rss2|atom)/?$ => index.php?pagename=$matches[1]&feed=$matches[2]"
"(.?.+?)/page/?([0-9]{1,})/?$ => index.php?pagename=$matches[1]&paged=$matches[2]"
"(.?.+?)/comment-page-([0-9]{1,})/?$ => index.php?pagename=$matches[1]&cpage=$matches[2]"
"(.?.+?)/wc-api(/(.*))?/?$ => index.php?pagename=$matches[1]&wc-api=$matches[3]"
"(.?.+?)/order-pay(/(.*))?/?$ => index.php?pagename=$matches[1]&order-pay=$matches[3]"
"(.?.+?)/order-received(/(.*))?/?$ => index.php?pagename=$matches[1]&order-received=$matches[3]"
"(.?.+?)/view-order(/(.*))?/?$ => index.php?pagename=$matches[1]&view-order=$matches[3]"
"(.?.+?)/edit-account(/(.*))?/?$ => index.php?pagename=$matches[1]&edit-account=$matches[3]"
"(.?.+?)/edit-address(/(.*))?/?$ => index.php?pagename=$matches[1]&edit-address=$matches[3]"
"(.?.+?)/lost-password(/(.*))?/?$ => index.php?pagename=$matches[1]&lost-password=$matches[3]"
"(.?.+?)/customer-logout(/(.*))?/?$ => index.php?pagename=$matches[1]&customer-logout=$matches[3]"
"(.?.+?)/add-payment-method(/(.*))?/?$ => index.php?pagename=$matches[1]&add-payment-method=$matches[3]"
".?.+?/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
".?.+?/attachment/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
"(.?.+?)(/[0-9]+)?/?$ => index.php?pagename=$matches[1]&page=$matches[2]"
// my rules ...
".*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$ => index.php?feed=old"
".*wp-app\.php(/.*)?$ => index.php?error=403"
".*wp-register.php$ => index.php?register=true"
"feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]"
"(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]"
"page/?([0-9]{1,})/?$ => index.php?&paged=$matches[1]"
"comment-page-([0-9]{1,})/?$ => index.php?&page_id=20&cpage=$matches[1]"
"wc-api(/(.*))?/?$ => index.php?&wc-api=$matches[2]"
"order-pay(/(.*))?/?$ => index.php?&order-pay=$matches[2]"
"order-received(/(.*))?/?$ => index.php?&order-received=$matches[2]"
"view-order(/(.*))?/?$ => index.php?&view-order=$matches[2]"
"edit-account(/(.*))?/?$ => index.php?&edit-account=$matches[2]"
"edit-address(/(.*))?/?$ => index.php?&edit-address=$matches[2]"
"lost-password(/(.*))?/?$ => index.php?&lost-password=$matches[2]"
"customer-logout(/(.*))?/?$ => index.php?&customer-logout=$matches[2]"
"add-payment-method(/(.*))?/?$ => index.php?&add-payment-method=$matches[2]"
"comments/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]&withcomments=1"
"comments/(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]&withcomments=1"
"comments/wc-api(/(.*))?/?$ => index.php?&wc-api=$matches[2]"
"search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?s=$matches[1]&feed=$matches[2]"
"search/(.+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?s=$matches[1]&feed=$matches[2]"
"search/(.+)/page/?([0-9]{1,})/?$ => index.php?s=$matches[1]&paged=$matches[2]"
"search/(.+)/wc-api(/(.*))?/?$ => index.php?s=$matches[1]&wc-api=$matches[3]"
"search/(.+)/?$ => index.php?s=$matches[1]"
"author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?author_name=$matches[1]&feed=$matches[2]"
"author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?author_name=$matches[1]&feed=$matches[2]"
"author/([^/]+)/page/?([0-9]{1,})/?$ => index.php?author_name=$matches[1]&paged=$matches[2]"
"author/([^/]+)/wc-api(/(.*))?/?$ => index.php?author_name=$matches[1]&wc-api=$matches[3]"
"author/([^/]+)/?$ => index.php?author_name=$matches[1]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/wc-api(/(.*))?/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&wc-api=$matches[5]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/wc-api(/(.*))?/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&wc-api=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]"
"([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&feed=$matches[2]"
"([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&feed=$matches[2]"
"([0-9]{4})/page/?([0-9]{1,})/?$ => index.php?year=$matches[1]&paged=$matches[2]"
"([0-9]{4})/wc-api(/(.*))?/?$ => index.php?year=$matches[1]&wc-api=$matches[3]"
"([0-9]{4})/?$ => index.php?year=$matches[1]"
"[^/]+/attachment/([^/]+)/?$ => index.php?attachment=$matches[1]"
"[^/]+/attachment/([^/]+)/trackback/?$ => index.php?attachment=$matches[1]&tb=1"
"[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?attachment=$matches[1]&cpage=$matches[2]"
"([^/]+)/trackback/?$ => index.php?name=$matches[1]&tb=1"
"([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?name=$matches[1]&feed=$matches[2]"
"([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?name=$matches[1]&feed=$matches[2]"
"([^/]+)/page/?([0-9]{1,})/?$ => index.php?name=$matches[1]&paged=$matches[2]"
"([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?name=$matches[1]&cpage=$matches[2]"
"([^/]+)/wc-api(/(.*))?/?$ => index.php?name=$matches[1]&wc-api=$matches[3]"
"[^/]+/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
"[^/]+/attachment/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
"([^/]+)(/[0-9]+)?/?$ => index.php?name=$matches[1]&page=$matches[2]"
"[^/]+/([^/]+)/?$ => index.php?attachment=$matches[1]"
"[^/]+/([^/]+)/trackback/?$ => index.php?attachment=$matches[1]&tb=1"
"[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?attachment=$matches[1]&cpage=$matches[2]"
I fix the problem (temporarily) with some array_splice, but I believe this fix could break in the futur
I would want to know why the generation is wrong
Thank you very much

Categories