Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Zf2 how arrays will save your project

955 views

Published on

  • Be the first to comment

Zf2 how arrays will save your project

  1. 1. Zend Framework2 How arrays will save your project in it2PROFESSIONAL PHP SERVICES
  2. 2. Michelangelo van Dam PHP Consultant, Community Leader & Trainer https://www.flickr.com/photos/akrabat/8784318813
  3. 3. Schedule Introduction to ZF2 The array Challenges in development Solutions offered in ZF2 More options
  4. 4. Schedule Introduction to ZF2 The array Challenges in development Solutions offered in ZF2 More options
  5. 5. “The Array Framework”
  6. 6. <?php /**  * Zend Framework 2 Configuration Settings  *  */ return array(     'modules' => array(         'Application',         'In2itSsoProvider',         'In2itCrmDashboard',         'In2itCrmContactManager',         'In2itCrmOrderManager',         'In2itCrmProductManager',     ),     'module_listener_options' => array(         'module_paths' => array(             './module',             './vendor'         ),         'config_glob_paths' => array(             '/home/dragonbe/workspace/Totem/config/autoload/{,*.}{global,local}.php'         ),         'config_cache_key' => 'application.config.cache',         'config_cache_enabled' => true,         'module_map_cache_key' => 'application.module.cache',         'module_map_cache_enabled' => true,         'cache_dir' => 'data/cache/'     ) );
  7. 7. <?php namespace In2itCrmDashboard; use ZendModuleManagerFeatureConfigProviderInterface; use ZendMvcModuleRouteListener; use ZendMvcMvcEvent; class Module implements ConfigProviderInterface {     public function getAutoloaderConfig()     {         return array(             'ZendLoaderClassMapAutoloader' => array(                 __DIR__ . '/autoload_classmap.php',             ),             'ZendLoaderStandardAutoloader' => array(                 'namespaces' => array(                     __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,                 ),             ),         );     }     public function getConfig()     {         return include __DIR__ . '/config/module.config.php';     } }
  8. 8. https://www.flickr.com/photos/dasprid/8147986307
  9. 9. Yaml XML INI CSV PHP
  10. 10. PHP
  11. 11. Schedule Introduction to ZF2 The array Challenges in development Solutions offered in ZF2 More options
  12. 12. array_change_key_case array_chunk array_column array_combine array_count_values array_diff_assoc array_diff_key array_diff_uassoc array_diff_ukey array_diff array_fill_keys array_fill array_filter array_flip array_intersect_assoc array_intersect_key array_intersect_uassoc array_intersect_ukey array_intersect array_key_exists array_keys array_map array_merge_recursive array_merge array_multisort array_pad array_pop array_product array_push array_rand array_reduce array_replace_recursive array_replace array_reverse array_search array_shift array_slice array_splice array_sum array_udiff_assoc array_udiff_uassoc array_udiff array_uintersect_assoc array_uintersect_uassoc array_uintersect array_unique array_unshift array_values array_walk_recursive array_walk array arsort asort compact count current each end extract in_array key_exists key krsort ksort list natcasesort natsort next pos prev range reset rsort shuffle sizeof sort uasort uksort usort
  13. 13. Do you know them?
  14. 14. array_search array_filter ? ? ? ? ? ? ? ?? ? ? ?? ? ? ? ?
  15. 15. count array_sum array_product ? ? ? ? ? ? ? ?? ? ? ?? ? ? ? ?
  16. 16. array_diff array_intersect array_merge ? ? ? ? ? ? ? ?? ? ? ?? ? ? ? ?
  17. 17. // Let's take one value out of our array $array = ['apple', 'banana', 'chocolate']; $newArray = []; foreach ($array as $value) {   if ('banana' !== $value) {       $newArray[] = $value;   } } echo implode(', ', $newArray); // Outputs: apple, chocolate
  18. 18. <?php // Let's take one value out of our array $array = ['apple', 'banana', 'chocolate']; // I keep an ignore list as well $ignore = ['banana']; // Ready for magic? echo implode(', ', array_diff($array, $ignore)); // Outputs: apple, chocolate
  19. 19. <?php // I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate']; // And a similar value array $similar = ['banana', 'chocolate']; // I need to get the keys of similar items from original array $newSimilar = []; foreach ($array as $key => $value) {     if (in_array($value, $similar)) {         $newSimilar[$key] = $value;     } } $similar = $newSimilar; unset ($newSimilar); var_dump($similar); /* Outputs: array(2) {   'b' =>   string(6) "banana"   'c' =>   string(9) "chocolate" } */
  20. 20. <?php // I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate']; // And a similar value array $similar = ['banana', 'chocolate']; // I need to get the keys of similar items from original array $similar = array_intersect($array, $similar); var_dump($similar); /* Outputs: array(2) {   'b' =>   string(6) "banana"   'c' =>   string(9) "chocolate" } */
  21. 21. One more?
  22. 22. <?php // I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate']; // I need to find a given value -> 'chocolate' $search = 'chocolate'; $searchResult = []; foreach ($array as $key => $value) {     if ($search === $value) {         $searchResult[$key] = $value;     } } var_dump($searchResult); /* Outputs: array(1) {   'c' =>   string(9) "chocolate" } */
  23. 23. <?php // I have one associative array $array = ['a' => 'apple', 'b' => 'banana', 'c' => 'chocolate']; // I need to find a given value -> 'chocolate' $search = 'chocolate'; $searchResult = array_filter($array, function ($var) use ($search) {      return $search === $var; }); var_dump($searchResult); /* Outputs: array(1) {   'c' =>   string(9) "chocolate" } */
  24. 24. Schedule Introduction to ZF2 The array Challenges in development Solutions offered in ZF2 More options
  25. 25. Lots of data
  26. 26. Lists of data rows
  27. 27. <?php $query = "SELECT * FROM `contact` WHERE `age` > ? AND `gende r` = ?"; $stmt = $pdo->prepare($query); $stmt->bindParam(1, $cleanAge); $stmt->bindParam(2, $cleanGender); $stmt->execute(); // A resultset of 63,992 entries stored in an array!!! $resultList = $stmt->fetchAll();
  28. 28. <?php public function getSelectedContacts($age, $gender) {     $resultSet = $this->tableGateway->select(array(         'age' => $age,         'gender' => $gender,     ));    return $resultSet; }
  29. 29. Iterators!!!
  30. 30. Loop with arrays • Data fetching time for 63992 of 250000 records:
 2.14 seconds • Data processing time for 63992 of 250000 records:
 7.11 seconds • Total time for 63992 of 250000 records: 
 9.25 seconds • Memory consumption for 63992 of 250000 records: 217.75MB
  31. 31. Loop with Iterators • Data fetching time for 63992 of 250000 records:
 0.92 seconds • Data processing time for 63992 of 250000 records: 
 5.57 seconds • Total time for 63992 of 250000 records: 
 6.49 seconds • Memory consumption for 63992 of 250000 records: 
 0.25MB
  32. 32. Loop with Iterators • Data fetching time for 63992 of 250000 records:
 0.92 seconds • Data processing time for 63992 of 250000 records: 
 5.57 seconds • Total time for 63992 of 250000 records: 
 6.49 seconds • Memory consumption for 63992 of 250000 records: 
 0.25MB <-> 217.75MB
  33. 33. Schedule Introduction to ZF2 The array Challenges in development Solutions offered in ZF2 More options
  34. 34. Iterators
  35. 35. Interfaces
  36. 36. Responsibility Separation
  37. 37. Modules
  38. 38. Schedule Introduction to ZF2 The array Challenges in development Solutions offered in ZF2 More options
  39. 39. –Michelangelo van Dam “You dislike arrays because you don’t know them well enough to love them”
  40. 40. Links • Array functions
 http://php.net/manual/en/ref.array.php • Iterator
 http://php.net/manual/en/class.iterator.php • SPL Iterators and DataStructures
 http://php.net/spl/
  41. 41. PHPSheatSheets http://phpcheatsheets.com/index.php
  42. 42. https://www.flickr.com/photos/lwr/13442542235
  43. 43. Contact us in it2PROFESSIONAL PHP SERVICES Michelangelo van Dam michelangelo@in2it.be www.in2it.be PHP Consulting - Training - QA
  44. 44. Thank you Have a great conference http://www.flickr.com/photos/drewm/3191872515

×