際際滷

際際滷Share a Scribd company logo
Fixin Framework
Attila Jenei
Fixin Framework
 Owner-managed classes
 Flexible
 Simple dispatch 鍖ow
 Built for PHP 7.1+
Owner-Managed Classes
 Constructor-based injection via options
__construct($resourceManager, array $options, string $name);
 No public dependency getters and setters
 Responsibility goes to the creator
 Class constants
 Prevents mistyping and hidden not-used options
Managed Class
 Abstract implementation of ManagedInterface
 Supports lazy-loading
 Supports options mapping
 Declares $options processing
Lazy-Loading
 Declaring property
$this->setLazyLoadingProperty(static::ENTITY, EntityInterface::class, $value);
 $value is a key to Resource Manager
 Loading property
protected function getEntity(): EntityInterface
{
return $this->entity ?: $this->loadLazyProperty(static::ENTITY);
}
Options Mapping
protected const THIS_SETS = [
self::DELAY => [Types::INT, Types::NULL],
self::NAME => [self::USING_SETTER, Types::NULL],
self::REPOSITORY => [self::LAZY_LOADING => RepositoryInterface::class]
]
 List of possible options and their allowed types
 Supports lazy-loading
 Supports custom setters
Resource Manager
 Holds shared Resources and preinitialized Prototypes
 Has con鍖guration for the keys
 Supports creation by class name, Factory, and
Abstract Factory
 Request with unde鍖ned key interpreted as class name
Resource Manager
 Getting a Resource:
$manager->get(BaseJsonJson, JsonInterface::class);
 Loads options from the con鍖guration on initialization
 Returns a ResourceInterface
 Always returns the same instance for the given key
Resource Manager
 Cloning a Prototype:
$manager->clone(BaseJsonJson, JsonInterface::class, [
JsonInterface::DECODING_MAX_DEPTH => 2
]);
 Loads options from the con鍖guration on
preinitialization
 Returns a cloned instance for the given key with the
additional options
Flexibility
 Interface-based classes
 Resource Manager con鍖guration
 Namespace fallback support
Interfaces
 All classes use interface types
 Option names are de鍖ned as interface constants
 All class replaceable with custom implementation
Resouce Manager
Con鍖guration
 Options for the keys
 Option inheritance
 Con鍖guration of B key inherited from A key
 Aliases
Namespace Fallback
 Referencing without top level
 The root namespace will be determined
 De鍖ned root search order
 Zero con鍖guration for class overriding
 Just put into the right folder
Namespace Fallback
Example:
 Requesting *ViewView
 Manager looks for AppViewView
 then: FixinViewView
Simple Dispatch Flow
 Information Cargo
 Cargo Handlers
 Called Delivery System
Cargo
 Holds the content and its type
 Delivered 鍖ag shows 鍖nal state
 Subtypes has other data too
HTTP Cargo
 Environment, Server
 Cookies, Session
 Protocol Version, Uri, Method
 Request Headers, Parameters
 Status Code, Response Headers
Cargo Handlers
 One required method
public function handle(CargoInterface $cargo): CargoInterface 
{}
Delivery System
 Application creates a Cargo
 Cargo goes through a Route
 Route builds up from Nodes
 A Hub might send to other handler
(Action Handler, Restful Handler, Route)
 Application unpacks the Cargo
Nodes
 ArrayToJson
 HttpClassHub
 HttpErrorHub
 HttpNotFoundFallback
 HttpRouterHub
 JsonToArray
 ThrowableToText
 ViewRender
 WrapInView
PHP 7.1+
 Parameter type declarations
 Return type declarations
 Nullable types
 Void functions
 Null coalescing operator
 Class constant visibility
Visit https://blog.鍖xinphp.com
Fixin Framework

More Related Content

Fixin Framework

  • 2. Fixin Framework Owner-managed classes Flexible Simple dispatch 鍖ow Built for PHP 7.1+
  • 3. Owner-Managed Classes Constructor-based injection via options __construct($resourceManager, array $options, string $name); No public dependency getters and setters Responsibility goes to the creator Class constants Prevents mistyping and hidden not-used options
  • 4. Managed Class Abstract implementation of ManagedInterface Supports lazy-loading Supports options mapping Declares $options processing
  • 5. Lazy-Loading Declaring property $this->setLazyLoadingProperty(static::ENTITY, EntityInterface::class, $value); $value is a key to Resource Manager Loading property protected function getEntity(): EntityInterface { return $this->entity ?: $this->loadLazyProperty(static::ENTITY); }
  • 6. Options Mapping protected const THIS_SETS = [ self::DELAY => [Types::INT, Types::NULL], self::NAME => [self::USING_SETTER, Types::NULL], self::REPOSITORY => [self::LAZY_LOADING => RepositoryInterface::class] ] List of possible options and their allowed types Supports lazy-loading Supports custom setters
  • 7. Resource Manager Holds shared Resources and preinitialized Prototypes Has con鍖guration for the keys Supports creation by class name, Factory, and Abstract Factory Request with unde鍖ned key interpreted as class name
  • 8. Resource Manager Getting a Resource: $manager->get(BaseJsonJson, JsonInterface::class); Loads options from the con鍖guration on initialization Returns a ResourceInterface Always returns the same instance for the given key
  • 9. Resource Manager Cloning a Prototype: $manager->clone(BaseJsonJson, JsonInterface::class, [ JsonInterface::DECODING_MAX_DEPTH => 2 ]); Loads options from the con鍖guration on preinitialization Returns a cloned instance for the given key with the additional options
  • 10. Flexibility Interface-based classes Resource Manager con鍖guration Namespace fallback support
  • 11. Interfaces All classes use interface types Option names are de鍖ned as interface constants All class replaceable with custom implementation
  • 12. Resouce Manager Con鍖guration Options for the keys Option inheritance Con鍖guration of B key inherited from A key Aliases
  • 13. Namespace Fallback Referencing without top level The root namespace will be determined De鍖ned root search order Zero con鍖guration for class overriding Just put into the right folder
  • 14. Namespace Fallback Example: Requesting *ViewView Manager looks for AppViewView then: FixinViewView
  • 15. Simple Dispatch Flow Information Cargo Cargo Handlers Called Delivery System
  • 16. Cargo Holds the content and its type Delivered 鍖ag shows 鍖nal state Subtypes has other data too
  • 17. HTTP Cargo Environment, Server Cookies, Session Protocol Version, Uri, Method Request Headers, Parameters Status Code, Response Headers
  • 18. Cargo Handlers One required method public function handle(CargoInterface $cargo): CargoInterface {}
  • 19. Delivery System Application creates a Cargo Cargo goes through a Route Route builds up from Nodes A Hub might send to other handler (Action Handler, Restful Handler, Route) Application unpacks the Cargo
  • 20. Nodes ArrayToJson HttpClassHub HttpErrorHub HttpNotFoundFallback HttpRouterHub JsonToArray ThrowableToText ViewRender WrapInView
  • 21. PHP 7.1+ Parameter type declarations Return type declarations Nullable types Void functions Null coalescing operator Class constant visibility