SlideShare una empresa de Scribd logo
1 de 19
Intercepting Filters Design
          Pattern
Overview
Objective

Learn how to use the intercepting filter design pattern.

Requirements

Array
Extending an Object
Estimated Time

10 minutes


                       www.prodigyview.com
Follow Along With Code
           Example
1. Download a copy of the example code at
  www.prodigyview.com/source.

2. Install the system in an environment you feel
  comfortable testing in.

3. Proceed to examples/design/Filters.php
What are Filters?
Intercepting Filters is a design pattern that wraps execution
and intercepts the transmissions and/or request of
response. Intercepting filters can be stacked in a chain and
alter execution without changing the source code.

A simpler explanation would be modifying the data that is
passed into or returned from a method. This may also
possibly affect the execution of that method without directly
altering the source code.
Intercepting Filters Visual
MyObject::doSomething($mydata);




                                                                         My Filter Object
                        Filter passes data to another object to filter
    Filter is reached
                                                                           Filter Data
       Continue
       Execution




        Output
PVPatterns and
                PVStaticPatterns
The classes that contain the functions for using filters is the
PVPatterns and PVStaticPatterns classes.

PVPatterns is for instances and PVStaticPatterns is for static
methods.

Both PVObject and PVStaticObject extend the pattern classes.
Vending Machine Example
       We are going to start off with a vending machine example.
       Our VendingMachine extends PVObject. PVObject
       extends PVPatterns which has the filter methods we
       need.

Extending PVObject


Compile the data to
filter




Make the method
filterable by adding
the filters
Adding A Filter
      If you noticed in our filter class, we had an explicit section
      where the filters are were defined.
           Checks if there is a filter for this class and this method




Apply the filter for this class and this method        Executes only if the event type has been set



     Filters are suppose to be tied to a specific function in a specific class. We can simply
     use get_class and __Function__ to get the current class and function. The method
     _hasFitler first determines if they method has any filters. If true, lets execute them.

     The function has two different filters because there are two different events being
     performed, a check and a selection. The filter is being applied by passing in the class
     name, the function name, the data to be filtered, and options. Keep in mind that the
     filter can only filter one piece of data.
Item Check
      Now for our vending we have items like beer which need to
      be checked before buying. Lets add in a class that handles
      that.
                                         Options passed about the filter
  Data passed from the filter




Return the data
Item Chooser
    Soda sounds generic. What kind of soda? Next we are
    going to add a class to handle what kind of item we are
    picking.
                                                     Options passed
Data passed from                                     about the filter
the filter




  Return the data
Vend! Round 1
So we have our vending machine set up. Lets run the
function with some data and look at the results. Remember
the parameters was item, money and age.
Round 1 Results




Oh man, that’s not good. We are having minors getting
beer and anyone putting any price and getting what they
want. And all the items are generic! Let’s fix this.
Round 2- Add Some filters
      So let’s add some filters in. The first two arguments is the
      class and method to tie the filter too. The second two
      arguments is the class and method that will do the filtering.
      The last in the options in which you can tie the filter being
      called to a particular event. Let’s give this a try.

                                                                                Filter works only on
The class to attach the filter to     The method to filter                      this event




The class that will filter the data         The method in the class to filter the data
Round 2 Results




Ok a little better, at least we are getting some none generic
items back. But we still need to verify the age and amount
tendered.
Round 3 – Verification Filters
Now we are going to add the last set filters on, the same
way we added the previous filters.




                         Calls an instance
Round 3 Result



Finally, the results we need. So that is filters in a nutshell.
We modified the data in the method without ever modifying
the method.
Challenge!
Below is an optional challenge designed to help you gain a
better understanding of the design pattern.
1. Create 3 classes with 2 methods each. Make sure
   each method accepts 2 parameters and has at least
   one filter.
2. Attach a filter to each method that filters out by calling a
   filter from another class.
3. Design the filters in a way THAT DOES NOT CAUSE
   AN INFINITE LOOP.
4. Execute code.
Summary
1. Apply a filter using the _applyFilter method. The name
   of the class and the name of the function calling the
   filter should be used. The function only accepts 1
   parameter for data to be filters.

2. Add a filter before execution using the _addFilter
   method. Specify the class and method to be filter and
   the class and method to run the filter through.
API Reference
For a better understanding of the Collections and the
Iterator, check out the api at the two links below.

PVStaticPatterns

PVPatterns



                     More Tutorials
For more tutorials, please visit:
http://www.prodigyview.com/tutorials



                         www.prodigyview.com

Más contenido relacionado

Similar a Intercepting Filters Design Pattern

Webinar: Inquiry and watch your data in a smart way with SpagoBI
Webinar: Inquiry and watch your data in a smart way with SpagoBIWebinar: Inquiry and watch your data in a smart way with SpagoBI
Webinar: Inquiry and watch your data in a smart way with SpagoBISpagoWorld
 
ASP.NET MVC controllers
ASP.NET MVC controllersASP.NET MVC controllers
ASP.NET MVC controllersMahmoud Tolba
 
Sumo Logic QuickStart Webinar - Get Certified
Sumo Logic QuickStart Webinar - Get CertifiedSumo Logic QuickStart Webinar - Get Certified
Sumo Logic QuickStart Webinar - Get CertifiedSumo Logic
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9aminmesbahi
 
Sumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - FundamentalsSumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - FundamentalsSumo Logic
 
Custom Validation PHP
Custom Validation PHPCustom Validation PHP
Custom Validation PHPProdigyView
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문Sangcheol Hwang
 
IT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNGIT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNGDataArt
 
Understanding Mahout classification documentation
Understanding Mahout  classification documentationUnderstanding Mahout  classification documentation
Understanding Mahout classification documentationNaveen Kumar
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design PatternProdigyView
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 
types of testing with descriptions and examples
types of testing with descriptions and examplestypes of testing with descriptions and examples
types of testing with descriptions and examplesMani Deepak Choudhry
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
Java - Basic Concepts
Java - Basic ConceptsJava - Basic Concepts
Java - Basic ConceptsVicter Paul
 
Soft And Handling
Soft And HandlingSoft And Handling
Soft And Handlinghiratufail
 
Pycon2015 scope
Pycon2015 scopePycon2015 scope
Pycon2015 scopearthi v
 

Similar a Intercepting Filters Design Pattern (20)

Webinar: Inquiry and watch your data in a smart way with SpagoBI
Webinar: Inquiry and watch your data in a smart way with SpagoBIWebinar: Inquiry and watch your data in a smart way with SpagoBI
Webinar: Inquiry and watch your data in a smart way with SpagoBI
 
ASP.NET MVC controllers
ASP.NET MVC controllersASP.NET MVC controllers
ASP.NET MVC controllers
 
Sumo Logic QuickStart Webinar - Get Certified
Sumo Logic QuickStart Webinar - Get CertifiedSumo Logic QuickStart Webinar - Get Certified
Sumo Logic QuickStart Webinar - Get Certified
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9
 
Sumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - FundamentalsSumo Logic Cert Jam - Fundamentals
Sumo Logic Cert Jam - Fundamentals
 
Custom Validation PHP
Custom Validation PHPCustom Validation PHP
Custom Validation PHP
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문
 
IT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNGIT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNG
 
Understanding Mahout classification documentation
Understanding Mahout  classification documentationUnderstanding Mahout  classification documentation
Understanding Mahout classification documentation
 
WEKA: The Explorer
WEKA: The ExplorerWEKA: The Explorer
WEKA: The Explorer
 
WEKA:The Explorer
WEKA:The ExplorerWEKA:The Explorer
WEKA:The Explorer
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design Pattern
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
types of testing with descriptions and examples
types of testing with descriptions and examplestypes of testing with descriptions and examples
types of testing with descriptions and examples
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
Java - Basic Concepts
Java - Basic ConceptsJava - Basic Concepts
Java - Basic Concepts
 
Soft And Handling
Soft And HandlingSoft And Handling
Soft And Handling
 
Pycon2015 scope
Pycon2015 scopePycon2015 scope
Pycon2015 scope
 
Magento Meetup New Delhi- Magento2 plugins
Magento Meetup New Delhi- Magento2 pluginsMagento Meetup New Delhi- Magento2 plugins
Magento Meetup New Delhi- Magento2 plugins
 

Más de ProdigyView

Installing Plug-ins
Installing Plug-insInstalling Plug-ins
Installing Plug-insProdigyView
 
Building An Application
Building An ApplicationBuilding An Application
Building An ApplicationProdigyView
 
Installing Applications
Installing ApplicationsInstalling Applications
Installing ApplicationsProdigyView
 
Video Content Management
Video Content ManagementVideo Content Management
Video Content ManagementProdigyView
 
Audio Content Management
Audio Content ManagementAudio Content Management
Audio Content ManagementProdigyView
 
File Content Management
File Content ManagementFile Content Management
File Content ManagementProdigyView
 
Email Configuration
Email ConfigurationEmail Configuration
Email ConfigurationProdigyView
 
HTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialHTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialProdigyView
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms TutorialProdigyView
 
Html Tags Tutorial
Html Tags TutorialHtml Tags Tutorial
Html Tags TutorialProdigyView
 
Video Conversion PHP
Video Conversion PHPVideo Conversion PHP
Video Conversion PHPProdigyView
 
Sending Email Basics PHP
Sending Email Basics PHPSending Email Basics PHP
Sending Email Basics PHPProdigyView
 
Tools ProdigyView
Tools ProdigyViewTools ProdigyView
Tools ProdigyViewProdigyView
 
Basic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPBasic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPProdigyView
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web CacheProdigyView
 
Javascript And CSS Libraries
Javascript And CSS LibrariesJavascript And CSS Libraries
Javascript And CSS LibrariesProdigyView
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements TutorialProdigyView
 
Creating Dynamic Objects PHP
Creating Dynamic Objects PHPCreating Dynamic Objects PHP
Creating Dynamic Objects PHPProdigyView
 

Más de ProdigyView (20)

Installing Plug-ins
Installing Plug-insInstalling Plug-ins
Installing Plug-ins
 
Building An Application
Building An ApplicationBuilding An Application
Building An Application
 
Installing Applications
Installing ApplicationsInstalling Applications
Installing Applications
 
Video Content Management
Video Content ManagementVideo Content Management
Video Content Management
 
Audio Content Management
Audio Content ManagementAudio Content Management
Audio Content Management
 
File Content Management
File Content ManagementFile Content Management
File Content Management
 
Email Configuration
Email ConfigurationEmail Configuration
Email Configuration
 
HTML5 Tags and Elements Tutorial
HTML5 Tags and Elements TutorialHTML5 Tags and Elements Tutorial
HTML5 Tags and Elements Tutorial
 
HTML Forms Tutorial
HTML Forms TutorialHTML Forms Tutorial
HTML Forms Tutorial
 
Html Tags Tutorial
Html Tags TutorialHtml Tags Tutorial
Html Tags Tutorial
 
Video Conversion PHP
Video Conversion PHPVideo Conversion PHP
Video Conversion PHP
 
Sending Email Basics PHP
Sending Email Basics PHPSending Email Basics PHP
Sending Email Basics PHP
 
Tools ProdigyView
Tools ProdigyViewTools ProdigyView
Tools ProdigyView
 
Basic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHPBasic File Cache Tutorial - PHP
Basic File Cache Tutorial - PHP
 
Understanding Web Cache
Understanding Web CacheUnderstanding Web Cache
Understanding Web Cache
 
Javascript And CSS Libraries
Javascript And CSS LibrariesJavascript And CSS Libraries
Javascript And CSS Libraries
 
PHP Libraries
PHP LibrariesPHP Libraries
PHP Libraries
 
SQL Prepared Statements Tutorial
SQL Prepared Statements TutorialSQL Prepared Statements Tutorial
SQL Prepared Statements Tutorial
 
Database Basics
Database BasicsDatabase Basics
Database Basics
 
Creating Dynamic Objects PHP
Creating Dynamic Objects PHPCreating Dynamic Objects PHP
Creating Dynamic Objects PHP
 

Último

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Intercepting Filters Design Pattern

  • 2. Overview Objective Learn how to use the intercepting filter design pattern. Requirements Array Extending an Object Estimated Time 10 minutes www.prodigyview.com
  • 3. Follow Along With Code Example 1. Download a copy of the example code at www.prodigyview.com/source. 2. Install the system in an environment you feel comfortable testing in. 3. Proceed to examples/design/Filters.php
  • 4. What are Filters? Intercepting Filters is a design pattern that wraps execution and intercepts the transmissions and/or request of response. Intercepting filters can be stacked in a chain and alter execution without changing the source code. A simpler explanation would be modifying the data that is passed into or returned from a method. This may also possibly affect the execution of that method without directly altering the source code.
  • 5. Intercepting Filters Visual MyObject::doSomething($mydata); My Filter Object Filter passes data to another object to filter Filter is reached Filter Data Continue Execution Output
  • 6. PVPatterns and PVStaticPatterns The classes that contain the functions for using filters is the PVPatterns and PVStaticPatterns classes. PVPatterns is for instances and PVStaticPatterns is for static methods. Both PVObject and PVStaticObject extend the pattern classes.
  • 7. Vending Machine Example We are going to start off with a vending machine example. Our VendingMachine extends PVObject. PVObject extends PVPatterns which has the filter methods we need. Extending PVObject Compile the data to filter Make the method filterable by adding the filters
  • 8. Adding A Filter If you noticed in our filter class, we had an explicit section where the filters are were defined. Checks if there is a filter for this class and this method Apply the filter for this class and this method Executes only if the event type has been set Filters are suppose to be tied to a specific function in a specific class. We can simply use get_class and __Function__ to get the current class and function. The method _hasFitler first determines if they method has any filters. If true, lets execute them. The function has two different filters because there are two different events being performed, a check and a selection. The filter is being applied by passing in the class name, the function name, the data to be filtered, and options. Keep in mind that the filter can only filter one piece of data.
  • 9. Item Check Now for our vending we have items like beer which need to be checked before buying. Lets add in a class that handles that. Options passed about the filter Data passed from the filter Return the data
  • 10. Item Chooser Soda sounds generic. What kind of soda? Next we are going to add a class to handle what kind of item we are picking. Options passed Data passed from about the filter the filter Return the data
  • 11. Vend! Round 1 So we have our vending machine set up. Lets run the function with some data and look at the results. Remember the parameters was item, money and age.
  • 12. Round 1 Results Oh man, that’s not good. We are having minors getting beer and anyone putting any price and getting what they want. And all the items are generic! Let’s fix this.
  • 13. Round 2- Add Some filters So let’s add some filters in. The first two arguments is the class and method to tie the filter too. The second two arguments is the class and method that will do the filtering. The last in the options in which you can tie the filter being called to a particular event. Let’s give this a try. Filter works only on The class to attach the filter to The method to filter this event The class that will filter the data The method in the class to filter the data
  • 14. Round 2 Results Ok a little better, at least we are getting some none generic items back. But we still need to verify the age and amount tendered.
  • 15. Round 3 – Verification Filters Now we are going to add the last set filters on, the same way we added the previous filters. Calls an instance
  • 16. Round 3 Result Finally, the results we need. So that is filters in a nutshell. We modified the data in the method without ever modifying the method.
  • 17. Challenge! Below is an optional challenge designed to help you gain a better understanding of the design pattern. 1. Create 3 classes with 2 methods each. Make sure each method accepts 2 parameters and has at least one filter. 2. Attach a filter to each method that filters out by calling a filter from another class. 3. Design the filters in a way THAT DOES NOT CAUSE AN INFINITE LOOP. 4. Execute code.
  • 18. Summary 1. Apply a filter using the _applyFilter method. The name of the class and the name of the function calling the filter should be used. The function only accepts 1 parameter for data to be filters. 2. Add a filter before execution using the _addFilter method. Specify the class and method to be filter and the class and method to run the filter through.
  • 19. API Reference For a better understanding of the Collections and the Iterator, check out the api at the two links below. PVStaticPatterns PVPatterns More Tutorials For more tutorials, please visit: http://www.prodigyview.com/tutorials www.prodigyview.com