Which class is responsible for creating an instance of the block? - magento-1.9

Which class is responsible for creating an instance of the block?
Please give the answer.

"Mage_Core_Model_Layout" this class creating instance of class .
class Mage_Core_Model_Layout extends Varien_Simplexml_Config
{
public function generateBlocks($parent=null)
{
if (empty($parent)) {
$parent = $this->getNode();
}
foreach ($parent as $node) {
$attributes = $node->attributes();
if ((bool)$attributes->ignore) {
continue;
}
switch ($node->getName()) {
case 'block':
$this->_generateBlock($node, $parent);
$this->generateBlocks($node);
break;
case 'reference':
$this->generateBlocks($node);
break;
case 'action':
$this->_generateAction($node, $parent);
break;
}
}
}
}

Related

How do I access a method that's in another method that's in a class in ECMA6Script?

How do I declare the method getYellowCycle() so that the variable game can access it? getYellowCycle is a method that's in another method called newGame(), that's in a class called model.game.
Here is where the method should be called.
let game = model.Game.newGame();
expect(game.getYellowCycle().getX()).to.equal(50);
Here is the class model.game
model.Game = class {
newGame() {
}
};
getYellowCycle() should go in newGame()
Something like this:
const model = {};
model.Game = class {
newGame() {
return {
getYellowCycle() {
return {
getX() {
console.log("In getX");
return 50;
}
};
}
};
}
};
const game = (new model.Game()).newGame();
console.log(game.getYellowCycle().getX());

PhpStorm type recognition/suggestions

Is there anything I can do to get PhpStorm (2016.1) to recognize types outside the "new X()" scope?
SomeClass.php:
class SomeClass
{
public function DoMagic()
{
echo "doing magic";
}
}
DummyClass.php:
class DummyClass
{
protected $mParamsList;
function __construct()
{
$this->mParamsList = array();
}
public function InitParamsList()
{
$this->mParamsList[] = new SomeClass();
}
public function GetParamsList()
{
return $this->mParamsList;
}
}
UserClass.php - no suggestions:
class UserClass
{
public function DoMagic()
{
$dummy2 = new DummyClass();
$params = $dummy2->GetParamsList();
foreach ($params as $param)
{
$param-> * nothing happens *
}
}
}
?>
I found adding this hack works, but it's getting frustrating to employ it:
if (false)
{
$param = new SomeClass();
}
So the full working example would be:
class UserClass
{
public function DoMagic()
{
$dummy = new DummyClass();
$params = $dummy->GetParamsList();
foreach ($params as $param)
{
if (false)
{
$param = new SomeClass();
}
$param-> * suggestions pop up *
}
}
}
You should use doc-type comments before your function:
/**
* #return \MyObject
*/
public function GetMyObject()
{
return new MyObject();
}

How to use this before super?

I know that this is not allowed before super but I need to do it. I was wondering if there was a legal way to do this in es6?
My code:
class DOMElement {
constructor(aNodeName) {
this.name = aNodeName;
this.create();
}
create() {
let domref = document.createElement(this.name);
document.body.appendChild(domref);
return domref;
}
}
class Button extends DOMElement {
constructor(aLabel) {
this.label = aLabel;
super('button');
}
create() {
let domref = super.create();
domref.textContent = this.label;
}
}
If I don't set this.label before calling super('button') in Button.prototype.create then domref.textContent is set to undefined.
There's no 'legal' way.
It can be be a getter in cases where static property value is supposed to be used by parent class on construction:
get label() {
return 'label';
}
In this case this means that class design is just wrong. There's nothing in parent class that would impose such restriction. Actually, label is only used by child class. It should be:
constructor(aLabel) {
super('button');
this._domref.textContent = alabel;
}
create() {
// if parent class is user-defined, it should be done there
// instead of returning a value, because it doesn't make sense
// to leave an important part of the object without a reference
this._domref = super.create();
}

Do nested functions reduce performance?

I have a class UglyLobster in a sidescroller-type game that uses artificial intelligence in AS3. UglyLobster is a largely self-operating class that determines what it will do next based on the environment. As I am building this artificial intelligence, I find the easiest solution is to use nested functions.
However, I am uncertain if nested functions will affect the performance and cause drag. This UglyLobster is not limited to one instance; many will be running at the same time. I've added code to show what I'm trying to do.
public class UglyLobster extends Mob {
//these vars determine what the UglyLobster will do next
public var behavior = "aggro"
private var behaviorStep:int = 1
public function UglyLobster() {
addEventListener(Event.ENTER_FRAME,performBehavior)
}
public function performBehavior(e) {
if (behavior == "aggro") {
aggro()
}
if (behavior == "tranq") {
tranq()
}
}
private function aggro() {
//it is necessary to have multiple steps.
//in step 1, the Lobster could bare its lobster fangs,
//then in step 2, crawl toward a point
//and in step 3, pinch somebody
if (behaviorStep == 1) {
step1()
}
if (behaviorStep == 2) {
step2()
}
if (behaviorStep == 3) {
step3()
}
function step1() {
if (someCondition) {
behaviorStep = 2
} else {
//do whatever happens in step1
}
}
function step2() {
if (someOtherCondition) {
behaviorStep = 3
} else {
//do whatever happens in step2
}
}
function step3() {
if (anotherCondition) {
behaviorStep = 1
} else {
behavior = "tranq"
}
}
}
private function tranq() {
//do nothing
}
}
Are the nested functions a memory-efficient way to complete the task? If not, how would you set up an artificial intelligence for UglyLobster? Examples would really help
Even if i don't like this kind of design and probably, as Jason suggested, there is an architectural design problem, i think there is no need for nested functions.
private function aggro() {
//it is necessary to have multiple steps.
//in step 1, the Lobster could bare its lobster fangs,
//then in step 2, crawl toward a point
//and in step 3, pinch somebody
if (behaviorStep == 1) {
step1()
}
if (behaviorStep == 2) {
step2()
}
if (behaviorStep == 3) {
step3()
}
}
private function step1() {
if (someCondition) {
behaviorStep = 2
} else {
//do whatever happens in step1
}
}
private function step2() {
if (someOtherCondition) {
behaviorStep = 3
} else {
//do whatever happens in step2
}
}
private function step3() {
if (anotherCondition) {
behaviorStep = 1
} else {
behavior = "tranq"
}
}

Calling methods from another class Action Script 3

I have two classes called 'main' and 'TimerCountDown'. I was try to call a single function 'reset' from 'TimerCountDown' in 'main' class.
This is my TimerCountDown class:
public class TimerCountDown extends MovieClip
{
public function TimerCountDown(t:TextField, timeType:String, timeValue:Number, es:String, _documentclass):void
{
this.documentclass = _documentclass;
this.tfTimeDisplay = t;
if (timeType == "seconds")
{
this.timeInSeconds = timeValue;
}
if (timeType == "minutes")
{
this.timeInSeconds = timeValue * 60;
}
this.tfEndDisplayString = es;
this.startTimer();
}
public function reset():void{
clockCounter.reset();
}
}
How can I create a reference in main class use the reset function in functions of main class? I can only do sth like
var myTimerObject:TimerCountDown = new TimerCountDown(timer, "seconds", 40, "0!", this);
but have no idea on calling reset function.
You can call it like this :
myTimerObject.reset();
You may keep a reference of myTimerObject in main class
public class Main {
private var _targetTimerObject:TimerCountDown;
public function set targetTimerObject(value:TimerCountDown):void {
_targetTimerObject = value;
}
public function someFunction():void {
if (_targetTimerObject) {
_targetTimerObject.reset();
}
}
}