SlideShare una empresa de Scribd logo
1 de 53
Descargar para leer sin conexión
Shahar Evron | Zend Technologies


Zend Framework Components
     ...for non-framework development
Agenda

• Zend Framework's „Use At Will“ approach
• So why would I want to use Zend Framework?
• Show Us The Code! (the interesting part)
     ○   Zend_Mail
     ○   Zend_Db
     ○   Zend_Config
     ○   Zend_Http_Client
     ○   Zend_Service
     ○   Zend_Json
     ○   Zend_Log

• Some other things worth looking at

Shahar Evron | Zend Technologies             2
Prologue

• Who Are You?

     ○   PHP Programmers / Users?
     ○   Using Zend Framework?
     ○   Using other PHP Frameworks?
     ○   Using PEAR classes in your code?
     ○   Tend to reuse other people's code?




Shahar Evron | Zend Technologies              3
Prologue

• Who am I?
     ○ Programming in PHP for ~6 years
     ○ Working for Zend for the last 3 years
           ▪ Services, Product Management
     ○   Part-time contributor to ZF
           ▪ Not a part of my actual job ;-)
     ○   If you have a hard time with my name:
           ▪   German: Shachar
           ▪   Spanish: Shajar
           ▪   Russian: Шахар
           ▪   Arabic: ‫ﺷﺨﺮ‬
           ▪   Hebrew: ‫שחר‬
                         ַ ָ


Shahar Evron | Zend Technologies                 4
Why Zend Framework?
Fire At Will!

• Zend Framework embraces a use-at-will philosophy
• In practice, this means we try to have little or no
  dependencies between components
     ○ You don't have to use the entire framework
     ○ You don't have to build your application in a particular way
     ○ ...But if you want to, you can!

• There are some components (mostly the MVC stuff)
  that have loose bindings to other components
• Many components have very little dependencies, and
  can simply be included and used in any application

Shahar Evron | Zend Technologies                    6
Ooohh... Pretty Colors!




Shahar Evron | Zend Technologies   7
If No Framework, Why Zend Framework?

• Because it's high quality
     ○   Strict standards from day one
     ○   Unit Tested (80%+ code coverage)
     ○   Used and reviewed by a large community of users

• Because it's clean IP and friendly licensed

• Because it's there!
     ○   Well, it's one good option – you have others of course ;)


Shahar Evron | Zend Technologies                     8
Ok, we get it,
Now show us the Code!
Zend_Mail




Shahar Evron | Zend Technologies               10
Zend_Mail

• Allows you to easily compose and send e-mail
  messages from your PHP applications
• Simplified control over recipients, headers, etc.
• Easy creation of multipart/alternative HTML
  messages
• Easy attachment handling
• Supports different delivery transports
• Allows you to read e-mail messages from POP3,
  IMAP, Mbox and Maildir (not discussed here)

Shahar Evron | Zend Technologies           11
Zend_Mail

Sending a simple message through Zend_Mail:
   // Load the Zend_Mail class
   require_once 'Zend/Mail.php';

   // Instantiate a new message object
   $message = new Zend_Mail('utf-8');

   // Use the fluent interface to set message properties
   $message->setFrom('shahar.e@zend.com', 'Shahar E')
           ->setSubject('Hello, world!')
           ->setBodyText(quot;Hi, what's up?quot;)
           ->addHeader('Importance', 'high')
           ->addTo('someone@example.com', 'Some One')
           ->addCc('other.guy@example.com', 'Other Guy')
           ->addBcc('t.person@example.com', 'The Third Person');

   // Send the message!
   $message->send();



Shahar Evron | Zend Technologies                      12
Zend_Mail

Creating multipart/alternative messages
   // ...Load the Zend_Mail and prepare the message object as before...

   $text = <<<WELCOME_MSG
   Hello Shahar,

   *Thank you* for registering to my new site.
   You are welcome to log in at http://example.com/log-in

   The example.com team!
   WELCOME_MSG;

   // Set the plain text and HTML body parts
   $message->setBodyText($text);
   $message->setBodyHtml(nl2br(preg_replace(
             array('/*(.+?)*/', '|https?://S+|'),
             array('<strong>1</strong>', '<a href=quot;0quot;>0</a>'),
             $text)));

   // Send the message!
   $message->send();




Shahar Evron | Zend Technologies                                    13
Zend_Mail

Creating multipart/alternative messages - result:
   Subject: Hello, world!
   From: quot;Shahar Equot; <shahar.e@zend.com>
   Importance: high
   Content-Type: multipart/alternative; charset=quot;utf8quot;;
    boundary=quot;=_96d67bd80a67ddc3fa0d70097a48504equot;
   MIME-Version: 1.0

   --=_96d67bd80a67ddc3fa0d70097a48504e
   Content-Type: text/plain; charset=quot;utf8quot;
   Content-Transfer-Encoding: quoted-printable

   Hello Shahar,=0A=0A*Thank you* for registering to my new site. =0AYou are=
    welcome to log in at http://example.com/log-in=0A=0AThe example.com team!

   --=_96d67bd80a67ddc3fa0d70097a48504e
   Content-Type: text/html; charset=quot;utf8quot;
   Content-Transfer-Encoding: quoted-printable

   Hello Shahar,<br />=0A<br />=0A<strong>Thank you</strong> for registering=
    to my new site. <br />=0AYou are welcome to log in at <a href=3Dquot;http://e=
   xample.com/log-inquot;>http://example.com/log-in</a><br />=0A<br />=0AThe exam=
   ple.com team!

   --=_96d67bd80a67ddc3fa0d70097a48504e--




Shahar Evron | Zend Technologies                                            14
Zend_Mail

Attaching files
   // Load the Zend_Mail class
   require_once 'Zend/Mail.php';

   // Instantiate a new message object
   $message = new Zend_Mail('utf-8');

   // Use the fluent interface to set message properties
   $message->setFrom('spammer@example.com', 'Spammer Dude')
           ->setSubject('The report you have requested is ready')
           ->addTo('shahar@localhost', 'Shahar Evron');

   // Add a PDF attachment (Will be base64 encoded)
   $pdf = $message->createAttachment(file_get_contents('report.pdf'));
   $pdf->type     = 'application/pdf';
   $pdf->filename = 'report.pdf';

   // ... Continued on next slide ...




Shahar Evron | Zend Technologies                                    15
Zend_Mail

Attaching files (contd.)
   // Add a logo to the message - referenced from the message HTML body
   $img = $message->createAttachment(file_get_contents('logo.png'));
   $img->type        = 'image/png';
   $img->id          = 'logo-image-png@example.com';
   $img->filename    = 'logo.png';
   $img->disposition = Zend_Mime::DISPOSITION_INLINE;

   // Set the message body
   $message->setBodyHtml(
             quot;Hello Shahar,<br /><br />quot; .
             quot;The report you have requested is attached as a PDF file.<br /><br />quot; .
             quot;Enjoy!<br />quot; .
             '<img src=quot;cid:logo-image-png@example.comquot; alt=quot;Example.com Logoquot; />'
   );

   // Set the message MIME-type to multipart/related
   $message->setType(Zend_Mime::MULTIPART_RELATED);

   // Send the message!
   $message->send();




Shahar Evron | Zend Technologies                                  16
Zend_Mail




Shahar Evron | Zend Technologies   17
Zend_Mail

Sending multiple e-mails efficiently
     ○ Using the PHP mail() function is bad for multiple e-mails
     ○ On each mail you send, you:
           ▪ Fork a sendmail process
           ▪ sendmail will open a connection to the SMTP server, send the
             message and close the connection
           ▪ The sendmail process is then closed

     ○   This is why Zend_Mail provides the SMTP transport
           ▪ A full implementation of an SMTP client in PHP
           ▪ Allows you to open a connection once and reuse it to send several
             messages
           ▪ No forking is needed, does not depend on sendmail


Shahar Evron | Zend Technologies                            18
Zend_Mail

Sending multiple e-mails efficiently

   // Load the Zend_Mail and Zend_Mail_Transport_Smtp classes
   require_once 'Zend/Mail.php';
   require_once 'Zend/Mail/Transport/Smtp.php';

   // Set up a transport using smtp.example.com as SMTP server
   $smtpConn = new Zend_Mail_Transport_Smtp('smtp.example.com');

   // ... $msg1, $msg2 and $msg3 are Zend_Mail message objects

   // Send a bunch of e-mail messages
   $msg1->send($smtpConn);
   $msg2->send($smtpConn);
   $msg3->send($smtpConn);




Shahar Evron | Zend Technologies                  19
Zend_Db_Adapter
                          Zend_Db_Select




Shahar Evron | Zend Technologies       20
Zend_Db_Adapter and Zend_Db_Select

• Zend_Db_Adapter provides an abstract, vendor-
  agnostic RDBMS connection layer
     ○ Mostly similar in concept and in interface to PDO
     ○ Actually, it will usually use PDO under the hood
     ○ But can also use other PHP RDBMS client extensions
     ○ It also provides some convenience methods for escaping
       and running queries

• Zend_Db_Select provides even better vendor-
  independence by abstracting SELECT SQL queries
     ○   This means you (almost) don't have to write any SQL code!

Shahar Evron | Zend Technologies                  21
Zend_Db_Adapter

Connecting to a MySQL database using the factory method

   require_once 'Zend/Db.php';

   // Connecting to MySQL through MySQLi
   $config = array(
       'adapter' => 'MYSQLI',
       'hostname' => 'localhost',
       'dbname'   => 'wiki_db',
       'username' => 'wiki_db_user',
       'password' => 'xxxxxx'
   );

   // Use the factory method to connect to the DB
   $db = Zend_Db::factory($config['adapter'], $config);




Shahar Evron | Zend Technologies                  22
Zend_Db_Adapter

Connecting to an SQLite DB and inserting some data

   // Same connect method – but this time to SQLite 3.x
   $config = array(
       'adapter' => 'PDO_SQLITE',
       'dbname'   => 'var/data/dbfile.sq3'
   );

   $db = Zend_Db::factory($config['adapter'], $config);

   // Insert a new row to the articles table
   $db->insert('articles', array(
       'created_by' => (int) $user_id,
       'created_at' => $_SERVER['REQUEST_TIME'],
       'title'      => $_POST['title'],
       'content'    => $_POST['content']
   ));



Shahar Evron | Zend Technologies                     23
Zend_Db_Select

Fetching data from the DB using Zend_Db_Select

   // Create the SELECT query
   $select = $db->select()
                ->from('articles', array('id', 'title'))
                ->join('users', 'articles.author = users.id',
                    array('name', 'email'))
                ->where('links_to', 5)
                ->order('articles.title')
                ->limit(16);

   // Execute the query, return a result set object
   $results = $select->query();

   --- Produced SQL query: ---
   SELECT quot;articlesquot;.quot;idquot;, quot;articlesquot;.quot;titlequot;, quot;usersquot;.quot;namequot;,
   quot;usersquot;.quot;emailquot; FROM quot;articlesquot; INNER JOIN quot;usersquot; ON articles.author =
   users.id WHERE (links_to = 5) ORDER BY quot;articlesquot;.quot;titlequot; ASC LIMIT 16




Shahar Evron | Zend Technologies                         24
Zend_Config




Shahar Evron | Zend Technologies                 25
Zend_Config

• The purpose of Zend_Config is to allow easy
  management of and access to configuration data
• Several configuration storage formats are supported
     ○ Native PHP arrays
     ○ INI or XML files
     ○ Adding support for other formats is easy!

• Supports some cool features as well
     ○ Nesting configuration
     ○ Inheritance between configuration sections
     ○ Default values


Shahar Evron | Zend Technologies                    26
Zend_Config

Sample INI file used in next slide (config.ini)

   [ production ]
   debug = Off
   path.web.root = /
   path.web.host = example.com

   db.adapter     =   MYSQLI
   db.hostname    =   10.1.2.3
   db.username    =   produser
   db.password    =   xxxxxxxx
   db.dbname      =   wikidb

   [ development      : production ]
   debug = On
   path.web.host      = dev.example.com
   db.adapter =       PDO_SQLITE
   db.dbname   =      wikidb.sq3




Shahar Evron | Zend Technologies                  27
Zend_Config

Using Zend_Config_Ini to manage configuration data

   $env = getenv('MYAPP_ENVIRONMENT');
   if (! $env) $env = 'production';

   // Load configuration data from file
   $cfg = new Zend_Config_Ini('config.ini', $env);

   // Connect to DB using our configuration settings
   $db = Zend_Db::factory($cfg->db->adapter, $cfg->db->toArray());

   // Will always print '/' regardless of environment
   echo $cfg->path->web->root;

   // Will be true or false - depending on environment
   var_dump($cfg->debug);

   // Fetching with default value
   $hostname = $cfg->path->web->get('host', $_SERVER['HOST_NAME']);



Shahar Evron | Zend Technologies                         28
Zend_Http_Client




Shahar Evron | Zend Technologies             29
Zend_Http_Client

• A PHP-implemented HTTP client
     ○ Can be used to pass data around using HTTP
     ○ Serves as the basis for web-service client components in ZF

• Does not require any extensions (CURL, pecl_http)
• Does not require allow_url_fopen
• Supports some advanced HTTP features
     ○ Cookie persistence
     ○ File uploads
     ○ Proxy, authentication, HTTPS over proxy



Shahar Evron | Zend Technologies                 30
Zend_Http_Client

Reusing cookies over consecutive requests

   // Set up the client and enable cookie persistance
   $client = new Zend_Http_Client('https://www.example.com/user/login');
   $client->setCookieJar();

   // Set the login parameters
   $client->setParameterPost(array(
       'username' => 'shahar.e',
       'password' => 'xxxxxxxxx'
   ));

   // Send a POST request
   $response = $client->request(Zend_Http_Client::POST);

   // Send a GET request to fetch the restricted content
   $client->resetParameters();
   $client->setUri('http://www.example.com/restricted');
   $response = $client->request(Zend_Http_Client::GET);



Shahar Evron | Zend Technologies                           31
Zend_Http_Client

Sending files over HTTP using POST file upload

   // Set up the client and enable cookie persistance
   $client = new Zend_Http_Client('http://www.example.com/upload-photo');

   // Add a file from disk
   $client->setFileUpload('/home/shahar/photos/image1.jpg', 'photo1');

   // Add a file from buffer
   $client->setFileUpload('mock-file.jpg', 'photo2', $image_data,
       'image/jpg');

   // Send files
   $response = $client->request();

   // Files will be available on server-side PHP as
   // $_FILES['photo1'] and $_FILES['photo2']




Shahar Evron | Zend Technologies                         32
Zend_Service




Shahar Evron | Zend Technologies              33
Zend_Service

• Zend Framework aims to provide easy-to-use web
  service clients for many web service providers
     ○   Yahoo!
     ○   Flickr
     ○   AudioScrobbler
     ○   Amazon
     ○   ...and many others
• New service clients are added on every release
• There are also the Gdata and Infocard clients
• There are also generic REST and XMLRPC clients

Shahar Evron | Zend Technologies        34
Zend_Service




Shahar Evron | Zend Technologies   35
Zend_Service_Akismet

Checking a blog post comment for spam using Akismet

   require_once   'Zend/Service/Akismet.php';

   // Create the client object using the API key and blog URL
   // Get your API key from http://akismet.com/ (free for personal use)
   $akismet = new Zend_Service_Akismet($apiKey, 'http://example.com/blog');

   // Check a blog post comment for spam
   $commentData = array(
       'user_ip'         => $_SERVER['REMOTE_ADDR'],
       'user_agent'      => $_SERVER['HTTP_USER_AGENT'],
       'comment_type'    => 'trackback',
       'comment_author' => 'Honest Bender',
       'comment_email'   => 'fake123@hotmail.com',
       'comment_content' => quot;Free pr0n and cheap Rolex!quot;
   );
   if ($akismet->isSpam($commentData)) {
       echo quot;Die, Evil Spammer!!!quot;;
   } else {
       echo quot;Thanks for your comment!quot;;
   }




Shahar Evron | Zend Technologies                                  36
Zend_Service_Akismet

Reporting new spam or false positives to Akismet

   $commentData = array(
       'user_ip'                   =>   $_SERVER['REMOTE_ADDR'],
       'user_agent'                =>   $_SERVER['HTTP_USER_AGENT'],
       'comment_type'              =>   'trackback',
       'comment_author'            =>   'Honest Bender',
       'comment_email'             =>   'fake123@hotmail.com',
       'comment_content'           =>   quot;Free pr0n and cheap Rolex!quot;
   );

   // Report new spam to Akismet
   $akismet->submitSpam($commentData);

   // Report false positive (ham) to Akismet
   $akismet->submitHam($commentData);




Shahar Evron | Zend Technologies                              37
Zend_Json




Shahar Evron | Zend Technologies               38
Zend_Json

• Allows to easily encode PHP data as JSON* and vice
  versa

• Can encode / decode PHP scalars, arrays and
  objects

• Will utilize ext/json if available – if not, will use the
  written-from-scratch JSON encoder and decoder


* JavaScript Object Notation, http://www.json.org/

Shahar Evron | Zend Technologies                     39
Zend_Json

Encoding PHP to JSON

   require_once 'Zend/Json.php';

   $article = array(
       'title'     =>      'How to make a good script great',
       'author'    =>      'Some Guy',
       'published' =>      time(),
       'tags'      =>      array('howto', 'scripting', 'script', 'guide')
   );

   // Encode the PHP array
   echo Zend_Json::encode($article);


   --- Output ---
   {quot;titlequot;:quot;How to make a good script greatquot;,quot;authorquot;:quot;Some Guyquot;,
   quot;publishedquot;:1211837898,quot;tagsquot;:[quot;howtoquot;,quot;scriptingquot;,quot;scriptquot;,quot;guidequot;]}




Shahar Evron | Zend Technologies                              40
Zend_Json

Decoding JSON to PHP

   // Decode JSON. Will decode to an associative array by default
   $article = Zend_Json::decode($json);

   --- Output ---
   stdClass Object
   (
       [title] => How to make a good script great
       [author] => Some Guy
       [published] => 1211837898
       [tags] => Array
           (
               [0] => howto
               [1] => scripting
               [2] => script
               [3] => guide
           )
   )



Shahar Evron | Zend Technologies                         41
Zend_Json

Decoding JSON to PHP

   // Decode JSON to stdClass object
   $article = Zend_Json::decode($json, Zend_Json::TYPE_OBJECT);

   --- Output ---
   Array
   (
       [title] => How to make a good script great
       [author] => Some Guy
       [published] => 1211837898
       [tags] => Array
           (
               [0] => howto
               [1] => scripting
               [2] => script
               [3] => guide
           )
   )



Shahar Evron | Zend Technologies                         42
Zend_Log




Shahar Evron | Zend Technologies              43
Zend_Log

• Provides powerful yet easy to use logging capabilities
• Supports different “writers” - can write to several
  backends (at the same time even!)
• Uses a default set of error levels, you can add more
• You can apply filters when logging – this allows, for
  example, to dynamically change the logging level
• You can apply formatters on writers – this allows
  advanced message formatting - for example XML



Shahar Evron | Zend Technologies           44
Zend_Log




Shahar Evron | Zend Technologies   45
Zend_Log

Quick Start: Logging to standard output

   require_once 'Zend/Log.php';
   require_once 'Zend/Log/Writer/Stream.php';

   // Create a simple log that will write to STDOUT
   $log = new Zend_Log(new Zend_Log_Writer_Stream('php://stdout'));

   // Log a warning message
   $log->log('Something might be wrong', Zend_Log::WARN);

   // A simpler way to do the same thing
   $log->warn('Something might be wrong');

   Output:
   2008-05-27T01:15:56+03:00 WARN (4): Something might be wrong




Shahar Evron | Zend Technologies                            46
Zend_Log

• You can apply one or more Filter objects to both
     ○ The Log object – this will affect all writers
     ○ A particular Writer object – this will affect only one write

• Several filters exist, and you can easily create your
  own filter classes
• The most common method of filtering messages is by
  priority
     ○   This lets you control the logging verbosity level at run time,
         without changing your code



Shahar Evron | Zend Technologies                      47
Zend_Log

• Default priorities correlate to the syslog standards:
     ○   EMERG (0)
     ○   ALERT (1)
     ○   CRIT (2)
     ○   ERR (3)
     ○   WARN (4)
     ○   NOTICE (5)
     ○   INFO (6)
     ○   DEBUG (7)
• You can add your own if needed

Shahar Evron | Zend Technologies           48
Zend_Log

Filtering messages according to priority

   $log = new Zend_Log();

   // Log all messages to a debugging log
   $log->addWriter(new Zend_Log_Writer_Stream('debug.log'));

   // Log only important messages to STDERR
   $stdErr = new Zend_Log_Writer_Stream('php://stderr');
   $stdErr->addFilter(new Zend_Log_Filter_Priority(Zend_Log::WARN));
   $log->addWriter($stdErr);

   // Log an informational message - will only appear in debug.log
   $log->info('The application is starting up');

   // Log an error message - will appear in both logs
   $log->err('Something very bad has happened');




Shahar Evron | Zend Technologies                         49
Epilogue
Some more components worth looking at

• Zend_Pdf
• Zend_Search_Lucene
• Zend_Memory
• Zend_Auth
• Zend_Acl
• Zend_Console_Getopt
• I18N and L10N components
• ... and the MVC parts as well ;)

Shahar Evron | Zend Technologies     51
Got Questions?

• Questions?

• This presentation will be available at:
     ○ http://prematureoptimization.org/
     ○ Slideshare: http://www.slideshare.net/shahar


• Feedback and questions: shahar.e@zend.com




Shahar Evron | Zend Technologies                 52
Thank You!

Más contenido relacionado

La actualidad más candente

ADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyRiza Nurman
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewLibin Pan
 
Quick Intro To JRuby
Quick Intro To JRubyQuick Intro To JRuby
Quick Intro To JRubyFrederic Jean
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatternsChul Ju Hong
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-publicChul Ju Hong
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -ServletsGagandeep Singh
 
PHP on Windows and on Azure
PHP on Windows and on AzurePHP on Windows and on Azure
PHP on Windows and on AzureMaarten Balliauw
 
Introduction to Sightly
Introduction to SightlyIntroduction to Sightly
Introduction to SightlyAnkit Gubrani
 

La actualidad más candente (11)

ADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages TechnologyADP - Chapter 5 Exploring JavaServer Pages Technology
ADP - Chapter 5 Exploring JavaServer Pages Technology
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's New
 
Quick Intro To JRuby
Quick Intro To JRubyQuick Intro To JRuby
Quick Intro To JRuby
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Understanding JSP -Servlets
Understanding JSP -ServletsUnderstanding JSP -Servlets
Understanding JSP -Servlets
 
PHP on Windows and on Azure
PHP on Windows and on AzurePHP on Windows and on Azure
PHP on Windows and on Azure
 
Introduction to Sightly
Introduction to SightlyIntroduction to Sightly
Introduction to Sightly
 

Similar a Zend Framework components for non-framework PHP development

EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD ApplicationRob Tweed
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScriptDataArt
 
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD ApplicationRob Tweed
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using phpRishabh Srivastava
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web frameworktaggg
 
Zend Server: Not just a PHP stack
Zend Server: Not just a PHP stackZend Server: Not just a PHP stack
Zend Server: Not just a PHP stackJeroen van Dijk
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php SecurityDave Ross
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)James Titcumb
 
Building Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMSBuilding Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMSPivorak MeetUp
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)James Titcumb
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormMichelangelo van Dam
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)James Titcumb
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.jssouridatta
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统yiditushe
 
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)James Titcumb
 

Similar a Zend Framework components for non-framework PHP development (20)

EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScript
 
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using php
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
Zend Server: Not just a PHP stack
Zend Server: Not just a PHP stackZend Server: Not just a PHP stack
Zend Server: Not just a PHP stack
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
 
Building Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMSBuilding Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMS
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
 
Pecl Picks
Pecl PicksPecl Picks
Pecl Picks
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
HackU PHP and Node.js
HackU PHP and Node.jsHackU PHP and Node.js
HackU PHP and Node.js
 
Facebook的缓存系统
Facebook的缓存系统Facebook的缓存系统
Facebook的缓存系统
 
Write php deploy everywhere tek11
Write php deploy everywhere   tek11Write php deploy everywhere   tek11
Write php deploy everywhere tek11
 
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
 

Más de Shahar Evron

Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentShahar Evron
 
Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkShahar Evron
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on WindowsShahar Evron
 
Zend Server: A Guided Tour
Zend Server: A Guided TourZend Server: A Guided Tour
Zend Server: A Guided TourShahar Evron
 
Zend Server: Scalability & Performance
Zend Server: Scalability & PerformanceZend Server: Scalability & Performance
Zend Server: Scalability & PerformanceShahar Evron
 
Scaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformScaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformShahar Evron
 
PHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניPHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניShahar Evron
 
PHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןPHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןShahar Evron
 
PHP - עבר הווה ועתיד
PHP - עבר הווה ועתידPHP - עבר הווה ועתיד
PHP - עבר הווה ועתידShahar Evron
 
Content Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneContent Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneShahar Evron
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development EnvironmentsShahar Evron
 

Más de Shahar Evron (12)

Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend Framework
 
PHP and Zend Framework on Windows
PHP and Zend Framework on WindowsPHP and Zend Framework on Windows
PHP and Zend Framework on Windows
 
Zend Server: A Guided Tour
Zend Server: A Guided TourZend Server: A Guided Tour
Zend Server: A Guided Tour
 
Zend Server: Scalability & Performance
Zend Server: Scalability & PerformanceZend Server: Scalability & Performance
Zend Server: Scalability & Performance
 
Intro To Couch Db
Intro To Couch DbIntro To Couch Db
Intro To Couch Db
 
Scaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend PlatformScaling PHP Applications with Zend Platform
Scaling PHP Applications with Zend Platform
 
PHP ואבטחה - חלק שני
PHP ואבטחה - חלק שניPHP ואבטחה - חלק שני
PHP ואבטחה - חלק שני
 
PHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשוןPHP ואבטחה - חלק ראשון
PHP ואבטחה - חלק ראשון
 
PHP - עבר הווה ועתיד
PHP - עבר הווה ועתידPHP - עבר הווה ועתיד
PHP - עבר הווה ועתיד
 
Content Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_LuceneContent Indexing with Zend_Search_Lucene
Content Indexing with Zend_Search_Lucene
 
Building Scalable Development Environments
Building Scalable Development EnvironmentsBuilding Scalable Development Environments
Building Scalable Development Environments
 

Último

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Último (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

Zend Framework components for non-framework PHP development

  • 1. Shahar Evron | Zend Technologies Zend Framework Components ...for non-framework development
  • 2. Agenda • Zend Framework's „Use At Will“ approach • So why would I want to use Zend Framework? • Show Us The Code! (the interesting part) ○ Zend_Mail ○ Zend_Db ○ Zend_Config ○ Zend_Http_Client ○ Zend_Service ○ Zend_Json ○ Zend_Log • Some other things worth looking at Shahar Evron | Zend Technologies 2
  • 3. Prologue • Who Are You? ○ PHP Programmers / Users? ○ Using Zend Framework? ○ Using other PHP Frameworks? ○ Using PEAR classes in your code? ○ Tend to reuse other people's code? Shahar Evron | Zend Technologies 3
  • 4. Prologue • Who am I? ○ Programming in PHP for ~6 years ○ Working for Zend for the last 3 years ▪ Services, Product Management ○ Part-time contributor to ZF ▪ Not a part of my actual job ;-) ○ If you have a hard time with my name: ▪ German: Shachar ▪ Spanish: Shajar ▪ Russian: Шахар ▪ Arabic: ‫ﺷﺨﺮ‬ ▪ Hebrew: ‫שחר‬ ַ ָ Shahar Evron | Zend Technologies 4
  • 6. Fire At Will! • Zend Framework embraces a use-at-will philosophy • In practice, this means we try to have little or no dependencies between components ○ You don't have to use the entire framework ○ You don't have to build your application in a particular way ○ ...But if you want to, you can! • There are some components (mostly the MVC stuff) that have loose bindings to other components • Many components have very little dependencies, and can simply be included and used in any application Shahar Evron | Zend Technologies 6
  • 7. Ooohh... Pretty Colors! Shahar Evron | Zend Technologies 7
  • 8. If No Framework, Why Zend Framework? • Because it's high quality ○ Strict standards from day one ○ Unit Tested (80%+ code coverage) ○ Used and reviewed by a large community of users • Because it's clean IP and friendly licensed • Because it's there! ○ Well, it's one good option – you have others of course ;) Shahar Evron | Zend Technologies 8
  • 9. Ok, we get it, Now show us the Code!
  • 10. Zend_Mail Shahar Evron | Zend Technologies 10
  • 11. Zend_Mail • Allows you to easily compose and send e-mail messages from your PHP applications • Simplified control over recipients, headers, etc. • Easy creation of multipart/alternative HTML messages • Easy attachment handling • Supports different delivery transports • Allows you to read e-mail messages from POP3, IMAP, Mbox and Maildir (not discussed here) Shahar Evron | Zend Technologies 11
  • 12. Zend_Mail Sending a simple message through Zend_Mail: // Load the Zend_Mail class require_once 'Zend/Mail.php'; // Instantiate a new message object $message = new Zend_Mail('utf-8'); // Use the fluent interface to set message properties $message->setFrom('shahar.e@zend.com', 'Shahar E') ->setSubject('Hello, world!') ->setBodyText(quot;Hi, what's up?quot;) ->addHeader('Importance', 'high') ->addTo('someone@example.com', 'Some One') ->addCc('other.guy@example.com', 'Other Guy') ->addBcc('t.person@example.com', 'The Third Person'); // Send the message! $message->send(); Shahar Evron | Zend Technologies 12
  • 13. Zend_Mail Creating multipart/alternative messages // ...Load the Zend_Mail and prepare the message object as before... $text = <<<WELCOME_MSG Hello Shahar, *Thank you* for registering to my new site. You are welcome to log in at http://example.com/log-in The example.com team! WELCOME_MSG; // Set the plain text and HTML body parts $message->setBodyText($text); $message->setBodyHtml(nl2br(preg_replace( array('/*(.+?)*/', '|https?://S+|'), array('<strong>1</strong>', '<a href=quot;0quot;>0</a>'), $text))); // Send the message! $message->send(); Shahar Evron | Zend Technologies 13
  • 14. Zend_Mail Creating multipart/alternative messages - result: Subject: Hello, world! From: quot;Shahar Equot; <shahar.e@zend.com> Importance: high Content-Type: multipart/alternative; charset=quot;utf8quot;; boundary=quot;=_96d67bd80a67ddc3fa0d70097a48504equot; MIME-Version: 1.0 --=_96d67bd80a67ddc3fa0d70097a48504e Content-Type: text/plain; charset=quot;utf8quot; Content-Transfer-Encoding: quoted-printable Hello Shahar,=0A=0A*Thank you* for registering to my new site. =0AYou are= welcome to log in at http://example.com/log-in=0A=0AThe example.com team! --=_96d67bd80a67ddc3fa0d70097a48504e Content-Type: text/html; charset=quot;utf8quot; Content-Transfer-Encoding: quoted-printable Hello Shahar,<br />=0A<br />=0A<strong>Thank you</strong> for registering= to my new site. <br />=0AYou are welcome to log in at <a href=3Dquot;http://e= xample.com/log-inquot;>http://example.com/log-in</a><br />=0A<br />=0AThe exam= ple.com team! --=_96d67bd80a67ddc3fa0d70097a48504e-- Shahar Evron | Zend Technologies 14
  • 15. Zend_Mail Attaching files // Load the Zend_Mail class require_once 'Zend/Mail.php'; // Instantiate a new message object $message = new Zend_Mail('utf-8'); // Use the fluent interface to set message properties $message->setFrom('spammer@example.com', 'Spammer Dude') ->setSubject('The report you have requested is ready') ->addTo('shahar@localhost', 'Shahar Evron'); // Add a PDF attachment (Will be base64 encoded) $pdf = $message->createAttachment(file_get_contents('report.pdf')); $pdf->type = 'application/pdf'; $pdf->filename = 'report.pdf'; // ... Continued on next slide ... Shahar Evron | Zend Technologies 15
  • 16. Zend_Mail Attaching files (contd.) // Add a logo to the message - referenced from the message HTML body $img = $message->createAttachment(file_get_contents('logo.png')); $img->type = 'image/png'; $img->id = 'logo-image-png@example.com'; $img->filename = 'logo.png'; $img->disposition = Zend_Mime::DISPOSITION_INLINE; // Set the message body $message->setBodyHtml( quot;Hello Shahar,<br /><br />quot; . quot;The report you have requested is attached as a PDF file.<br /><br />quot; . quot;Enjoy!<br />quot; . '<img src=quot;cid:logo-image-png@example.comquot; alt=quot;Example.com Logoquot; />' ); // Set the message MIME-type to multipart/related $message->setType(Zend_Mime::MULTIPART_RELATED); // Send the message! $message->send(); Shahar Evron | Zend Technologies 16
  • 17. Zend_Mail Shahar Evron | Zend Technologies 17
  • 18. Zend_Mail Sending multiple e-mails efficiently ○ Using the PHP mail() function is bad for multiple e-mails ○ On each mail you send, you: ▪ Fork a sendmail process ▪ sendmail will open a connection to the SMTP server, send the message and close the connection ▪ The sendmail process is then closed ○ This is why Zend_Mail provides the SMTP transport ▪ A full implementation of an SMTP client in PHP ▪ Allows you to open a connection once and reuse it to send several messages ▪ No forking is needed, does not depend on sendmail Shahar Evron | Zend Technologies 18
  • 19. Zend_Mail Sending multiple e-mails efficiently // Load the Zend_Mail and Zend_Mail_Transport_Smtp classes require_once 'Zend/Mail.php'; require_once 'Zend/Mail/Transport/Smtp.php'; // Set up a transport using smtp.example.com as SMTP server $smtpConn = new Zend_Mail_Transport_Smtp('smtp.example.com'); // ... $msg1, $msg2 and $msg3 are Zend_Mail message objects // Send a bunch of e-mail messages $msg1->send($smtpConn); $msg2->send($smtpConn); $msg3->send($smtpConn); Shahar Evron | Zend Technologies 19
  • 20. Zend_Db_Adapter Zend_Db_Select Shahar Evron | Zend Technologies 20
  • 21. Zend_Db_Adapter and Zend_Db_Select • Zend_Db_Adapter provides an abstract, vendor- agnostic RDBMS connection layer ○ Mostly similar in concept and in interface to PDO ○ Actually, it will usually use PDO under the hood ○ But can also use other PHP RDBMS client extensions ○ It also provides some convenience methods for escaping and running queries • Zend_Db_Select provides even better vendor- independence by abstracting SELECT SQL queries ○ This means you (almost) don't have to write any SQL code! Shahar Evron | Zend Technologies 21
  • 22. Zend_Db_Adapter Connecting to a MySQL database using the factory method require_once 'Zend/Db.php'; // Connecting to MySQL through MySQLi $config = array( 'adapter' => 'MYSQLI', 'hostname' => 'localhost', 'dbname' => 'wiki_db', 'username' => 'wiki_db_user', 'password' => 'xxxxxx' ); // Use the factory method to connect to the DB $db = Zend_Db::factory($config['adapter'], $config); Shahar Evron | Zend Technologies 22
  • 23. Zend_Db_Adapter Connecting to an SQLite DB and inserting some data // Same connect method – but this time to SQLite 3.x $config = array( 'adapter' => 'PDO_SQLITE', 'dbname' => 'var/data/dbfile.sq3' ); $db = Zend_Db::factory($config['adapter'], $config); // Insert a new row to the articles table $db->insert('articles', array( 'created_by' => (int) $user_id, 'created_at' => $_SERVER['REQUEST_TIME'], 'title' => $_POST['title'], 'content' => $_POST['content'] )); Shahar Evron | Zend Technologies 23
  • 24. Zend_Db_Select Fetching data from the DB using Zend_Db_Select // Create the SELECT query $select = $db->select() ->from('articles', array('id', 'title')) ->join('users', 'articles.author = users.id', array('name', 'email')) ->where('links_to', 5) ->order('articles.title') ->limit(16); // Execute the query, return a result set object $results = $select->query(); --- Produced SQL query: --- SELECT quot;articlesquot;.quot;idquot;, quot;articlesquot;.quot;titlequot;, quot;usersquot;.quot;namequot;, quot;usersquot;.quot;emailquot; FROM quot;articlesquot; INNER JOIN quot;usersquot; ON articles.author = users.id WHERE (links_to = 5) ORDER BY quot;articlesquot;.quot;titlequot; ASC LIMIT 16 Shahar Evron | Zend Technologies 24
  • 25. Zend_Config Shahar Evron | Zend Technologies 25
  • 26. Zend_Config • The purpose of Zend_Config is to allow easy management of and access to configuration data • Several configuration storage formats are supported ○ Native PHP arrays ○ INI or XML files ○ Adding support for other formats is easy! • Supports some cool features as well ○ Nesting configuration ○ Inheritance between configuration sections ○ Default values Shahar Evron | Zend Technologies 26
  • 27. Zend_Config Sample INI file used in next slide (config.ini) [ production ] debug = Off path.web.root = / path.web.host = example.com db.adapter = MYSQLI db.hostname = 10.1.2.3 db.username = produser db.password = xxxxxxxx db.dbname = wikidb [ development : production ] debug = On path.web.host = dev.example.com db.adapter = PDO_SQLITE db.dbname = wikidb.sq3 Shahar Evron | Zend Technologies 27
  • 28. Zend_Config Using Zend_Config_Ini to manage configuration data $env = getenv('MYAPP_ENVIRONMENT'); if (! $env) $env = 'production'; // Load configuration data from file $cfg = new Zend_Config_Ini('config.ini', $env); // Connect to DB using our configuration settings $db = Zend_Db::factory($cfg->db->adapter, $cfg->db->toArray()); // Will always print '/' regardless of environment echo $cfg->path->web->root; // Will be true or false - depending on environment var_dump($cfg->debug); // Fetching with default value $hostname = $cfg->path->web->get('host', $_SERVER['HOST_NAME']); Shahar Evron | Zend Technologies 28
  • 29. Zend_Http_Client Shahar Evron | Zend Technologies 29
  • 30. Zend_Http_Client • A PHP-implemented HTTP client ○ Can be used to pass data around using HTTP ○ Serves as the basis for web-service client components in ZF • Does not require any extensions (CURL, pecl_http) • Does not require allow_url_fopen • Supports some advanced HTTP features ○ Cookie persistence ○ File uploads ○ Proxy, authentication, HTTPS over proxy Shahar Evron | Zend Technologies 30
  • 31. Zend_Http_Client Reusing cookies over consecutive requests // Set up the client and enable cookie persistance $client = new Zend_Http_Client('https://www.example.com/user/login'); $client->setCookieJar(); // Set the login parameters $client->setParameterPost(array( 'username' => 'shahar.e', 'password' => 'xxxxxxxxx' )); // Send a POST request $response = $client->request(Zend_Http_Client::POST); // Send a GET request to fetch the restricted content $client->resetParameters(); $client->setUri('http://www.example.com/restricted'); $response = $client->request(Zend_Http_Client::GET); Shahar Evron | Zend Technologies 31
  • 32. Zend_Http_Client Sending files over HTTP using POST file upload // Set up the client and enable cookie persistance $client = new Zend_Http_Client('http://www.example.com/upload-photo'); // Add a file from disk $client->setFileUpload('/home/shahar/photos/image1.jpg', 'photo1'); // Add a file from buffer $client->setFileUpload('mock-file.jpg', 'photo2', $image_data, 'image/jpg'); // Send files $response = $client->request(); // Files will be available on server-side PHP as // $_FILES['photo1'] and $_FILES['photo2'] Shahar Evron | Zend Technologies 32
  • 33. Zend_Service Shahar Evron | Zend Technologies 33
  • 34. Zend_Service • Zend Framework aims to provide easy-to-use web service clients for many web service providers ○ Yahoo! ○ Flickr ○ AudioScrobbler ○ Amazon ○ ...and many others • New service clients are added on every release • There are also the Gdata and Infocard clients • There are also generic REST and XMLRPC clients Shahar Evron | Zend Technologies 34
  • 35. Zend_Service Shahar Evron | Zend Technologies 35
  • 36. Zend_Service_Akismet Checking a blog post comment for spam using Akismet require_once 'Zend/Service/Akismet.php'; // Create the client object using the API key and blog URL // Get your API key from http://akismet.com/ (free for personal use) $akismet = new Zend_Service_Akismet($apiKey, 'http://example.com/blog'); // Check a blog post comment for spam $commentData = array( 'user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'comment_type' => 'trackback', 'comment_author' => 'Honest Bender', 'comment_email' => 'fake123@hotmail.com', 'comment_content' => quot;Free pr0n and cheap Rolex!quot; ); if ($akismet->isSpam($commentData)) { echo quot;Die, Evil Spammer!!!quot;; } else { echo quot;Thanks for your comment!quot;; } Shahar Evron | Zend Technologies 36
  • 37. Zend_Service_Akismet Reporting new spam or false positives to Akismet $commentData = array( 'user_ip' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'comment_type' => 'trackback', 'comment_author' => 'Honest Bender', 'comment_email' => 'fake123@hotmail.com', 'comment_content' => quot;Free pr0n and cheap Rolex!quot; ); // Report new spam to Akismet $akismet->submitSpam($commentData); // Report false positive (ham) to Akismet $akismet->submitHam($commentData); Shahar Evron | Zend Technologies 37
  • 38. Zend_Json Shahar Evron | Zend Technologies 38
  • 39. Zend_Json • Allows to easily encode PHP data as JSON* and vice versa • Can encode / decode PHP scalars, arrays and objects • Will utilize ext/json if available – if not, will use the written-from-scratch JSON encoder and decoder * JavaScript Object Notation, http://www.json.org/ Shahar Evron | Zend Technologies 39
  • 40. Zend_Json Encoding PHP to JSON require_once 'Zend/Json.php'; $article = array( 'title' => 'How to make a good script great', 'author' => 'Some Guy', 'published' => time(), 'tags' => array('howto', 'scripting', 'script', 'guide') ); // Encode the PHP array echo Zend_Json::encode($article); --- Output --- {quot;titlequot;:quot;How to make a good script greatquot;,quot;authorquot;:quot;Some Guyquot;, quot;publishedquot;:1211837898,quot;tagsquot;:[quot;howtoquot;,quot;scriptingquot;,quot;scriptquot;,quot;guidequot;]} Shahar Evron | Zend Technologies 40
  • 41. Zend_Json Decoding JSON to PHP // Decode JSON. Will decode to an associative array by default $article = Zend_Json::decode($json); --- Output --- stdClass Object ( [title] => How to make a good script great [author] => Some Guy [published] => 1211837898 [tags] => Array ( [0] => howto [1] => scripting [2] => script [3] => guide ) ) Shahar Evron | Zend Technologies 41
  • 42. Zend_Json Decoding JSON to PHP // Decode JSON to stdClass object $article = Zend_Json::decode($json, Zend_Json::TYPE_OBJECT); --- Output --- Array ( [title] => How to make a good script great [author] => Some Guy [published] => 1211837898 [tags] => Array ( [0] => howto [1] => scripting [2] => script [3] => guide ) ) Shahar Evron | Zend Technologies 42
  • 43. Zend_Log Shahar Evron | Zend Technologies 43
  • 44. Zend_Log • Provides powerful yet easy to use logging capabilities • Supports different “writers” - can write to several backends (at the same time even!) • Uses a default set of error levels, you can add more • You can apply filters when logging – this allows, for example, to dynamically change the logging level • You can apply formatters on writers – this allows advanced message formatting - for example XML Shahar Evron | Zend Technologies 44
  • 45. Zend_Log Shahar Evron | Zend Technologies 45
  • 46. Zend_Log Quick Start: Logging to standard output require_once 'Zend/Log.php'; require_once 'Zend/Log/Writer/Stream.php'; // Create a simple log that will write to STDOUT $log = new Zend_Log(new Zend_Log_Writer_Stream('php://stdout')); // Log a warning message $log->log('Something might be wrong', Zend_Log::WARN); // A simpler way to do the same thing $log->warn('Something might be wrong'); Output: 2008-05-27T01:15:56+03:00 WARN (4): Something might be wrong Shahar Evron | Zend Technologies 46
  • 47. Zend_Log • You can apply one or more Filter objects to both ○ The Log object – this will affect all writers ○ A particular Writer object – this will affect only one write • Several filters exist, and you can easily create your own filter classes • The most common method of filtering messages is by priority ○ This lets you control the logging verbosity level at run time, without changing your code Shahar Evron | Zend Technologies 47
  • 48. Zend_Log • Default priorities correlate to the syslog standards: ○ EMERG (0) ○ ALERT (1) ○ CRIT (2) ○ ERR (3) ○ WARN (4) ○ NOTICE (5) ○ INFO (6) ○ DEBUG (7) • You can add your own if needed Shahar Evron | Zend Technologies 48
  • 49. Zend_Log Filtering messages according to priority $log = new Zend_Log(); // Log all messages to a debugging log $log->addWriter(new Zend_Log_Writer_Stream('debug.log')); // Log only important messages to STDERR $stdErr = new Zend_Log_Writer_Stream('php://stderr'); $stdErr->addFilter(new Zend_Log_Filter_Priority(Zend_Log::WARN)); $log->addWriter($stdErr); // Log an informational message - will only appear in debug.log $log->info('The application is starting up'); // Log an error message - will appear in both logs $log->err('Something very bad has happened'); Shahar Evron | Zend Technologies 49
  • 51. Some more components worth looking at • Zend_Pdf • Zend_Search_Lucene • Zend_Memory • Zend_Auth • Zend_Acl • Zend_Console_Getopt • I18N and L10N components • ... and the MVC parts as well ;) Shahar Evron | Zend Technologies 51
  • 52. Got Questions? • Questions? • This presentation will be available at: ○ http://prematureoptimization.org/ ○ Slideshare: http://www.slideshare.net/shahar • Feedback and questions: shahar.e@zend.com Shahar Evron | Zend Technologies 52