SlideShare a Scribd company logo
1 of 29
Download to read offline
Perforce PHP Object and
Record Models
Geoff Nicol
Software Developer
Perforce PHP Object Model
Overview

   • Abstract perforce operations
      • Do a lot of the parsing and assembly to avoid string bashing elsewhere
   • Create a more PHP natural layer
   • Wrap multiple connection types
   • Provide a reliable interface
   • Creates a foundation for PHP Record Model
MODELS
MODELS
MODELS
MODELS
SPEC OUTPUT SAMPLE

   p4 changes -m1
   ... change 318652
   ... time 1305914360
   ... user gnicol
   ... client gnicol
   ... status submitted
   ... changeType public
   ... path //depot/main/application/...
   ... desc Sed ut perspiciatis und

   p4 change -o 318652
   ... Change 318652
   ... Date 2011/05/20 10:59:20
   ... Client gnicol
   ... User gnicol
   ... Status submitted
   ... Description Sed ut perspiciatis unde omnis iste natus
   error sit voluptatem.

   Accusantium doloremque laudantium.

   ... Type public
CONNECTION HANDLING

   • Connection Abstract defines base capabilities
      • Concrete wrappers for CLI and Native Extension
      • Static factory method does type selection
      • Supports concept of setting ‘default’ connection


   • Connected Abstract
      • Implements [get/set/has/clear]Connection
      • Provides static getDefaultConnection to allow per-model defaults
CONNECTION SAMPLE

   $connection = P4_Connection::factory(
       'perforce:1666',
       'user',
       'client',
       null
   );

   P4_Connection::setDefaultConnection($connection);
SPEC SAMPLE

   // Assume default connection setup as per previous example
   $job = new P4_Job();
   $job->setDescription('test')->save();

   // Or use a manual connection
   $job = new P4_Job(
       P4_Connection::factory('other:1666', 'joe')
   );
   $job->setValue('Description', 'test2')->save();

   // will contain a partially populated version
   $jobs = P4_Job::fetchAll(
       array(P4_Job::FETCH_BY_FILTER => 'test')
   );

   foreach($jobs as $job) {
       echo $job->getId();    // Pulled from partial population
       echo ': ' . $job->getDescription();    // Will lazy load
   }
P4_File

    • Wraps numerous perforce commands (fstat, print, attribute, etc.)


    • Allows users to limit files via a Query API we provide
       • Limit results based on path(s)
       • Specify sorting options
       • Paginate results: max rows, row offset

    • Exposes our Filter API to further limit results
       • Programmatic interface to fstat -F <expr>
       • Supports literal and regex matches
       • Conditions can be AND’d, OR’d together
       • Supports sub-filters
       • Casts to fstat -F <expr> via toString()
FILE SAMPLE

   $file = new P4_File;
   $file->setFilespec('//depot/small.txt')
        ->open()
        ->setLocalContents('A small file.')
        ->setAttribute('foo', 'small')
        ->submit('Add a small file.');

   $file->edit()
        ->setLocalContents('An edited small file.')
        ->submit('Edit a small file');

   echo P4_File::fetch('//depot/small.txt')
               ->getDepotContents();


   ----- Output ------------------------------------------
   Edit a small file
SUGAR

  • Pass strings or objects when passing parameters like user, group, etc.
  • Spec word-lists are returned as associative arrays
      • Mutators accept hashes or strings as input
  • A fluent interface is supported wherever possible
  • Iterator provide convenience methods such as Invoke, Filter, Search, Sort
SUGAR EXAMPLES

   // Pass in object or string, where appropriate
   $group = new P4_Group;
   $user = P4_User::fetch('Bob');
   $group->setId('test')
         ->addUser($user)
         ->addUser('joe')
         ->save();

   // Pass in string or hash, where appropriate
   $triggers = P4_Triggers::fetch();
   $values    = $triggers->getTriggers();
   $values[] = 'test-trigger form-in //... /path/script.sh';
   $values[] = array(
       'name'     => 'test2',
       'type'     => 'form-out',
       'path'     => '//...',
       'command' => '/path/otherScript.sh'
   );
   $triggers->setTriggers($values)->save();
Perforce CMS
Record Model
Overview

   • Storing data in perforce can be hard, this layer should make it easy.
   • Provide a natural CRUD interface more in line with Active Record
   • Provide features such as lazy loading, fluent interface, etc.
   • Has the option of extension
   • Supports several modes of operation
      • Static
      • Object
      • Extended Object
SIMPLE STATIC API

   • store(<values>)
   • fetch(<id>)
   • fetchAll(<query>)
   • exists(<id>)
   • count(<query>)
   • remove(<id>)
USING THE STATIC API

   $record = P4Cms_Record::store(
       array(
           'firstName' => 'Don',
           'lastName' => 'Draper’
       )
   );

   print_r($record->getValues());


   ----- Output ------------------------------------------
   Array(
       [id]        => 1
       [firstName] => Don
       [lastName] => Draper
   )
STORAGE LOCATION

   <storage path> / <storage sub-path> / <ID derived file name>


   • Storage Path is provided by the Record Adapter
      • We support a default adapter concept
   • Storage Sub-Path is, optionally, provided by the Record Model
   • ID is based on Record ID
OBJECT MODEL

   • Can instantiate record class
   • Provides in-memory data objects
   • get/setId()
   • get/setValues()
   • save()
   • delete()
USING THE OBJECT MODEL

   $peg = new P4Cms_Record;
   $peg->setValue('firstName', 'Peggy')
       ->setValue('lastName', 'Olson')
       ->save();

   print_r($peg->getValues());


   ----- Output ------------------------------------------
   Array(
       [id]        => 2
       [firstName] => Peggy
       [lastName] => Olson
   )
EXTENDING THE OBJECT MODEL

   • Why extend?
   • Specify a storage sub-path
   • Define defaults, known fields, id-field, file-field
   • Define custom field accessors, mutators
   • Provide access to related records
      • e.g. $person->getFriends()
OTHER FEATURES

   • Lazy-load
      • fetch(<id>) defers populate until getValue()

   • IDs & Auto-increment
      • IDs can be strings e.g. ‘path/to/foo.bar’
      • If no ID is given, store() makes one

   • Query and Filter APIs extended from Object layer


   • Batches
      • Put modified records in a pending change
      • Can be committed or reverted
      • Faster, atomic
USING THE FILTER API

   $names = array('Pete', 'Betty', 'Joan', 'Roger');
   foreach ($names as $name) {
       Person::store(array('firstName' => $name));
   }

   $filter = new P4Cms_Record_Filter;
   $filter->add('firstName', array('Betty', 'Joan'));
   $ladies = Person::fetchAll(
       new P4Cms_Record_Query(array('filter' => $filter))
   );

   print_r($ladies->invoke('getValue', array('firstName'));


   ----- Output ------------------------------------------
   Array(
       [0] => Betty
       [1] => Joan
   )
USING BATCHES

   $people = Person::fetchAll();
   $adapter = P4Cms_Record::getDefaultAdapter();

   $adapter->beginBatch('Bulk Update');
   $people->invoke('setValue', array('fictional', true));
   $people->invoke('save');
   $adapter->commitBatch();

   // use the P4 layer to verify batching occured
   $changes = P4_Change::fetchAll(array('maximum' => 1));
   print count($changes->current()->getFiles());


   ----- Output ------------------------------------------
   6
HOW DOES IT WORK?

   • Record ‘Adapter’ hold connection object, specifies storage path, manages
     batches
   • Record IDs map to filenames
   • Values map to attributes
   • Query API leans heavily on p4 fstat
   • Uses our Perforce PHP Object Model
CONCLUSION

   • Perforce PHP Object Model
      • Provides deep access to perforce functionality
      • Removes the need to bash strings and spec forms manually
      • Provides a more consistent and fully detailed view of objects


   • Perforce PHP Record Model
      • Provides a more ActiveRecord style interface to Perforce
      • Can be used in conjunction with Object Model
Questions ???

More Related Content

What's hot

Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128PrinceGuru MS
 
vfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsFrank Kleine
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of LithiumNate Abele
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownpartsBastian Feder
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium AppsNate Abele
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Kris Wallsmith
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Workhorse Computing
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome TownRoss Tuck
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Workhorse Computing
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm OldRoss Tuck
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Fabien Potencier
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 

What's hot (20)

Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
vfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent tests
 
Metadata-driven Testing
Metadata-driven TestingMetadata-driven Testing
Metadata-driven Testing
 
The Origin of Lithium
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Findbin libs
Findbin libsFindbin libs
Findbin libs
 
Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!Hypers and Gathers and Takes! Oh my!
Hypers and Gathers and Takes! Oh my!
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 

Similar to Perforce Object and Record Model

Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Designunodelostrece
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitsmueller_sandsmedia
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHPHari K T
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?Alexandru Badiu
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr PasichPiotr Pasich
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastMichelangelo van Dam
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappersPositive Hack Days
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of LithiumNate Abele
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceIvan Chepurnyi
 

Similar to Perforce Object and Record Model (20)

Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Zendcon 2007 Api Design
Zendcon 2007 Api DesignZendcon 2007 Api Design
Zendcon 2007 Api Design
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
 
Aura Project for PHP
Aura Project for PHPAura Project for PHP
Aura Project for PHP
 
What's new in the Drupal 7 API?
What's new in the Drupal 7 API?What's new in the Drupal 7 API?
What's new in the Drupal 7 API?
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Legacy applications - 4Developes konferencja, Piotr Pasich
Legacy applications  - 4Developes konferencja, Piotr PasichLegacy applications  - 4Developes konferencja, Piotr Pasich
Legacy applications - 4Developes konferencja, Piotr Pasich
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
On secure application of PHP wrappers
On secure application  of PHP wrappersOn secure application  of PHP wrappers
On secure application of PHP wrappers
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
Tutorial Puppet
Tutorial PuppetTutorial Puppet
Tutorial Puppet
 
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for PerformanceMeet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 

More from Perforce

How to Organize Game Developers With Different Planning Needs
How to Organize Game Developers With Different Planning NeedsHow to Organize Game Developers With Different Planning Needs
How to Organize Game Developers With Different Planning NeedsPerforce
 
Regulatory Traceability: How to Maintain Compliance, Quality, and Cost Effic...
Regulatory Traceability:  How to Maintain Compliance, Quality, and Cost Effic...Regulatory Traceability:  How to Maintain Compliance, Quality, and Cost Effic...
Regulatory Traceability: How to Maintain Compliance, Quality, and Cost Effic...Perforce
 
Efficient Security Development and Testing Using Dynamic and Static Code Anal...
Efficient Security Development and Testing Using Dynamic and Static Code Anal...Efficient Security Development and Testing Using Dynamic and Static Code Anal...
Efficient Security Development and Testing Using Dynamic and Static Code Anal...Perforce
 
Understanding Compliant Workflow Enforcement SOPs
Understanding Compliant Workflow Enforcement SOPsUnderstanding Compliant Workflow Enforcement SOPs
Understanding Compliant Workflow Enforcement SOPsPerforce
 
Branching Out: How To Automate Your Development Process
Branching Out: How To Automate Your Development ProcessBranching Out: How To Automate Your Development Process
Branching Out: How To Automate Your Development ProcessPerforce
 
How to Do Code Reviews at Massive Scale For DevOps
How to Do Code Reviews at Massive Scale For DevOpsHow to Do Code Reviews at Massive Scale For DevOps
How to Do Code Reviews at Massive Scale For DevOpsPerforce
 
How to Spark Joy In Your Product Backlog
How to Spark Joy In Your Product Backlog How to Spark Joy In Your Product Backlog
How to Spark Joy In Your Product Backlog Perforce
 
Going Remote: Build Up Your Game Dev Team
Going Remote: Build Up Your Game Dev Team Going Remote: Build Up Your Game Dev Team
Going Remote: Build Up Your Game Dev Team Perforce
 
Shift to Remote: How to Manage Your New Workflow
Shift to Remote: How to Manage Your New WorkflowShift to Remote: How to Manage Your New Workflow
Shift to Remote: How to Manage Your New WorkflowPerforce
 
Hybrid Development Methodology in a Regulated World
Hybrid Development Methodology in a Regulated WorldHybrid Development Methodology in a Regulated World
Hybrid Development Methodology in a Regulated WorldPerforce
 
Better, Faster, Easier: How to Make Git Really Work in the Enterprise
Better, Faster, Easier: How to Make Git Really Work in the EnterpriseBetter, Faster, Easier: How to Make Git Really Work in the Enterprise
Better, Faster, Easier: How to Make Git Really Work in the EnterprisePerforce
 
Easier Requirements Management Using Diagrams In Helix ALM
Easier Requirements Management Using Diagrams In Helix ALMEasier Requirements Management Using Diagrams In Helix ALM
Easier Requirements Management Using Diagrams In Helix ALMPerforce
 
How To Master Your Mega Backlog
How To Master Your Mega Backlog How To Master Your Mega Backlog
How To Master Your Mega Backlog Perforce
 
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...Perforce
 
How to Scale With Helix Core and Microsoft Azure
How to Scale With Helix Core and Microsoft Azure How to Scale With Helix Core and Microsoft Azure
How to Scale With Helix Core and Microsoft Azure Perforce
 
Achieving Software Safety, Security, and Reliability Part 2
Achieving Software Safety, Security, and Reliability Part 2Achieving Software Safety, Security, and Reliability Part 2
Achieving Software Safety, Security, and Reliability Part 2Perforce
 
Should You Break Up With Your Monolith?
Should You Break Up With Your Monolith?Should You Break Up With Your Monolith?
Should You Break Up With Your Monolith?Perforce
 
Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...
Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...
Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...Perforce
 
What's New in Helix ALM 2019.4
What's New in Helix ALM 2019.4What's New in Helix ALM 2019.4
What's New in Helix ALM 2019.4Perforce
 
Free Yourself From the MS Office Prison
Free Yourself From the MS Office Prison Free Yourself From the MS Office Prison
Free Yourself From the MS Office Prison Perforce
 

More from Perforce (20)

How to Organize Game Developers With Different Planning Needs
How to Organize Game Developers With Different Planning NeedsHow to Organize Game Developers With Different Planning Needs
How to Organize Game Developers With Different Planning Needs
 
Regulatory Traceability: How to Maintain Compliance, Quality, and Cost Effic...
Regulatory Traceability:  How to Maintain Compliance, Quality, and Cost Effic...Regulatory Traceability:  How to Maintain Compliance, Quality, and Cost Effic...
Regulatory Traceability: How to Maintain Compliance, Quality, and Cost Effic...
 
Efficient Security Development and Testing Using Dynamic and Static Code Anal...
Efficient Security Development and Testing Using Dynamic and Static Code Anal...Efficient Security Development and Testing Using Dynamic and Static Code Anal...
Efficient Security Development and Testing Using Dynamic and Static Code Anal...
 
Understanding Compliant Workflow Enforcement SOPs
Understanding Compliant Workflow Enforcement SOPsUnderstanding Compliant Workflow Enforcement SOPs
Understanding Compliant Workflow Enforcement SOPs
 
Branching Out: How To Automate Your Development Process
Branching Out: How To Automate Your Development ProcessBranching Out: How To Automate Your Development Process
Branching Out: How To Automate Your Development Process
 
How to Do Code Reviews at Massive Scale For DevOps
How to Do Code Reviews at Massive Scale For DevOpsHow to Do Code Reviews at Massive Scale For DevOps
How to Do Code Reviews at Massive Scale For DevOps
 
How to Spark Joy In Your Product Backlog
How to Spark Joy In Your Product Backlog How to Spark Joy In Your Product Backlog
How to Spark Joy In Your Product Backlog
 
Going Remote: Build Up Your Game Dev Team
Going Remote: Build Up Your Game Dev Team Going Remote: Build Up Your Game Dev Team
Going Remote: Build Up Your Game Dev Team
 
Shift to Remote: How to Manage Your New Workflow
Shift to Remote: How to Manage Your New WorkflowShift to Remote: How to Manage Your New Workflow
Shift to Remote: How to Manage Your New Workflow
 
Hybrid Development Methodology in a Regulated World
Hybrid Development Methodology in a Regulated WorldHybrid Development Methodology in a Regulated World
Hybrid Development Methodology in a Regulated World
 
Better, Faster, Easier: How to Make Git Really Work in the Enterprise
Better, Faster, Easier: How to Make Git Really Work in the EnterpriseBetter, Faster, Easier: How to Make Git Really Work in the Enterprise
Better, Faster, Easier: How to Make Git Really Work in the Enterprise
 
Easier Requirements Management Using Diagrams In Helix ALM
Easier Requirements Management Using Diagrams In Helix ALMEasier Requirements Management Using Diagrams In Helix ALM
Easier Requirements Management Using Diagrams In Helix ALM
 
How To Master Your Mega Backlog
How To Master Your Mega Backlog How To Master Your Mega Backlog
How To Master Your Mega Backlog
 
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
Achieving Software Safety, Security, and Reliability Part 3: What Does the Fu...
 
How to Scale With Helix Core and Microsoft Azure
How to Scale With Helix Core and Microsoft Azure How to Scale With Helix Core and Microsoft Azure
How to Scale With Helix Core and Microsoft Azure
 
Achieving Software Safety, Security, and Reliability Part 2
Achieving Software Safety, Security, and Reliability Part 2Achieving Software Safety, Security, and Reliability Part 2
Achieving Software Safety, Security, and Reliability Part 2
 
Should You Break Up With Your Monolith?
Should You Break Up With Your Monolith?Should You Break Up With Your Monolith?
Should You Break Up With Your Monolith?
 
Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...
Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...
Achieving Software Safety, Security, and Reliability Part 1: Common Industry ...
 
What's New in Helix ALM 2019.4
What's New in Helix ALM 2019.4What's New in Helix ALM 2019.4
What's New in Helix ALM 2019.4
 
Free Yourself From the MS Office Prison
Free Yourself From the MS Office Prison Free Yourself From the MS Office Prison
Free Yourself From the MS Office Prison
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: 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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
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
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: 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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
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
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
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
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Perforce Object and Record Model

  • 1. Perforce PHP Object and Record Models Geoff Nicol Software Developer
  • 3. Overview • Abstract perforce operations • Do a lot of the parsing and assembly to avoid string bashing elsewhere • Create a more PHP natural layer • Wrap multiple connection types • Provide a reliable interface • Creates a foundation for PHP Record Model
  • 8. SPEC OUTPUT SAMPLE p4 changes -m1 ... change 318652 ... time 1305914360 ... user gnicol ... client gnicol ... status submitted ... changeType public ... path //depot/main/application/... ... desc Sed ut perspiciatis und p4 change -o 318652 ... Change 318652 ... Date 2011/05/20 10:59:20 ... Client gnicol ... User gnicol ... Status submitted ... Description Sed ut perspiciatis unde omnis iste natus error sit voluptatem. Accusantium doloremque laudantium. ... Type public
  • 9. CONNECTION HANDLING • Connection Abstract defines base capabilities • Concrete wrappers for CLI and Native Extension • Static factory method does type selection • Supports concept of setting ‘default’ connection • Connected Abstract • Implements [get/set/has/clear]Connection • Provides static getDefaultConnection to allow per-model defaults
  • 10. CONNECTION SAMPLE $connection = P4_Connection::factory( 'perforce:1666', 'user', 'client', null ); P4_Connection::setDefaultConnection($connection);
  • 11. SPEC SAMPLE // Assume default connection setup as per previous example $job = new P4_Job(); $job->setDescription('test')->save(); // Or use a manual connection $job = new P4_Job( P4_Connection::factory('other:1666', 'joe') ); $job->setValue('Description', 'test2')->save(); // will contain a partially populated version $jobs = P4_Job::fetchAll( array(P4_Job::FETCH_BY_FILTER => 'test') ); foreach($jobs as $job) { echo $job->getId(); // Pulled from partial population echo ': ' . $job->getDescription(); // Will lazy load }
  • 12. P4_File • Wraps numerous perforce commands (fstat, print, attribute, etc.) • Allows users to limit files via a Query API we provide • Limit results based on path(s) • Specify sorting options • Paginate results: max rows, row offset • Exposes our Filter API to further limit results • Programmatic interface to fstat -F <expr> • Supports literal and regex matches • Conditions can be AND’d, OR’d together • Supports sub-filters • Casts to fstat -F <expr> via toString()
  • 13. FILE SAMPLE $file = new P4_File; $file->setFilespec('//depot/small.txt') ->open() ->setLocalContents('A small file.') ->setAttribute('foo', 'small') ->submit('Add a small file.'); $file->edit() ->setLocalContents('An edited small file.') ->submit('Edit a small file'); echo P4_File::fetch('//depot/small.txt') ->getDepotContents(); ----- Output ------------------------------------------ Edit a small file
  • 14. SUGAR • Pass strings or objects when passing parameters like user, group, etc. • Spec word-lists are returned as associative arrays • Mutators accept hashes or strings as input • A fluent interface is supported wherever possible • Iterator provide convenience methods such as Invoke, Filter, Search, Sort
  • 15. SUGAR EXAMPLES // Pass in object or string, where appropriate $group = new P4_Group; $user = P4_User::fetch('Bob'); $group->setId('test') ->addUser($user) ->addUser('joe') ->save(); // Pass in string or hash, where appropriate $triggers = P4_Triggers::fetch(); $values = $triggers->getTriggers(); $values[] = 'test-trigger form-in //... /path/script.sh'; $values[] = array( 'name' => 'test2', 'type' => 'form-out', 'path' => '//...', 'command' => '/path/otherScript.sh' ); $triggers->setTriggers($values)->save();
  • 17. Overview • Storing data in perforce can be hard, this layer should make it easy. • Provide a natural CRUD interface more in line with Active Record • Provide features such as lazy loading, fluent interface, etc. • Has the option of extension • Supports several modes of operation • Static • Object • Extended Object
  • 18. SIMPLE STATIC API • store(<values>) • fetch(<id>) • fetchAll(<query>) • exists(<id>) • count(<query>) • remove(<id>)
  • 19. USING THE STATIC API $record = P4Cms_Record::store( array( 'firstName' => 'Don', 'lastName' => 'Draper’ ) ); print_r($record->getValues()); ----- Output ------------------------------------------ Array( [id] => 1 [firstName] => Don [lastName] => Draper )
  • 20. STORAGE LOCATION <storage path> / <storage sub-path> / <ID derived file name> • Storage Path is provided by the Record Adapter • We support a default adapter concept • Storage Sub-Path is, optionally, provided by the Record Model • ID is based on Record ID
  • 21. OBJECT MODEL • Can instantiate record class • Provides in-memory data objects • get/setId() • get/setValues() • save() • delete()
  • 22. USING THE OBJECT MODEL $peg = new P4Cms_Record; $peg->setValue('firstName', 'Peggy') ->setValue('lastName', 'Olson') ->save(); print_r($peg->getValues()); ----- Output ------------------------------------------ Array( [id] => 2 [firstName] => Peggy [lastName] => Olson )
  • 23. EXTENDING THE OBJECT MODEL • Why extend? • Specify a storage sub-path • Define defaults, known fields, id-field, file-field • Define custom field accessors, mutators • Provide access to related records • e.g. $person->getFriends()
  • 24. OTHER FEATURES • Lazy-load • fetch(<id>) defers populate until getValue() • IDs & Auto-increment • IDs can be strings e.g. ‘path/to/foo.bar’ • If no ID is given, store() makes one • Query and Filter APIs extended from Object layer • Batches • Put modified records in a pending change • Can be committed or reverted • Faster, atomic
  • 25. USING THE FILTER API $names = array('Pete', 'Betty', 'Joan', 'Roger'); foreach ($names as $name) { Person::store(array('firstName' => $name)); } $filter = new P4Cms_Record_Filter; $filter->add('firstName', array('Betty', 'Joan')); $ladies = Person::fetchAll( new P4Cms_Record_Query(array('filter' => $filter)) ); print_r($ladies->invoke('getValue', array('firstName')); ----- Output ------------------------------------------ Array( [0] => Betty [1] => Joan )
  • 26. USING BATCHES $people = Person::fetchAll(); $adapter = P4Cms_Record::getDefaultAdapter(); $adapter->beginBatch('Bulk Update'); $people->invoke('setValue', array('fictional', true)); $people->invoke('save'); $adapter->commitBatch(); // use the P4 layer to verify batching occured $changes = P4_Change::fetchAll(array('maximum' => 1)); print count($changes->current()->getFiles()); ----- Output ------------------------------------------ 6
  • 27. HOW DOES IT WORK? • Record ‘Adapter’ hold connection object, specifies storage path, manages batches • Record IDs map to filenames • Values map to attributes • Query API leans heavily on p4 fstat • Uses our Perforce PHP Object Model
  • 28. CONCLUSION • Perforce PHP Object Model • Provides deep access to perforce functionality • Removes the need to bash strings and spec forms manually • Provides a more consistent and fully detailed view of objects • Perforce PHP Record Model • Provides a more ActiveRecord style interface to Perforce • Can be used in conjunction with Object Model