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();
}
Related
I have problems setting up my Crud Controller's association fields. I want to only see users of a certain ROLE_ in the klient_id_klienta field and I don't know how to set it up.
Here is my CrudController:
class AdresKlientaCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return AdresKlienta::class;
}
/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
];
}
*/
// public function configureFields(string $pageName): iterable
// {
// return [
// 'id',
// 'klient_id_klienta',
// 'miejscowosc',
// 'ulica',
// 'nr_domu',
// 'nr_lokalu',
// 'kod_pocztowy'
// ];
// }
public function configureFields(string $pageName): iterable
{
//moje
// $qb = new QueryBuilder($this->getDoctrine()->getManager());
// $qb->select('u')->from('User','u')->where('u.roles = ?ROLE_USER');
//
//
// dump(EntityFilter::new('klient_id_klienta')->apply($qb));
//koniec moje
$foreignKey = AssociationField::new('klient_id_klienta'); //here is my problem as it shows every user
return [
// IdField::new('id'),
TextField::new('miejscowosc'),
TextField::new('ulica'),
TextField::new('nr_domu'),
TextField::new('nr_lokalu'),
TextField::new('kod_pocztowy'),
//AssociationField::new('klient_id_klienta')
$foreignKey
];
}
}
And here is the user entity
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* #ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface
{
/**
* #ORM\Id()
* #ORM\GeneratedValue()
* #ORM\Column(type="integer")
*/
private $id;
/**
* #ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* #ORM\Column(type="json")
*/
private $roles = [];
/**
* #var string The hashed password
* #ORM\Column(type="string")
*/
private $password;
/**
* #ORM\Column(type="string", length=255)
*/
private $name;
/**
* #ORM\Column(type="string", length=255)
*/
private $surname;
/**
* #ORM\Column(type="string", length=255)
*/
private $tel;
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* #see UserInterface
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* #see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* #see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* #see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* #see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(string $surname): self
{
$this->surname = $surname;
return $this;
}
public function getTel(): ?string
{
return $this->tel;
}
public function setTel(string $tel): self
{
$this->tel = $tel;
return $this;
}
//moje funkcje
public function __toString()
{
// TODO: Implement __toString() method.
$userAndRole = implode($this->roles);
return $this->email.'-'.$userAndRole;
}
}
I only want to see users who have ROLE_USER
I tried to use filters but from what I see in Easyadmin documentation filters allow me to set up choices based what they get so that wouldnt work for me. I also tried to use QueryBuilder to get Users with certain ROLE_ and that also failed.
I figured it out and I want to thank you for answering. I'm posting my solution because I don't want to be one of those people who say "I figured it out" and don't post how they actually figured that out.
public function configureFields(string $pageName): iterable
{
//utworzenie wyświetlania tylko tych użytkowników, którzy maja role ROLE_USER
$association = AssociationField::new('klient_id_klienta', 'Email klienta')
->setFormTypeOption(
'query_builder', function (UserRepository $userRepository){
return $userRepository->createQueryBuilder('u')
->andWhere('u.roles LIKE :role')->setParameter('role', '%"ROLE_USER"%');
}
);
return [
// IdField::new('id'),
TextField::new('miejscowosc', 'Miejscowość'),
TextField::new('ulica', 'Ulica'),
TextField::new('nr_domu', 'Numer domu'),
TextField::new('nr_lokalu', 'Numer Lokalu'),
TextField::new('kod_pocztowy', 'Kod pocztowy'),
$association,//wywołanie klucza obcego który odfiltrowuje użytkowników
];
}
As you can see I got the users with the certain role that I wanted to get by using query builder. Amazing tool, through that query buider I can get virtually anything I want from my databases and put it in my Crud Controllers. I hope it helps someone someday.
Try this :
public function configureFields(string $pageName): iterable
{
$users = $this->entityManager->getRepository(User::class)->findBy([
'roles' => 'ROLE_USER']);
yield AssociationField::new('klient_id_klienta')->onlyOnForms()->setFormTypeOptions(["choices" => $users->toArray()]);
}
I have a table like:
sysopt|sysval
......................
site_url|http://domain.com/
site_title|My Website
......................
in mysql i use:
$query = $db->query("SELECT * FROM sysconfig");
while ($result = $db->fetch_array($query)) {
$settings[$result['sysopt']] = $result['sysval'];
}
But in CI:
class Sysinfo
{
var $info = array();
public function __construct()
{
$CI =& get_instance();
$settings = $CI->db->select("*")
->get("sysconfig");
foreach($settings as $setting) {
$this->info[$setting['sysopt']] = $setting['sysval'];
}
}
In view i call:
<?php echo $this->Sysinfo->info->site_url; ?>
Show error.
Message: Undefined property: CI_Loader::$Sysinfo
Thankyou any solution fix.
Why just not extend the CI_Model? For me, in framework..just extend the class so you would be easier
In your model:
class Sysinfo extends CI_Model
{
var $info = array();
public function __construct()
{
//$CI =& get_instance();
$settings = $this->db->select("*")
->get("sysconfig")->result_array(); //Return result as array
foreach($settings as $setting) {
$this->info[$setting['sysopt']] = $setting['sysval'];
}
}
function get_sysinfo_data()
{
return $this->info;
}
}
In your Controller
public function __construct()
{
$this->load->model('Sysinfo');
}
function index()
{
$data['arr_result'] = $this->Sysinfo->get_sysinfo_data();
$this->load->view('your_view',$data);
}
In view:
foreach($arr_result as $row_array):
var_dump($row_array); // To view your result
endforeach;
If you want Sysinfo as library..then do like this:
Your library should be name as Sysinfo.php:
class Sysinfo
{
var $info = array();
public function __construct()
{
$CI =& get_instance();
$settings = $CI->db->select("*")
->get("sysconfig")->result_array(); //Return result as array
foreach($settings as $setting) {
$this->info[$setting['sysopt']] = $setting['sysval'];
}
}
function get_sysinfo_data()
{
return $this->info;
}
}
In your Controller:
public function __construct()
{
$this->load->library('Sysinfo');
}
function index()
{
$data['arr_result'] = $this->Sysinfo->get_sysinfo_data();
$this->load->view('your_view',$data);
}
Hope it helps.
The error is appearing because you haven't extended your class with CI_Model base class.
Try defining your class as:
class Sysinfo extends CI_Model{ //your code }
will get rid of this error message.
my english is poor because this is not my main language but i'll do my best.
I need help with the argument to the constructor because i dont know where to take all these information.
here my defaultitem class:
public class DefaultItem extends MovieClip
{
private var _id:String;
private var _lastX:int;
private var _lastY:int;
private var _isStackable:Boolean = false;
private var _type:String;
private var _isDragging:Boolean = false;
private var _currentContainer:DefaultContainer;
private var _lastContainer:DefaultContainer;
public function DefaultItem($id:String, $type:String, $x:int, $y:int)
{
stop();
id = $id;
type = $type;
x = $x;
y = $y;
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
init();
}
public function init():void
{
buttonMode = true;
mouseChildren = false;
_lastX = x;
_lastY = y;
addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
this.stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
//resolve drag bugs
}
/**
* Mouse Event Handlers
*/
private function onMouseDownHandler(e:MouseEvent):void
{
isDragging = true;
this.mouseEnabled = false;
dispatchEvent(new ItemEvent(ItemEvent.ITEM_PICKED_UP, this));
}
private function onMouseUpHandler(e:MouseEvent):void
{
// check if item is being dragged
if (isDragging)
{
isDragging = false;
this.mouseEnabled = true;
dispatchEvent(new ItemEvent(ItemEvent.ITEM_DROPPED, this));
}
}
/**
* Getters & Setters
*/
public function get id():String { return _id; }
public function set id(value:String):void
{
_id = value;
}
public function get lastX():int { return _lastX; }
public function set lastX(value:int):void
{
_lastX = value;
}
public function get lastY():int { return _lastY; }
public function set lastY(value:int):void
{
_lastY = value;
}
public function get currentContainer():DefaultContainer { return _currentContainer; }
public function set currentContainer(value:DefaultContainer):void
{
_currentContainer = value;
}
public function get lastContainer():DefaultContainer { return _lastContainer; }
public function set lastContainer(value:DefaultContainer):void
{
_lastContainer = value;
}
public function get type():String
{
return _type;
}
public function set type(value:String):void
{
_type = value;
}
public function get isDragging():Boolean
{
return _isDragging;
}
public function set isDragging(value:Boolean):void
{
_isDragging = value;
}
/**
* Destroys item
*/
public function destroy():void
{
buttonMode = false;
removeEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
this.stage.removeEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
}
}
}
here my item class:
public class Slot extends DefaultContainer
{
// vars
private var _id:String;
private var _item:DefaultItem;
private var _type:DefaultItem;
//private var isdragging:DefaultItem;
public var defaultitem:DefaultItem = new DefaultItem(id, _type, x, y);
// trace(DefaultItem.getisDragging());
//trace(DefaultItem.getisDragging());
/**
* Constructor
*
* #param $id Slot id
*/
public function Slot($id:String)
{
addEventListener(MouseEvent.ROLL_OUT, onMouseOutHandler);
addEventListener(MouseEvent.ROLL_OVER, onMouseOverHandler);
id = $id;
setLabel($id);
stop();
}
/**
* Slot Methods
*/
public function getItem():DefaultItem { return _item; }
public override function addItem($item:DefaultItem):void
{
_item = $item;
addChild(_item);
//
this.gotoAndStop(2); //active slot
}
public override function removeItem($item:DefaultItem):void
{
removeChild(_item);
_item = null;
this.gotoAndStop(1); //default slot
}
public function hasItem():Boolean
{
if (_item == null)
{
return false;
}
else
{
return true;
}
}
private function onMouseOutHandler(e:MouseEvent):void {
trace("mouseOutHandler");
this.gotoAndPlay("out");
}
private function onMouseOverHandler(e:MouseEvent):void {
trace("mouseoverHandler");
// if (!isDragging)
//{
//trace("drag = "+ isDragging);
this.gotoAndPlay("over");
// }
//else {
//trace("drag = " + isDragging );
//this.gotoAndPlay("dragUp");
// }
}
/**
* Getters & Setters
*/
public function get id():String { return _id; }
public function set id(value:String):void
{
_id = value;
}
public function setLabel($label:String):void
{
this.label.text = $label;
}
/**
* Destroy
*/
public function destroy():void
{
removeItem(_item)
}
}
}
the problem is here public var defaultitem:DefaultItem = new DefaultItem(id, _type, x, y);
i'm not sure id and _type is working good. I wanna know where to get all these information because i need to call the function isdragging and if i use the var id he target the item and not the defaultcountainer id thanks guys
You are creating and instance of DefaultItem but passing wrong arguments.
public var defaultitem:DefaultItem = new DefaultItem(id, _type, x, y);
Since this is created prior to constructor running, id is null, _type is not a String and is null and x, y are out of scope.
It should be:
public var defaultitem:DefaultItem;
Then in Slot constructor:
id = $id;
defaultitem = new DefaultItem(id, _type, x, y);
//but _type is still not a String and is still null
It seems to me like you're dragging an item onto something, sorry if I've misunderstood.
But, in that case, you can use something like:
var itemID:String = e.target.id;
var itemType:String = e.target._type;
That's in case you have the item's id and type stored somewhere.
Also, as for the x and y, those depend on where you want to put them.
For example, if you had a character and you wanted to give him a sword, it would look something like:
//somewhere in your code:
weapon.id = "Iron Sword";
weapon._type = "Sword";
//And then when you get to the default item part...
var itemId:String = e.target.id;
var itemType:String = e.target._type;
var defaultitem:DefaultItem = new DefaultItem(itemID,itemType, character.x, character.y);
Again, sorry if I misunderstood. Best of luck with your program!
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();
}
}
}
So, I got this .as file that is called, let say, class A.
class A inside has other 2 classes, class B and class C, and the only class that is inside a package is class A. And it throws that error.
I downloaded this as an example, and it should work, however Flash Builder 4.6 doesn't like it.
The structure of the as file is like this:
imports
variables
class B
class C
package
public class A
/package
Btw, I'm using Flash Builder not Flash CC.
Update, posting code:
import com.adobe.serialization.json.JSON;
import com.shephertz.appwarp.WarpClient;
import com.shephertz.appwarp.listener.ConnectionRequestListener;
import com.shephertz.appwarp.listener.NotificationListener;
import com.shephertz.appwarp.listener.RoomRequestListener;
import com.shephertz.appwarp.listener.ZoneRequestListener;
import com.shephertz.appwarp.messages.Chat;
import com.shephertz.appwarp.messages.LiveResult;
import com.shephertz.appwarp.messages.LiveRoom;
import com.shephertz.appwarp.messages.LiveUser;
import com.shephertz.appwarp.messages.Lobby;
import com.shephertz.appwarp.messages.MatchedRooms;
import com.shephertz.appwarp.messages.Move;
import com.shephertz.appwarp.messages.Room;
import com.shephertz.appwarp.types.ResultCode;
import flash.utils.ByteArray;
var APIKEY:String = "key";
var SECRETEKEY:String = "secretkey";
var Connected:Boolean = false;
var INITIALIZED:Boolean = false;
var client:WarpClient;
var roomID:String;
var State:int = 0;
var User:String;
class connectionListener implements ConnectionRequestListener
{
private var connectFunc:Function;
public function connectionListener(f:Function)
{
connectFunc = f;
}
public function onConnectDone(res:int):void
{
if(res == ResultCode.success)
{
Connected = true;
}
else
{
Connected = false;
}
connectFunc(res);
}
public function onDisConnectDone(res:int):void
{
Connected = false;
}
}
class roomListener implements RoomRequestListener
{
private var connectFunc:Function;
private var joinFunc:Function;
public function roomListener(f:Function,f1:Function)
{
connectFunc = f;
joinFunc = f1;
}
public function onSubscribeRoomDone(event:Room):void
{
if(State == 2)
joinFunc();
else
connectFunc();
}
public function onUnsubscribeRoomDone(event:Room):void
{
}
public function onJoinRoomDone(event:Room):void
{
if(event.result == ResultCode.resource_not_found)
{
if(State == 1)
{
State = 3;
}
client.createRoom("room","admin",2,null);
}
else if(event.result == ResultCode.success)
{
if(State == 1)
{
State = 2;
}
roomID = event.roomId;
client.subscribeRoom(roomID);
}
}
public function onLeaveRoomDone(event:Room):void
{
client.unsubscribeRoom(roomID);
}
public function onGetLiveRoomInfoDone(event:LiveRoom):void
{
}
public function onSetCustomRoomDataDone(event:LiveRoom):void
{
}
public function onUpdatePropertyDone(event:LiveRoom):void
{
}
public function onLockPropertiesDone(result:int):void
{
}
public function onUnlockPropertiesDone(result:int):void
{
}
public function onUpdatePropertiesDone(event:LiveRoom):void
{
}
}
class zoneListener implements ZoneRequestListener
{
public function onCreateRoomDone(event:Room):void
{
roomID = event.roomId;
client.joinRoom(roomID);
}
public function onDeleteRoomDone(event:Room):void
{
}
public function onGetLiveUserInfoDone(event:LiveUser):void
{
}
public function onGetAllRoomsDone(event:LiveResult):void
{
}
public function onGetOnlineUsersDone(event:LiveResult):void
{
}
public function onSetCustomUserInfoDone(event:LiveUser):void
{
}
public function onGetMatchedRoomsDone(event:MatchedRooms):void
{
}
}
class notifylistener implements NotificationListener
{
private var joinFunc:Function;
private var msgFunc:Function;
private var leaveFunc:Function;
public function notifylistener(f:Function)
{
joinFunc = f;
}
public function msgListener(f:Function,f1:Function):void
{
msgFunc = f;
leaveFunc = f1;
}
public function onRoomCreated(event:Room):void
{
}
public function onRoomDestroyed(event:Room):void
{
}
public function onUserLeftRoom(event:Room, user:String):void
{
if(user != User)
{
leaveFunc();
}
}
public function onUserJoinedRoom(event:Room, user:String):void
{
if(State == 3)
joinFunc();
}
public function onUserLeftLobby(event:Lobby, user:String):void
{
}
public function onUserJoinedLobby(event:Lobby, user:String):void
{
}
public function onChatReceived(event:Chat):void
{
if(event.sender != User)
{
var obj:Object = com.adobe.serialization.json.JSON.decode(event.chat);
msgFunc(obj);
}
}
public function onUpdatePeersReceived(update:ByteArray):void
{
}
public function onUserChangeRoomProperty(room:Room, user:String,properties:Object):void
{
}
public function onPrivateChatReceived(sender:String, chat:String):void
{
}
public function onUserChangeRoomProperties(room:Room, user:String,properties:Object, lockTable:Object):void
{
}
public function onMoveCompleted(move:Move):void
{
}
}
package
{
import com.adobe.serialization.json.JSON;
import com.shephertz.appwarp.WarpClient;
public class AppWarp
{
public static var _roomlistener:roomListener;
public static var _zonelistener:zoneListener;
public static var _notifylistener:notifylistener;
public static var _connectionlistener:connectionListener;
private static function generateRandomString(strlen:Number):String{
var chars:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var num_chars:Number = chars.length - 1;
var randomChar:String = "";
for (var i:Number = 0; i < strlen; i++){
randomChar += chars.charAt(Math.floor(Math.random() * num_chars));
}
return randomChar;
}
public static function connect(f:Function):void
{
if(INITIALIZED == false)
{
WarpClient.initialize(APIKEY, SECRETEKEY);
client = WarpClient.getInstance();
INITIALIZED = true;
}
if(Connected == false)
{
_connectionlistener = new connectionListener(f);
client.setConnectionRequestListener(_connectionlistener);
User = generateRandomString(16);
client.connect(User);
}
else
f(0);
}
public static function join(f1:Function, f2:Function):void
{
_roomlistener = new roomListener(f1,f2);
_zonelistener = new zoneListener();
_notifylistener = new notifylistener(f2);
client.setRoomRequestListener(_roomlistener);
client.setZoneRequestListener(_zonelistener);
client.setNotificationListener(_notifylistener);
State = 1;
client.joinRoomInRange(1,1,true);
}
public static function leave():void
{
client.leaveRoom(roomID);
}
public static function begin(f:Function, f1:Function, dir:int, x:int, y:int):void
{
_notifylistener.msgListener(f, f1);
send(0,dir,x,y);
}
public static function move(dir:int,x:int,y:int):void
{
send(1,dir,x,y);
}
public static function eat(dir:int,x:int,y:int):void
{
send(2,dir,x,y);
}
public static function send(type:int,dir:int,x:int,y:int):void
{
if(Connected == true)
{
var obj:Object = new Object();
obj.type = type;
obj.dir = dir;
obj.x = x;
obj.y = y;
client.sendChat(com.adobe.serialization.json.JSON.encode(obj));
}
}
}
}
I needed to place the package keyword at the very beginning of the .as file, otherwise an error is thrown.
You can only define one class in a package in a file. You can define other classes outside the package, but I don't think that is a good idea as I have observed that in some versions of compiler you have to place it at the beginning and in some at the end. Sometimes, it won't work in anyway.
A better way is to define different classes for each listener in different files. You can use the same package name.
I would recommend creating a single class to listen to all listeners by implementing all base listener classes.
For e.g.
//listener.as
package
{
public class Listener implements ConnectionRequestListener, RoomRequestListener, NotificationListener
{
}
}