Wstęp do programowania w języku PHP



Similar documents
Intro to Web Programming. using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

A Tour of Silex and Symfony Components. Robert

>

CS170 Lab 11 Abstract Data Types & Objects

The PHP 5.4 Features You Will Actually Use



Ch 7-1. Object-Oriented Programming and Classes

Testking.M Q

How Scala Improved Our Java

Entites in Drupal 8. Sascha Grossenbacher Christophe Galli

ARC: appmosphere RDF Classes for PHP Developers

Sending images from a camera to an iphone. PowerShot G1X MarkII, PowerShot SX600 HS, PowerShot N100, PowerShot SX700 HS, PowerShot ELPH 340 HS

Yandex.Widgets Quick start

SECTION 1: FIND OUT THE IP ADDRESS OF DVR To find out the IP of DVR for your DVR do the following:

Using vcenter Orchestrator AMQP Plug-in

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

WEB SERVICES TECHNICAL GUIDE FOR DEVELOPERS

BEST PRACTICES FOR OBTAINING MOBILE DEVICE IDENTIFIERS FOR MOBILE DEVICE THEFT PREVENTION (MDTP)

PHP Integration Kit. Version User Guide

4G Ready Mobiles - Apple Devices

An Introduction to Developing ez Publish Extensions

Specialized Programme on Web Application Development using Open Source Tools

Java Server Pages and Java Beans

Instructor: Betty O Neil

Script Handbook for Interactive Scientific Website Building

Home AV Networks. T Multimedia Programming. Outline. Architectures Media Centers Distributed Systems. Jari Kleimola November 2, 2006

This is our best... YOUR best... Online Banking yet!

USING MAGENTO TRANSLATION TOOLS

It has a parameter list Account(String n, double b) in the creation of an instance of this class.

Write Your Angry Bird Game on Tizen for Fun and Profit. Lu Guanqun Intel Corporation

Dashboard Skin Tutorial. For ETS2 HTML5 Mobile Dashboard v3.0.2

the future of mobile web by startech.ro

MASTERTAG DEVELOPER GUIDE

Using an iphone to control the camera during remote shooting (PowerShot SX530 HS, SX610 HS, and SX710 HS)

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

Lecture 17: Mobile Computing Platforms: Android. Mythili Vutukuru CS 653 Spring 2014 March 24, Monday

Classes, Objects, and Methods

Drupal 8. Core and API Changes Shabir Ahmad MS Software Engg. NUST Principal Software Engineser PHP/Drupal

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Once the software has finished downloading, locate the ivms-4000(v2.0).exe on your hard drive and open it.

How To Write A Program On Java.Io.2.2 (Java)

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

Business Online Banking Quick Users Guide

1 CONNECT & CREATE CHAMBERLAIN INTERNET GATEWAY USER S GUIDE. Featuring MyQ Technology

How To Create A Simple Module in Magento 2.0. A publication of

SRFax Fax API Web Services Documentation

Release Notes: Onsight Connect for Android Software Release Notes. Software Version Revision 1.0.0

Stack vs. Heap. Introduction to Programming. How the Stack Works. Primitive vs. Reference Types. Stack

public static void main(string[] args) { System.out.println("hello, world"); } }

PHP and XML. Brian J. Stafford, Mark McIntyre and Fraser Gallop

Certified PHP/MySQL Web Developer Course

Install Java Development Kit (JDK) 1.8

Practical Guided Tour of Symfony

Search and Replace in SAS Data Sets thru GUI

Web development... the server side (of the force)

Mobile memory dumps, MSAB and MPE+ Data collection Information recovery Analysis and interpretation of results

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

CSCI110: Examination information.

BASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo.

The C Programming Language course syllabus associate level

Chances of changes in Magento 2.0 extension development. Gerhard Fobe Netresearch App Factory

sqlpp11 - An SQL Library Worthy of Modern C++

Moving from CS 61A Scheme to CS 61B Java

PHP AdWords API Lib Quick Start

Lab 5 Introduction to Java Scripts

English 1. Deutsch 10. Français 19 中 文 简 体 46

Learning Remote Control Framework ADD-ON for LabVIEW

Reliable Mitigation of DOM-based XSS

Presto User s Manual. Collobos Software Version Collobos Software, Inc

PHP Tutorial From beginner to master

g!mobile 6 Android App Android 4.0 or above -- See Android Devices table for compatibility information Document Revision Date: 2/14/2013

Visualizing Software Projects in JavaScript

Opera System Configuration for Apps

orrelog SNMP Trap Monitor Software Users Manual

Laravel + AngularJS - Contact Manager

A REST API for Arduino & the CC3000 WiFi Chip

Illustration 1: Diagram of program function and data flow

APEX_ITEM and Dynamic Tabular Forms

Two Factor Authentication (TFA; 2FA) is a security process in which two methods of authentication are used to verify who you are.

ipad Basics Tips from the October 16, 2014 ipad Basics Class Tip No. 1 Apple ID Where is it found? Settings>iCloud>Apple ID

Web Development using PHP (WD_PHP) Duration 1.5 months

Ada. Randki (spotkania) w Adzie. Model. U Ady. Zasady. task Buffer is entry Append (I: in integer); entry Take (I: out integer); end Buffer;

2 Tablet Stands. ASM-iSTAND ipad STAND. ASM-iMINISTAND ipad MINI STAND ASM-TABSTAND TABLET STAND

Mobile Data Collection with Avenza PDF Maps

Certified PHP Developer VS-1054

itunes: About ios backups

Quick Start Guide: ios and Android Iridium GO! App

Transcription:

Wstęp do programowania w języku PHP

Programowanie obiektowe PHP OOP

O czym jest ta prezentacja wstęp do programowania obiektowego cechy języka php przestrzenie nazw composer automatyczne ładowanie klas

Programowanie obiektowe klasa enkapsulacja metody magiczne dziedziczenie klasy abstrakcyjne interfejsy cechy przestrzenie nazw

Klasa /** * Class representing any electronic Device * @author John Doe <john.doe@example.com> */ class Device { /** * Outer case color * @var string */ public $color = 'white'; /** * Returns device's unique s/n * @return string */ public function getserial() { return '1M8GDM9AKP042788'; /** * Performs soft restart on a device */ public function restart() {

Klasa class Device { public $color = 'white'; public function getserial () { return '1M8GDM9AKP042788' ; public function restart () { $mydevice = new Device(); $mydevice ->color = 'black';

Enkapsulacja class Device { private $color = 'white'; public function getserial () { return '1M8GDM9AKP042788' ; $mydevice = new Device(); $mydevice ->color = 'black'; Fatal error: Cannot access private property Device::$color

Enkapsulacja class Device { private $color = 'white'; Modyfikatory dostępu private protected public public function getserial () { return '1M8GDM9AKP042788' ; $mydevice = new Device(); $mydevice ->color = 'black'; Fatal error: Cannot access private property Device::$color

Konstruktor class Phone { private $imei; public function construct ($imei) { $this->imei = $imei;

Konstruktor class Phone { private $imei; public function construct ($imei) { $this->imei = $imei;

Konstruktor class Phone { private $imei; public function construct ($imei) { $this->imei = $imei; $foo = new Phone();

Konstruktor class Phone { private $imei; public function construct ($imei) { $this->imei = $imei; $foo = new Phone(); Warning:Missing argument 1 for Phone:: construct ()

Konstruktor class Phone { private $imei; public function construct ($imei) { $this->imei = $imei; $foo = new Phone('75473858437534325' );

Metody Magiczne class Phone { private $attributes = array(); public function construct (array $attributes ) { $this->attributes = $attributes ;

Metody Magiczne class Phone { private $attributes = array(); public function construct (array $attributes ) { $this->attributes = $attributes ; public function get($name) { if(array_key_exists ($name, $this->attributes )) { return $this->attributes [$name]; return null;

Metody Magiczne class Phone { //... public function get($name) { if(array_key_exists ($name, $this->attributes )) { return $this->attributes [$name]; return null; $phone = new Phone([ 'color' => 'black', 'mpix' => 8 ]); echo $phone->mpix;

Metody Magiczne class Phone { //... public function set($name, $value ) { $this->attributes[$name] = $value; $phone = new Phone([ 'color' => 'black', 'mpix' => 8 ]);

Metody Magiczne class Phone { //... public function set($name, $value ) { $this->attributes[$name] = $value; $phone = new Phone([ 'color' => 'black', 'mpix' => 8 ]); $phone->mpix = 16; echo $phone->mpix;

Dziedziczenie class Phone extends Device { public function call($number) { // (...) $myphone = new Phone();

Dziedziczenie class Phone extends Device { public function call($number) { // (...) $myphone = new Phone(); $myphone ->color = 'blue';

Dziedziczenie class Phone extends Device { public function call($number) { // (...) $myphone = new Phone(); $myphone ->color = 'blue'; $serial = $myphone ->getserial ();

Dziedziczenie class Phone extends Device { public function call($number) { // (...) $myphone = new Phone(); $myphone ->color = 'blue'; $serial = $myphone ->getserial (); $myphone ->call('+48 708 477 130' );

Klasa abstrakcyjna abstract class PhoneAbstract { public $color = 'white'; public abstract function call($number); ; $somephone = new PhoneAbstract ();

Klasa abstrakcyjna abstract class PhoneAbstract { public $color = 'white'; public abstract function call($number); ; $somephone = new PhoneAbstract (); Fatal error: Cannot instantiate abstract class Phone

Klasa abstrakcyjna class IPhone extends PhoneAbstract { ; $iphone = new IPhone();

Klasa abstrakcyjna class IPhone extends PhoneAbstract { ; $iphone = new IPhone(); Fatal error: Class IPhone contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Phone::call)

Klasa abstrakcyjna class IPhone extends PhoneAbstract { public function call($number){ //... ;

Klasa abstrakcyjna vs interfejs abstract class Camera { public abstract function record(); class IPhone extends Phone, Camera {

Klasa abstrakcyjna vs interfejs abstract class Camera { public abstract function record(); class IPhone extends Phone, Camera {

Klasa abstrakcyjna vs interfejs abstract class Camera{ public abstract function record(); class IPhone extends Phone, Camera { Brak wielokrotnego dziedziczenia w języku PHP

Interface common/phoneinterface.php interface PhoneInterface { public function call($number); common/camerainterface.php interface CameraInterface { public function record();

Interface common/phoneinterface.php interface PhoneInterface { public function call($number); common/camerainterface.php interface CameraInterface { public function record(); class IPhone implements PhoneInterface, CameraInterface { public function call($number) { /*... */ public function record() { /*... */

Interface common/phoneinterface.php interface PhoneInterface { public function call($number); Tylko metody publiczne common/camerainterface.php interface CameraInterface { public function record(); class IPhone implements PhoneInterface, CameraInterface { public function call($number) { /*... */ public function record() { /*... */

Cechy trait PhoneBehavior { public function call($number) { /*... */

Cechy trait PhoneBehavior { public function call($number) { /*... */ trait CameraBehavior { public function record() { /*... */

Cechy trait PhoneBehavior { public function call($number) { /*... */ trait CameraBehavior { public function record() { /*... */ class IPhone { use PhoneBehavior, CameraBehavior ; $iphone = new IPhone(); $iphone->record();

Przestrzenie nazw smartphone/camerainterface.php /** * This is a smartphone camera interface, every smartphone with digital camera must implement * this interface. */ interface CameraInterface { sony/dvr/camerainterface.php /** * This is SONY digital camera interface, every sony DVR must implement this interface. */ interface CameraInterface {

Przestrzenie nazw smartphone/camerainterface.php /** * This is a smartphone camera interface, every smartphone with digital camera must implement * this interface. */ interface CameraInterface { sony/dvr/camerainterface.php /** * This is SONY digital camera interface, every sony DVR must implement this interface. */ interface CameraInterface { class IPhone implements PhoneInterface, CameraInterface { public function call($number) { /*... */ public function record() { /*... */

Przestrzenie nazw smartphone/camerainterface.php Kolizja nazw, parser PHP nie wie, który interfejs implementuje nasz IPhone /** * This is a smartphone camera interface, every smartphone with digital camera must implement * this interface. */ interface CameraInterface { sony/dvr/camerainterface.php /** * This is SONY digital camera interface, every sony DVR must implement this interface. */ interface CameraInterface { class IPhone implements PhoneInterface, CameraInterface { public function call($number) { /*... */ public function record() { /*... */

Przestrzenie nazw src/apple/camerainterface.php namespace Apple; interface CameraInterface { public function record(); public function takephoto ();

Przestrzenie nazw src/apple/camerainterface.php namespace Apple; interface CameraInterface { public function record(); public function takephoto (); src/apple/iphone.php namespace Apple; class Iphone implements CameraInterface {

Przestrzenie nazw namespace MyApplication ; use Apple; $phone = new Apple\IPhone ();

http://www.phptherightway.com/

Zarządzanie zależnościami composer

Zarządzanie zależnościami co to są zależności composer.json packagist automatyczne ładowanie klas

Zależności i zależności zależności

composer.json { "require": { "symfony/translation": "*"

https://packagist.org/

Automatyczne ładowanie klas require 'vendor/autoload.php' ; use Symfony\Component\Translation\Translator ; use Symfony\Component\Translation\MessageSelector ; use Symfony\Component\Translation\Loader\ArrayLoader ; $translator = new Translator ('fr_fr', new MessageSelector ()); $translator ->setfallbacklocales (array('fr')); $translator ->addloader ('array', new ArrayLoader ()); $translator ->addresource ('array', array( 'Hello World!' => 'Bonjour', ), 'fr'); echo $translator ->trans('hello World!' )."\n";

composer.json { "require": { "symfony/translation": "*", "autoload": { "psr-4": {"RSTDevSchool\\": "src/"

Automatyczne ładowanie klas namespace RSTDevSchool ; use Symfony\Component\Translation\Translator ; use Symfony\Component\Translation\MessageSelector ; use Symfony\Component\Translation\Loader\ArrayLoader ; class Renderer { public function render($view) { /* */ $this->renderinternal ($view, $this->translator );

Automatyczne ładowanie klas require 'vendor/autoload.php' ; use \RstDevSchool\Renderer ;

Automatyczne ładowanie klas require 'vendor/autoload.php' ; use \RstDevSchool\Renderer ; use \RSTDevSchool as Rst;

Automatyczne ładowanie klas require 'vendor/autoload.php' ; use \RstDevSchool\Renderer ; use \RSTDevSchool as Rst; $renderer = new Rst/Renderer (); $renderer ->render('myview' );

Automatyczne ładowanie klas require 'vendor/autoload.php' ; use \RstDevSchool\Renderer ; use \RSTDevSchool as Rst; $renderer = new Rst/Renderer (); $renderer ->render('myview' ); $renderer = new Renderer (); $renderer ->render('myotherview' );

slim framework { "require": { "slim/slim": "2.*"

slim framework require 'vendor/autoload.php' ; $app = new \Slim\Slim (); $app->get('/hello/:name', function ($name) { echo "Hello, $name"; ); $app->run();

Dziekuje ;)