Exemplo n.º 1
0
 public function testCat()
 {
     $cat = new Cat("Thelma");
     $this->assertEquals("Thelma", $cat->getName());
     $this->assertEquals("Thelma the Cat", (string) $cat);
     $cat->setName("Alice");
     $this->assertEquals("Alice", $cat->getName());
     $this->assertEquals("Alice the Cat", (string) $cat);
 }
Exemplo n.º 2
0
 function beforeroute()
 {
     //list of categories
     $cats = new Cat($this->db);
     $this->f3->set('cs', $cats->all());
     //item count (menu)
     $items = new Item($this->db);
     $nb = $items->itemcount();
     $this->f3->set('cgall', $nb);
     //category menu
     $cgs = new CatGroup($this->db);
     $this->f3->set('cgs', $cgs->all());
 }
 /**
  *
  */
 public function testWrite_WriteObjects_ObjectsWritten()
 {
     $batchSizes = array(10, 30, 100, 300);
     foreach ($batchSizes as $size) {
         $owners = array();
         $dogs = array();
         $cats = array();
         $writer = new \BatchedWriter($size);
         for ($i = 0; $i < 100; $i++) {
             $owner = new Human();
             $owner->Name = 'Human ' . $i;
             $dog = new Dog();
             $dog->Name = 'Dog ' . $i;
             $cat = new Cat();
             $cat->Name = 'Cat ' . $i;
             $owner->onAfterExistsCallback(function ($owner) use($dog, $writer) {
                 $dog->OwnerID = $owner->ID;
                 $writer->write($dog);
             });
             $dog->onAfterExistsCallback(function ($dog) use($cat, $writer) {
                 $cat->EnemyID = $dog->ID;
                 $writer->write($cat);
             });
             $owners[] = $owner;
             $dogs[] = $dog;
             $cats[] = $cat;
         }
         // writes dogs first time
         $writer->write($dogs);
         // dogs written again from owner callback
         $writer->write($owners);
         $writer->finish();
         $owners = Human::get();
         $dogs = Dog::get();
         $cats = Cat::get();
         $this->assertEquals(100, $owners->Count());
         $this->assertEquals(100, $dogs->Count());
         $this->assertEquals(100, $cats->Count());
         for ($i = 0; $i < 100; $i++) {
             $owner = $owners[$i];
             $dog = $dogs[$i];
             $cat = $cats[$i];
             $this->assertEquals($owner->ID, $dog->OwnerID);
             $this->assertEquals($dog->ID, $cat->EnemyID);
         }
         $writer->delete($owners);
         $writer->delete($dogs);
         $writer->delete($cats);
         $writer->finish();
         $this->assertEquals(0, Human::get()->Count());
         $this->assertEquals(0, Dog::get()->Count());
         $this->assertEquals(0, Cat::get()->Count());
     }
 }
Exemplo n.º 4
0
<?php

require_once "Animal.php";
require_once "Cat.php";
/**
 * @author Gutsulyak Vadim <*****@*****.**>
 */
$animal = new Animal("green");
$animal->sayHello();
$cat = new Cat("white");
$cat->sayHello();
$cat->sayMeow();
Exemplo n.º 5
0
        } else {
            echo $this->name . " is fully fed!";
            echo "<br>";
        }
    }
    public function howOld()
    {
        echo $this->name . " is " . $this->age . " years old.";
        echo "<br>";
        echo $this->name . " is " . $this->age . " cat years old!";
        echo "<br>";
    }
}
$cat1 = new Cat("Little Buddy", 2, 8);
$cat2 = new Cat("Sneaky Pete", 0, 2);
$cat3 = new Cat("whiskers", 1, 2);
$cat1->howOld();
$cat1->feedCat(6);
$cat3->howOld();
echo $cat2->name;
echo "<br>";
echo "TESTING!!!!";
$student1 = new Student('Harry', 'Potter', 17);
$student2 = new Student('Charlie', 'Brown', 16);
$student3 = new Student('Gary', 'Coleman', 15);
echo $student1->firstName;
echo "<br>";
echo $student1->lastName;
echo "<br>";
echo $student1->age;
echo "<br>";
Exemplo n.º 6
0
            echo "<br>";
        }
    }
    public function howOld()
    {
        echo $this->name . " is " . $this->age . " years old.";
        echo "<br>";
        echo $this->name . " is " . $this->age . " cat years old!";
        echo "<br>";
    }
}
$cat1 = new Cat("Little Buddy", 2, 8);
$cat2 = new Cat("Sneaky Pete", 0, 2);
$cat3 = new Cat("Jim", 1, 3);
$cat4 = new Cat("Tom", 2, 5);
$cat5 = new Cat("Kit", 120, 500);
$cat1->howOld();
$cat1->feedCat(6);
$cat3->howOld();
$cat5->howOld();
echo $cat2->name;
echo "<br>";
// =========== NEW CLASS ==========
class Car
{
    public $brand;
    public $price;
    public function __construct($_brand, $_price)
    {
        $this->brand = $_brand;
        $this->price = $_price;
Exemplo n.º 7
0
<?php

/**
 * Created by PhpStorm.
 * User: ET
 * Date: 6/26/2015
 * Time: 5:34 PM
 */
include 'Dog.php';
include 'Cat.php';
echo Pet::getCount() . "<-Total Pet object<br>";
// 0
$dog = new Dog('Satchel');
echo Pet::getCount() . "<-Total Pet object<br>";
// 1
$cat = new Cat('Bucky');
echo Pet::getCount() . "<-Total Pet object<br>";
// 2
$dog->eat();
$cat->eat();
$dog->sleep();
$cat->sleep();
$dog->play();
$cat->play();
echo "Unset dog object<br>";
unset($dog);
echo Pet::getCount() . " Pet instance left<br>";
// 1
echo "Unset cat instance<br>";
unset($cat);
echo Pet::getCount() . " Pet instance left<br>";
<?php

include 'Cat.php';
$cat1 = new Cat();
$cat1->setColor("black");
$cat1->setName("Zoe");
$cat1->setBreed("Siamese ");
$myCats[] = $cat1;
$cat2 = new Cat();
$cat2->setColor("orange");
$cat2->setName("Garfield");
$cat2->setBreed("Tabby ");
$myCats[] = $cat2;
$cat3 = new Cat();
$cat3->setColor("tabby");
$cat3->setName("Fluffy");
$cat3->setBreed("catType3 ");
$myCats[] = $cat3;
$count = 0;
catCount($myCats, $count);
echo "the count for is " . $count . "<br>";
for ($i = 0; $i < 3; $i++) {
    displayCatInfo($myCats[$i]);
}
function catCount($cats, &$num)
{
    for ($i = 0; $i < 2; $i++) {
        if ($cats[$i]->getColor() == "orange") {
            $num++;
        }
    }
Exemplo n.º 9
0
var_dump($valores);
die;
print_r($GLOBALS);
die;
echo "<form action='closure.php' method='POST'>";
echo "<input type='text' name='a'>";
echo "<input type='text' name='b'>";
echo "<input type='text' name='c'>";
echo "<input type='text' name='d'>";
echo "<input type='text' name='e'>";
?>
  <input type='submit' name='action' value='Submit'>
  
  <?php 
echo "</form>";
echo file_get_contents("php://input");
die;
class Cat
{
    public $sound = "meow";
    function meow()
    {
        echo $this->sound . "<br>" . PHP_EOL;
    }
}
$showSound = function () {
    echo "Sound is " . $this->sound;
};
$lenny = new Cat();
//$showSound->bindTo($lenny);
$lenny->meow();
Exemplo n.º 10
0
     switch ($key) {
         case "Libelle":
             $three = $txt;
             break;
         case "Categorie":
             $two = $txt;
             break;
         case "Style":
             $one = $txt;
             break;
     }
 }
 //==============fill first record===============--------------------------------------
 //trim space and comma
 $pathN = yakcatPathN($one);
 $categorie = new Cat($one, $one, $pathN, 1, '', $status);
 $succes = $categorie->saveToMongo($level = 1);
 //================fill record two======================================
 $title2 = $two;
 $path2 = $one . ", " . $two;
 $pathN2 = $pathN . "#" . yakcatPathN($title2);
 echo "<br>" . $pathN;
 $categorie->setAncestors($one, $pathN);
 $categorie->setParent($one, $pathN);
 $categorie->title = $title2;
 $categorie->path = $path2;
 $categorie->pathN = $pathN2;
 $categorie->level = 2;
 $succes = $categorie->saveToMongo($level = 2);
 //exit;
 //insert db results for ID--here---------------------------
Exemplo n.º 11
0
            echo $this->name . " needs more food than that!";
            echo "<br>";
        } else {
            echo $this->name . " is fully fed!";
            echo "<br>";
        }
    }
    public function howOld()
    {
        echo $this->name . " is " . $this->age . " years old.";
        echo "<br>";
        echo $this->name . " is " . $this->age . " cat years old!";
        echo "<br>";
    }
}
$cat1 = new Cat("Little Buddy", 2, 8);
$cat2 = new Cat("Sneaky Pete", 0, 2);
$cat1->howOld();
$cat1->feedCat(6);
echo $cat2->name;
echo "<br>";
?>

</body>
</html>





Exemplo n.º 12
0
 public function search()
 {
     $busq = Input::get('busq');
     $title = "Busqueda: " . $busq;
     $cat = Cat::where('deleted', '=', 0)->get(array('categorias.id', 'categorias.cat_nomb'));
     $subcat = array();
     foreach ($cat as $c) {
         $aux = SubCat::where('cat_id', '=', $c->id)->where('deleted', '=', 0)->get();
         $subcat[$c->id] = $aux->toArray();
     }
     $art = DB::select("SELECT DISTINCT `item`.`id`,\t\n\t\t\t\t\t\t\t\t\t\t   `item`.`item_nomb`,\n\t\t\t\t\t\t\t\t\t\t   `item`.`item_cod`,\n\t\t\t\t\t\t\t\t\t\t   `item`.`item_stock`,\n\t\t\t\t\t\t\t\t\t\t   `item`.`item_precio`,\n\t\t\t\t\t\t\t\t\t\t   `m`.`id` AS misc_id,\n\t\t\t\t\t\t\t\t\t\t   `i`.`image`\n\t\t\tFROM  `item` \n\t\t\tLEFT JOIN  `miscelanias` AS m ON  `m`.`item_id` =  `item`.`id` \n\t\t\tLEFT JOIN  `images` \t AS i ON  `i`.`misc_id` =  `m`.`id`\n\t\t\tLEFT JOIN  `tallas`      AS t ON  `m`.`item_talla`=`t`.`id`\n\t\t\tLEFT JOIN  `colores` \t AS c ON  `m`.`item_color`=`c`.`id`\n\t\t\tWHERE (\n\t\t\t\tLOWER(  `item`.`item_nomb` ) LIKE  '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER(  `item`.`item_desc` ) LIKE  '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER(  `item`.`item_precio` ) LIKE  '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER(  `t`.`talla_desc` ) LIKE  '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER(  `t`.`talla_nomb` ) LIKE  '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER(  `c`.`color_nomb` ) LIKE  '%" . strtolower($busq) . "%' OR\n\t\t\t\tLOWER(  `c`.`color_desc` ) LIKE  '%" . strtolower($busq) . "%'\n\t\t\t)\n\t\t\tAND  `item`.`deleted` = 0\n\t\t\tGROUP BY item.id\n\t\t\t");
     return View::make('indexs.busq')->with('title', $title)->with('art', $art)->with('cat', $cat)->with('subcat', $subcat)->with('busq', $busq);
 }
Exemplo n.º 13
0
<?php

function __autoload($class_name)
{
    $name = $class_name . ".php";
    if (file_exists($name)) {
        require_once $name;
    } else {
        echo "Class not found";
    }
}
$cat = new Cat("maca", 23);
var_dump($cat->getName());
echo $cat::$counter;
$cat->talk();
Exemplo n.º 14
0
    return View::make('cats/index')->with('cats', $cats);
});
Route::get('cats/breeds/{name}', function ($name) {
    $breed = Breed::whereName($name)->with('cats')->first();
    return View::make('cats/index')->with('breed', $breed)->with('cats', $breed->cats);
});
Route::get('cats/create', function () {
    $cat = new Cat();
    return View::make('cats.edit')->with('cat', $cat)->with('method', 'post');
});
Route::post('cats', function () {
    $cat = Cat::create(Input::all());
    return Redirect::to('cats/' . $cat->id)->with('message', 'Profil został utworzony!');
});
Route::get('cats/{id}', function ($id) {
    $cat = Cat::find($id);
    return View::make('cats.single')->with('cat', $cat);
});
Route::get('cats/{cat}/edit', function (Cat $cat) {
    return View::make('cats.edit')->with('cat', $cat)->with('method', 'put');
});
Route::get('cats/{cat}/delete', function (Cat $cat) {
    return View::make('cats.edit')->with('cat', $cat)->with('method', 'delete');
});
Route::put('cats/{cat}', function (Cat $cat) {
    $cat->update(Input::all());
    return Redirect::to('cats/' . $cat->id)->with('message', 'Profil został uaktualniony!');
});
Route::delete('cats/{cat}', function (Cat $cat) {
    $cat->delete();
    return Redirect::to('cats')->with('message', 'Profil został usunięty!');
Exemplo n.º 15
0
 */
class Dog extends Pet
{
    function play()
    {
        // Call the Pet::play() method:
        parent::play();
        echo "<p>{$this->name} is fetching.</p>";
    }
}
// End of Dog class.
# ***** END OF CLASSES ***** #
// Create a dog:
$dog = new Dog('Satchel');
// Create a cat:
$cat = new Cat('Bucky');
// Create an unknown type of pet:
$pet = new Pet('Rob');
// Feed them:
$dog->eat();
$cat->eat();
$pet->eat();
// Nap time:
$dog->sleep();
$cat->sleep();
$pet->sleep();
// Have them play:
$dog->play();
$cat->play();
$pet->play();
// Delete the objects:
<?php

include 'Cat.php';
$cat1 = new Cat();
$cat1->setColor("black");
$cat1->setBreed("Calico");
$cat1->setname("Zoe");
$myCats[] = $cat1;
$cat2 = new Cat();
$cat2->setColor("orange");
$cat2->setBreed("Siamese");
$cat2->setname("Garfield");
$myCats[] = $cat2;
$cat3 = new Cat();
$cat3->setColor("tabby");
$cat3->setBreed("Lion");
$cat3->setname("Fluffy");
$myCats[] = $cat3;
displayCatInfo($cat1);
displayCatInfo($cat2);
displayCatInfo($cat3);
echo "The number of cats of color orange is " . countByColor("orange", $myCats);
function displayCatInfo($catExample)
{
    echo "Name: " . $catExample->getName();
    echo "<br>";
    echo "Color: " . $catExample->getColor();
    echo "<br>";
    echo "Breed: " . $catExample->getBreed();
    echo "<br>";
    echo "<br>";
Exemplo n.º 17
0
<?php

include 'autoload.php';
$cat = new Cat('garfield');
echo $cat->getName() === 'garfield';
echo $cat->meow() === 'Cat garfield is saying meow';
Exemplo n.º 18
0
 public function testMultipleNamesAndAverageNameLength()
 {
     @($cat = new Cat());
     $names = ['Chaos', 'Chocolate', 'Felix', 'Garfield', 'Nermal', 'Scratchy'];
     $totalLength = 0;
     foreach ($names as $name) {
         $cat->setName($name);
         $totalLength += strlen($name);
     }
     $allNames = $cat->getNames();
     $this->assertEquals(implode(',', $names), $allNames);
     $this->assertEquals($totalLength / count($names), $cat->getAverageNameLength());
 }
Exemplo n.º 19
0
<!DOCTYPE html>
<html>
    <head>
	  <title> Hora do Desafio! </title>
      <link type='text/css' rel='stylesheet' href='style.css'/>
	</head>
	<body>
      <p>
        <?php 
// Digite seu código aqui
class Cat
{
    public $isAlive = true;
    public $numLegs = 4;
    public $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function meow()
    {
        return 'Meow meow';
    }
}
$siames = new Cat('CodeCat');
echo $siames->meow();
?>
      </p>
    </body>
</html>
Exemplo n.º 20
0
    }
    public function howOld()
    {
        echo $this->name . " is " . $this->age . " years old.";
        echo "<br>";
        echo $this->name . " is " . $this->age . " cat years old!";
        echo "<br>";
    }
    public function catWeight()
    {
        echo $this->name . " is " . $this->weight . " pound";
    }
}
$cat1 = new Cat("Little Buddy", 2, 8);
$cat2 = new Cat("Sneaky Pete", 0, 2);
$cat3 = new Cat("Mephisto", 300, 900);
$cat1->howOld();
$cat1->feedCat(6);
$cat3->howOld();
$cat3->catWeight();
echo "<br>";
echo $cat3->age;
echo "<br>";
echo $cat3->weight;
?>

</body>
</html>


Exemplo n.º 21
0
<?php

//http://www.php.net/manual/en/language.namespaces.rationale.php
namespace my\name;

class Cat
{
    static function says()
    {
        echo 'meoow\\n';
    }
}
$o = new Cat();
$o->says();
$o = new \my\name\Cat();
$o->says();
echo __NAMESPACE__;
Exemplo n.º 22
0
class Cat
{
    public $isAlive = true;
    public $numLegs = 4;
    public $name;
    public function __construct($name)
    {
        $this->name = $name;
    }
    public function meow()
    {
        return "Meow meow";
    }
}
$cat1 = new Cat("CodeCat");
echo $cat1->meow();
die;
?>

<!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
<?php 
header("Content-type: text/html; charset=utf-8");
?>

<?php 
// Declarando os valores das variáveis
$a = 4;
$b = 2;
?>
<h2>Adição</h2>
Exemplo n.º 23
0
}
class Cat implements Animal
{
    protected $name;
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
    public function getColour()
    {
    }
}
class Dog
{
}
class Vet
{
    public function treat(Animal $animal)
    {
        echo 'The vet has treated ' . $animal->getName();
    }
}
$cat = new Cat();
$cat->setName('Felix');
//echo $cat->getName();
$vet = new Vet();
$vet->treat($cat);
Exemplo n.º 24
0
<?php

if (isset($_POST["url"])) {
    $url = $_POST["url"];
    $subdomains = array("m.", "www.", "mobile.");
    $host = str_ireplace($subdomains, "", parse_url($url, PHP_URL_HOST));
}
switch ($host) {
    case "8tracks.com":
        require "stuff/fetch/EightTracks.php";
        $mixId = isset($_POST["mix_id"]) ? $_POST["mix_id"] : false;
        $trackNumber = isset($_POST["track_number"]) ? $_POST["track_number"] : 0;
        $please = new EightTracks($output);
        $please->get($url, $mixId, $trackNumber);
        break;
    case "songza.com":
        require "stuff/fetch/Songza.php";
        $stationId = isset($_POST["station_id"]) ? $_POST["station_id"] : false;
        $sessionId = isset($_POST["session_id"]) ? $_POST["session_id"] : false;
        $please = new Songza($output);
        $please->get($url, $stationId, $sessionId);
        break;
    default:
        require "stuff/fetch/Cat.php";
        $please = new Cat($output);
        $please->getCat();
}
Exemplo n.º 25
0
class Bird extends Animal
{
    public function __construct($name, $height, $weight, $favFood, $speed, $sound, $canFly)
    {
        parent::__construct($name, $height, $weight, $favFood, $speed, $sound, $canFly);
    }
}
try {
    $dog = new Dog('dog', 3, 4, 'cat', 5, 'Bark', false);
    $playwithanimal = new PlayWithAnimal($dog);
    echo "<br>";
    $dog->tryToFly();
    echo "<br>";
    $dog->talk();
    echo "<br>";
    $cat = new Cat('cat', 3, 4, 'mice', 5, 'miow', false);
    $playwithanimal = new PlayWithAnimal($cat);
    echo "<br>";
    $cat->tryToFly();
    echo "<br>";
    $cat->talk();
    echo "<br>";
    $bird = new Bird('Bird', 3, 4, 'insect', 5, 'miow', true);
    $playwithanimal = new PlayWithAnimal($bird);
    echo "<br>";
    $bird->tryToFly();
    echo "<br>";
    $bird->talk();
} catch (Exception $e) {
    echo $e->getMessage();
}
<?php

$cat1 = new Cat();
$cat1->setColor("black");
$cat1->setname("Zoe");
$myCats[] = $cat1;
$cat2 = new Cat();
$cat2->setColor("orange");
$cat2->setname("Garfield");
$myCats[] = $cat2;
$cat3 = new Cat();
$cat3->setColor("tabby");
$cat3->setname("Fluffy");
$myCats[] = $cat3;
Exemplo n.º 27
0
<?php

/* Кот от кота, а собака от собаки
Переопределить метод getChild в классах Cat(кот) и Dog(собака), чтобы кот порождал кота, а собака – собаку.
*/
class Cat
{
    public static function getChirld()
    {
        return new Cat();
    }
}
class Dog
{
    public static function getChirld()
    {
        return new Dog();
    }
}
Cat::getChirld();
Dog::getChirld();
<?php

include 'Cat.php';
$cat1 = new Cat();
$cat1->setColor("black");
$cat1->setname("Zoe");
$cat1->setBreed("Scottish Fold");
$myCats[] = $cat1;
$cat2 = new Cat();
$cat2->setColor("orange");
$cat2->setname("Garfield");
$cat2->setBreed("Persian");
$myCats[] = $cat2;
$cat3 = new Cat();
$cat3->setColor("tabby");
$cat3->setname("Fluffy");
$cat3->setBreed("Ragamuffin");
$myCats[] = $cat3;
$cont = 0;
displayCount($cat1, $cont);
// calling the function to count the cats.
displayCount($cat2, $cont);
displayCount($cat3, $cont);
echo "The number of cat that the color is orange is " . $cont;
displayCatInfo($cat1);
displayCatInfo($cat2);
displayCatInfo($cat3);
function displayCount($cat, &$cont)
{
    if ($cat->getColor() == 'orange') {
        //comparison to verify the orange collor
Exemplo n.º 29
0
 public function getCategoryName()
 {
     $category = Cat::findOne($this->cat_id);
     return $category->title;
 }
 /**
  *
  */
 public function testBatchWrite_DifferentClasses_WritesObjects()
 {
     $dog = new Dog();
     $dog->Name = 'Snuffins';
     $dog->Color = 'Red';
     $cat = new Cat();
     $cat->Name = 'Puff daddy';
     $cat->HasClaws = true;
     $batch = new \Batch();
     $batch->write(array($dog, $cat));
     $this->assertTrue($dog->exists());
     $this->assertTrue($cat->exists());
     $dog = Dog::get()->first();
     $this->assertEquals('Snuffins', $dog->Name);
     $this->assertEquals('Red', $dog->Color);
     $cat = Cat::get()->first();
     $this->assertEquals('Puff daddy', $cat->Name);
     $this->assertEquals(1, $cat->HasClaws);
 }